This module provides some support for @codahale Metrics library in a Play2 application (Scala)
Play Version: 2.3.0, Metrics Version: 3.0.1, Scala Versions: 2.10.2, 2.11.1
- Default Metrics Registry
- Metrics Servlet
- Filter to instrument http requests
Add metrics-play dependency:
val appDependencies = Seq(
...
"com.kenshoo" %% "metrics-play" % "2.3.0_0.1.6"
)
To enable the plugin:
add to conf/play.plugins the following line
{priority}:com.kenshoo.play.metrics.MetricsPlugin
where priority is the priority of this plugin with respect to other plugins.
import com.kenshoo.play.metrics.MetricsRegistry
import com.codahale.metrics.Counter
val counter = MetricsRegistry.default.counter("name")
counter.inc()
An implementation of the metrics-servlet as a play2 controller.
It exports all registered metrics as a json document.
To enable the controller add a mapping to conf/routes file
GET /admin/metrics com.kenshoo.play.metrics.MetricsController.metrics
Some configuration is supported through the default configuration file:
metrics.rateUnit - (default is SECONDS)
metrics.durationUnit (default is SECONDS)
metrics.showSamples [true/false] (default is false)
metrics.jvm - [true/false] (default is true)
An implementation of the Metrics' instrumenting filter for Play2. It records requests duration, number of active requests and counts each return code
import com.kenshoo.play.metrics.MetricsFilter
import play.api.mvc._
object Global extends WithFilters(MetricsFilter)
This code is released under the Apache Public License 2.0.