HdrMetricBuilder

class HdrMetricBuilder(baseName: MetricName, registry: MetricRegistry, resetAtSnapshot: Boolean) extends MetricBuilder

An alternative metric builder that creates Histograms and Timers with Reservoirs from the HdrHistogram library.

See the the manual for more instructions on using hdrhistogram.

Value parameters:
resetAtSnapshot

false to use reservoirs that accumulate internal state forever, or true to use a reservoir that resets its internal state on each snapshot (which is how reporters get information from reservoirs). See this article for when the latter is useful.

class MetricBuilder
trait DeprecatedMetricBuilder
class Object
trait Matchable
class Any

Value members

Concrete methods

override def histogram(name: String): Histogram

Creates a new histogram metric with a Reservoir from the HdrHistogram library.

Creates a new histogram metric with a Reservoir from the HdrHistogram library.

Value parameters:
name

the name of the histogram

Definition Classes
MetricBuilder
override def timer(name: String): Timer

Creates a new timer metric with a Reservoir from the HdrHistogram library.

Creates a new timer metric with a Reservoir from the HdrHistogram library.

Value parameters:
name

the name of the timer

Definition Classes
MetricBuilder

Inherited methods

def cachedGauge[A](name: String, timeout: FiniteDuration)(f: => A): Gauge[A]

Registers a new gauge metric that caches its value for a given duration.

Registers a new gauge metric that caches its value for a given duration.

Example:

import nl.grons.metrics4.scala._
import scala.concurrent.duration._
class UserRepository(db: Database) extends DefaultInstrumented {
 // Defines the gauge.
 metrics.cachedGauge("row-count", 5.minutes) {
   // Does a measurement at most once every 5 minutes.
   db.usersRowCount()
 }
}
Value parameters:
f

a code block that does a measurement

name

the name of the gauge

timeout

the timeout

Throws:
IllegalArgumentException

when a metric with the given name already exists

Inherited from:
MetricBuilder
def counter(name: String): Counter

Creates a new counter metric.

Creates a new counter metric.

Value parameters:
name

the name of the counter

Inherited from:
MetricBuilder
def gauge[A](name: String)(f: => A): Gauge[A]

Registers a new gauge metric.

Registers a new gauge metric.

Example:

import nl.grons.metrics4.scala._
class SessionStore(cache: Cache) extends DefaultInstrumented {
 // Defines the gauge.
 metrics.gauge("cache-evictions") {
   // Does a measurement.
   cache.getEvictionsCount()
 }
}
Value parameters:
f

a code block that does a measurement

name

the name of the gauge

Throws:
IllegalArgumentException

when a metric with the given name already exists

Inherited from:
MetricBuilder
def meter(name: String): Meter

Creates a new meter metric.

Creates a new meter metric.

Value parameters:
name

the name of the meter

Inherited from:
MetricBuilder
def pushGauge[A](name: String, startValue: A): PushGauge[A]

Registers a new gauge metric to which you can push values.

Registers a new gauge metric to which you can push values.

Example:

import nl.grons.metrics4.scala._
class ExternalCacheUpdater extends DefaultInstrumented {
 // Defines a push gauge
 private val cachedItemsCount = metrics.pushGauge[Int]("cached.items.count", 0)

 def updateExternalCache(): Unit = {
   val items = fetchItemsFromDatabase()
   pushItemsToExternalCache(items)
   // Pushes a new measurement to the gauge
   cachedItemsCount.push(items.size)
   // Alternative way to push a new measurement
   cachedItemsCount.value = items.size
 }
}

When a gauge already exists with the given name, parameter startValue is ignored and the existing gauge is returned.

Value parameters:
name

the name of the gauge

startValue

the first value of the gauge, typically this is 0, 0L or null.

Inherited from:
MetricBuilder
def pushGaugeWithTimeout[A](name: String, defaultValue: A, timeout: FiniteDuration): PushGaugeWithTimeout[A]

Registers a new gauge metric to which you can push values.

