nl.grons.metrics4.scala
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.
Instrumented
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.
The MetricRegistry where created metrics are registered.
The base name for all metrics created from this builder.
The MetricBuilder that can be used for creating timers, counters, etc.
The mixin trait for creating a class which is instrumented with metrics.
Use it as follows:
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:
If you want to use hdrhistograms, you can override the metric builder as follows:
See the the manual for more instructions on using hdrhistogram.