nl.grons.metrics4.scala
Members list
Type members
Classlikes
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
Provides a wrapper for by-name expressions with the intent that they can become eligible for implicit conversions and implicit resolution.
Provides a wrapper for by-name expressions with the intent that they can become eligible for implicit conversions and implicit resolution.
Type parameters
- T
-
Result type of the evaluated
expression
Value parameters
- expression
-
A by-name parameter that will yield a result of type
Twhen evaluated
Attributes
- Companion
- object
- Supertypes
-
trait () => Tclass Objecttrait Matchableclass Any
The mixin trait for creating a class which creates health checks.
The mixin trait for creating a class which creates health checks.
Attributes
- Supertypes
- Known subtypes
-
trait DefaultInstrumented
A Scala facade class for DropwizardCounter.
A Scala facade class for DropwizardCounter.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
A mixin trait for creating a class that publishes metrics and health checks to the "default" registries.
A mixin trait for creating a class that publishes metrics and health checks to the "default" registries.
This follows the Dropwizard 1.0.0+ application convention of storing the metric registry to SharedMetricRegistries under the name "default". This was extended with storing the health check registry to SharedHealthCheckRegistries under the same name.
After mixing in this trait, metrics and health checks can be defined. For example:
class Example(db: Database) extends DefaultInstrumented {
// Define a health check:
healthCheck("alive") { workerThreadIsActive() }
// Define a timer metric:
private[this] val loading = metrics.timer("loading")
// Use the timer metric:
def loadStuff(): Seq[Row] = loading.time {
db.fetchRows()
}
}
See InstrumentedBuilder for instruction on overriding the metric base name or using hdrhistograms. See CheckedBuilder for instructions on overriding the timeout for scala.concurrent.Future executions.
Attributes
- Supertypes
-
trait CheckedBuildertrait InstrumentedBuildertrait BaseBuilderclass Objecttrait Matchableclass AnyShow all
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class MetricBuilder
- Self type
Attributes
- Supertypes
-
trait SettableGauge[A]trait Gauge[A]trait Metricclass Objecttrait Matchableclass AnyShow all
A mixin trait to get a fresh empty health check registry every time.
A mixin trait to get a fresh empty health check registry every time.
See FreshRegistries for more information.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
A mixin trait to get a fresh empty metric registry every time.
A mixin trait to get a fresh empty metric registry every time.
See FreshRegistries for more information.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
A mixin trait to get a fresh empty metric and health check registry every time.
A mixin trait to get a fresh empty metric and health check registry every time.
Often a singleton service class defines a gauge with a static name. However, during testing multiple instances are needed. Unfortunately the metrics registry doesn't allow registering a gauge under the same name twice. This is not a problem when a new registry is used for each instance.
The same is the case for health checks (since dropwizard-metrics 4.1).
Example
With the following gauge in class Example:
class Example(db: Database) extends nl.grons.metrics4.scala.DefaultInstrumented {
// Define a gauge with a static name
metrics.gauge("aGauge") { db.rowCount() }
}
This trait can be mixed in with any instance of Example:
val example = new Example(db) with FreshRegistries
See also FreshMetricRegistry and FreshHealthCheckRegistry in case your class only extends InstrumentedBuilder or CheckedBuilder respectively.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
A Scala facade class for DropwizardGauge.
A Scala facade class for DropwizardGauge.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
Magnet for the checker. See http://spray.io/blog/2012-12-13-the-magnet-pattern/.
Magnet for the checker. See http://spray.io/blog/2012-12-13-the-magnet-pattern/.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
HealthCheckMagnet.type
A Scala facade class for DropwizardHistogram.
A Scala facade class for DropwizardHistogram.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
The mixin trait for creating a class which is instrumented with metrics.
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.
Attributes
- Supertypes
- Known subtypes
-
trait DefaultInstrumented
A Scala facade class for DropwizardMeter.
A Scala facade class for DropwizardMeter.
Example usage:
class Example(val db: Db) extends Instrumented {
private[this] val rowsLoadedMeter = metrics.meter("rowsLoaded")
def load(id: Long): Seq[Row] = {
val rows = db.load(id)
rowsLoaded.mark(rows.size)
rows
}
}
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Builds and registers metrics.
Builds and registers metrics.
Attributes
- Supertypes
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
MetricName.type
The (base)name of a metric.
The (base)name of a metric.
Constructed via the companion object, e.g. MetricName(getClass, "requests").
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
A gauge to which you can push new values.
A gauge to which you can push new values.
For more information see MetricBuilder.pushGauge.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class PushGaugeWithTimeout[A]
A gauge to which you can push new values. Values are forgotten after some time.
A gauge to which you can push new values. Values are forgotten after some time.
For more information see MetricBuilder.pushGaugeWithTimeout.
Attributes
- Supertypes
A Scala facade class for DropwizardTimer.
A Scala facade class for DropwizardTimer.
Features:
- measure the execution duration of a block of code with time
- measure the time until a future is completed with timeFuture
- add an execution duration measurement as a side effect to a partial function with timePF
- direct access to the underlying timer with update, timerContext, count, max, etc.
Example usage:
class Example(val db: Db) extends Instrumented {
private[this] val loadTimer = metrics.timer("load")
def load(id: Long) = loadTimer.time {
db.load(id)
}
}
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any