Registers a new gauge metric to which you can push values.

The reported value is reset to defaultValue after the timeout.

Example in which the last pushed measurement is reported for at most 10 minutes.

import nl.grons.metrics4.scala._
import scala.concurrent.duration._
class ExternalCacheUpdater extends DefaultInstrumented {
 // Defines a push gauge
 private val cachedItemsCount = metrics.pushGaugeWithTimeout[Int]("cached.items.count", 0, 10.minutes)

 def updateExternalCache(): Unit = {
   val items = fetchItemsFromDatabase()
   pushItemsToExternalCache(items)
   // Pushes a new measurement to the gauge
   cachedItemsCount.push(items.size)
   // Alternative way to push a new measurement
   cachedItemsCount.value = items.size
 }
}

When a gauge already exists with the given name, parameters defaultValue and timeout are ignored and the existing gauge is returned.

Note: Cleanup of old values happens only on read. In the absence of a metric reporter or other reader, the last pushed value will continue to take space on the heap. As most values are very small (e.g. an Int), this should not matter much.

Value parameters:
defaultValue

the first and default value of the gauge, typically this is 0,0Lornull`.

name

the name of the gauge

timeout

the timeout

Inherited from:
MetricBuilder
def unregisterGauges(): Unit

Unregisters all gauges that were created through this builder.

Unregisters all gauges that were created through this builder.

Inherited from:
MetricBuilder

Deprecated and Inherited methods

@deprecated("Please use `cachedGauge(name+\".\"+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.", "4.0.3")
def cachedGauge[A](name: String, timeout: FiniteDuration, scope: String)(f: => A): Gauge[A]

Registers a new gauge metric that caches its value for a given duration.

Registers a new gauge metric that caches its value for a given duration.

Value parameters:
name

the name of the gauge

scope

(deprecated) the scope of the gauge or null for no scope

timeout

the timeout

Deprecated
Inherited from:
DeprecatedMetricBuilder
@deprecated("Please use `counter(name+\".\"+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.", "4.0.3")
def counter(name: String, scope: String): Counter

Creates a new counter metric.

Creates a new counter metric.

Value parameters:
name

the name of the counter

scope

(deprecated) the scope of the counter or null for no scope

Deprecated
Inherited from:
DeprecatedMetricBuilder
@deprecated("Please use `gauge(name+\".\"+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.", "4.0.3")
def gauge[A](name: String, scope: String)(f: => A): Gauge[A]

Registers a new gauge metric.

Registers a new gauge metric.

Value parameters:
name

the name of the gauge

scope

(deprecated) the scope of the gauge or null for no scope

Deprecated
Inherited from:
DeprecatedMetricBuilder
@deprecated("Please use `histogram(name+\".\"+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.", "4.0.3")
def histogram(name: String, scope: String): Histogram

Creates a new histogram metric.

Creates a new histogram metric.

Value parameters:
name

the name of the histogram

scope

(deprecated) the scope of the histogram or null for no scope

Deprecated
Inherited from:
DeprecatedMetricBuilder
@deprecated("Please use `meter(name+\".\"+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.", "4.0.3")
def meter(name: String, scope: String): Meter

Creates a new meter metric.

Creates a new meter metric.

Value parameters:
name

the name of the meter

scope

(deprecated) the scope of the meter or null for no scope

Deprecated
Inherited from:
DeprecatedMetricBuilder
@deprecated("Do not use metricNameFor, it is an internal API. This method will be removed in v5.0.0.", "4.0.3")
protected def metricNameFor(name: String, scope: String): String
Deprecated
Inherited from:
DeprecatedMetricBuilder
@deprecated("Please use `timer(name+\".\"+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.", "4.0.3")
def timer(name: String, scope: String): Timer

Creates a new timer metric.

Creates a new timer metric.

Value parameters:
name

the name of the timer

scope

(deprecated) the scope of the timer or null for no scope

Deprecated
Inherited from:
DeprecatedMetricBuilder