THIS IS A FORK OF kenshoo/metrics-play. IT WILL STOP MAINTENANCE ONCE MY PULL REQUEST IS MERGED.
This module provides some support for @codahale Metrics library in a Play2 application (Scala)
Play Version: 2.4.3, Metrics Version: 3.1.1, Scala Versions: 2.11.6
- Default Metrics Registry
- Metrics Servlet
- Filter to instrument http requests
Add metrics-play dependency:
resolvers += "metrics-play" at "https://edvakf.github.io/tmp-metrics-play-artifacts/"
val appDependencies = Seq(
...
"com.github.edvakf" %% "metrics-play" % "2.4.3_0.4.0"
)
To enable the module:
add to application.conf the following line
play.modules.enabled+="com.kenshoo.play.metrics.PlayModule"
To add a custom metrics, you can use defaultRegistry
which returns an instance of MetricRegistry.
import com.kenshoo.play.metrics.Metrics
import com.codahale.metrics.Counter
class SomeController @Inject() (metrics: Metrics) {
val counter = metrics.defaultRegistry.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) controls reporting jvm metrics
metrics.logback - [true/false] (default is true) controls reporing logback metrics
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._
class Filters @Inject() (metricsFilter: MetricsFilter) extends HttpFilters {
val filters = Seq(metricsFilter)
}
- 2.4.3_0.4.0 - Upgrade to play 2.4.3
- 2.4.0_0.4.0 - Re-implement as Play Module
- 2.4.0_0.3.0 - Upgrade to play 2.4, metrics 3.1.2
- 2.3.0_0.2.1 - Breaking Change! prefix jvm metric names to standardize with dropwizard
- 2.3.0_0.2.0 - Meter uncaught exceptions as 500 Internal Server Error
- 2.3.0_0.1.9 - Add extra http codes, support configurable metrics names for requests filter
- 2.3.0_0.1.8 - Support default registry in play java. Replace MetricsRegistry.default with MetricsRegistry.defaultRegistry (to support java where default is a reserved keyword)
This code is released under the Apache Public License 2.0.