本文整理汇总了Scala中com.codahale.metrics.json.MetricsModule类的典型用法代码示例。如果您正苦于以下问题:Scala MetricsModule类的具体用法?Scala MetricsModule怎么用?Scala MetricsModule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetricsModule类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SystemResource
//设置package包名称以及导入依赖的类
package mesosphere.marathon.api
import java.io.StringWriter
import java.util.concurrent.TimeUnit
import javax.servlet.http.HttpServletRequest
import javax.ws.rs._
import javax.ws.rs.core.{ Context, MediaType, Response }
import com.codahale.metrics.{ MetricFilter, MetricRegistry }
import com.codahale.metrics.annotation.Timed
import com.codahale.metrics.json.MetricsModule
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.inject.Inject
import mesosphere.marathon.MarathonConf
import mesosphere.marathon.io.IO
import mesosphere.marathon.plugin.auth.AuthorizedResource.SystemConfig
import mesosphere.marathon.plugin.auth.{ Authenticator, Authorizer, ViewResource }
@Path("")
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
class SystemResource @Inject() (metrics: MetricRegistry, val config: MarathonConf)(implicit
val authenticator: Authenticator,
val authorizer: Authorizer) extends RestResource with AuthResource {
private[this] lazy val mapper = new ObjectMapper().registerModule(
new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false, MetricFilter.ALL)
)
@GET
@Path("ping")
@Timed
def ping(@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
withAuthorization(ViewResource, SystemConfig){
ok("pong")
}
}
@GET
@Path("metrics")
@Timed
def metrics(@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
withAuthorization(ViewResource, SystemConfig){
IO.using(new StringWriter()) { writer =>
mapper.writer().writeValue(writer, metrics)
ok(writer.toString)
}
}
}
}
示例2: ApplicationController
//设置package包名称以及导入依赖的类
package dcos.metronome.api.v1.controllers
import java.io.StringWriter
import java.util.concurrent.TimeUnit
import com.codahale.metrics.json.MetricsModule
import com.fasterxml.jackson.databind.ObjectMapper
import dcos.metronome.api.RestController
import dcos.metronome.behavior.Metrics
import mesosphere.marathon.io.IO
import play.api.http.ContentTypes
import play.api.mvc.Action
class ApplicationController(metrics: Metrics) extends RestController {
private[this] val metricsMapper = new ObjectMapper().registerModule(
new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)
)
def ping = Action { Ok("pong") }
def showMetrics = Action {
val metricsJsonString = IO.using(new StringWriter()) { writer =>
metricsMapper.writer().writeValue(writer, metrics.metricRegistry)
writer.getBuffer.toString
}
Ok(metricsJsonString).as(ContentTypes.JSON)
}
}