InstrumentedBuilder

The mixin trait for creating a class which is instrumented with metrics.

Use it as follows:

object Application {
 // The application wide metrics registry.
 val metricRegistry = new com.codahale.metrics.MetricRegistry()
}
trait Instrumented extends InstrumentedBuilder {
 val metricRegistry = Application.metricRegistry
}

class Example(db: Database) extends Instrumented {
 private[this] val loading = metrics.timer("loading")

 def loadStuff(): Seq[Row] = loading.time {
   db.fetchRows()
 }
}

As an alternative to your own Instrumented as above, it is possible to use DefaultInstrumented instead.

By default metric names are prefixed with the name of the current class. You can override this metric base name. For example:

class Example(db: Database) extends Instrumented {
 override lazy val metricBaseName = MetricName("Overridden.Base.Name")
 private[this] val loading = metrics.timer("loading")

 def loadStuff(): Seq[Row] = loading.time {
   db.fetchRows()
 }
}

If you want to use hdrhistograms, you can override the metric builder as follows:

trait Instrumented extends InstrumentedBuilder {
 override lazy protected val metricBuilder = new HdrMetricBuilder(metricBaseName, metricRegistry, false)
 val metricRegistry = Application.metricRegistry
}

See the the manual for more instructions on using hdrhistogram.

class Object
trait Matchable
class Any

Value members

Abstract methods

def metricRegistry: MetricRegistry

The MetricRegistry where created metrics are registered.

The MetricRegistry where created metrics are registered.

Concrete methods

The MetricBuilder that can be used for creating timers, counters, etc.

The MetricBuilder that can be used for creating timers, counters, etc.

Concrete fields

lazy protected

Inherited fields

The base name for all metrics created from this builder.

The base name for all metrics created from this builder.

Inherited from
BaseBuilder