Metrics module for Play2
Clone or download
Pull request Compare This branch is 3 commits ahead, 27 commits behind kenshoo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This module provides some support for @codahale Metrics library in a Play2 application (Scala)

This fork contains support for Graphite reporter and works with InfluxDB Graphite input plugin.

Build Status

Play Version: 2.3.4, Metrics Version: 3.1.0, Scala Versions: 2.10.4, 2.11.2


  1. Default Metrics Registry
  2. Metrics Servlet
  3. Filter to instrument http requests


Add metrics-play dependency:

    val appDependencies = Seq(
    "com.kenshoo" %% "metrics-play" % "2.3.0_0.1.9"

To enable the plugin:

add to conf/play.plugins the following line


where priority is the priority of this plugin with respect to other plugins.

Default Registry

     import com.codahale.metrics.Counter

     val counter = MetricsRegistry.defaultRegistry.counter("name")

Metrics Controller

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    


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

Metrics Filter

An implementation of the Metrics' instrumenting filter for Play2. It records requests duration, number of active requests and counts each return code

    import play.api.mvc._

    object Global extends WithFilters(MetricsFilter)

Note - to use the filter in play java, replace MetricsFilter class with JavaMetricsFilter

   import play.GlobalSettings;
   import play.api.mvc.EssentialFilter;
   public class Global extends GlobalSettings {
       public <T extends EssentialFilter> Class<T>[] filters() {
           return new Class[]{JavaMetricsFilter.class};


Configuration can optionally be overridden through subclassing MetricsFilter in order to change the prefix label for created metrics, and to specify which HTTP Status codes should have individual metrics.

    import{MetricsRegistry, MetricsFilter}
    import play.api.mvc._

    class Global(val reg: MetricRegistry) extends WithFilters(new MetricsFilter{
      val registry: MetricRegistry = reg
      override val knownStatuses: Seq[Int] = Seq(Status.OK, Status.BAD_REQUEST, Status.FORBIDDEN, Status.NOT_FOUND, Status.CREATED, Status.TEMPORARY_REDIRECT, Status.INTERNAL_SERVER_ERROR)
      override val label: String = classOf[MetricsFilter].getName


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) 2.3.0_0.1.9 - Add extra http codes, support configurable metrics names for requests filter 2.3.0_0.2.0 - Meter uncaught exceptions as 500 Internal Server Error 2.3.0_0.2.1 - Breaking Change! prefix jvm metric names to standardize with dropwizard


This code is released under the Apache Public License 2.0.