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() } }
the name of the gauge
the timeout
a code block that does a measurement
Creates a new counter metric.
Creates a new counter metric.
the name of the counter
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() } }
the name of the gauge
a code block that does a measurement
Creates a new histogram metric.
Creates a new histogram metric.
the name of the histogram
Creates a new meter metric.
Creates a new meter metric.
the name of the meter
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) } }
the name of the gauge
the first value of the gauge, typically this is 0
, 0L
or null
.
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) } }
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.
the name of the gauge
the first and default value of the gauge, typically this is 0,
0L or
null.
the timeout
Creates a new timer metric.
Creates a new timer metric.
the name of the timer
Unregisters all gauges that were created through this builder.
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.
the name of the gauge
the timeout
(deprecated) the scope of the gauge or null for no scope
(Since version 4.0.3) Please use cachedGauge(name+"."+scope)(f)
instead. The scope parameter has been deprecated and will be removed in v5.0.0.
Creates a new counter metric.
Creates a new counter metric.
the name of the counter
(deprecated) the scope of the counter or null for no scope
(Since version 4.0.3) Please use counter(name+"."+scope)(f)
instead. The scope parameter has been deprecated and will be removed in v5.0.0.
Registers a new gauge metric.
Registers a new gauge metric.
the name of the gauge
(deprecated) the scope of the gauge or null for no scope
(Since version 4.0.3) Please use gauge(name+"."+scope)(f)
instead. The scope parameter has been deprecated and will be removed in v5.0.0.
Creates a new histogram metric.
Creates a new histogram metric.
the name of the histogram
(deprecated) the scope of the histogram or null for no scope
(Since version 4.0.3) Please use histogram(name+"."+scope)(f)
instead. The scope parameter has been deprecated and will be removed in v5.0.0.
Creates a new meter metric.
Creates a new meter metric.
the name of the meter
(deprecated) the scope of the meter or null for no scope
(Since version 4.0.3) Please use meter(name+"."+scope)(f)
instead. The scope parameter has been deprecated and will be removed in v5.0.0.
(Since version 4.0.3) Do not use metricNameFor, it is an internal API. This method will be removed in v5.0.0.
Creates a new timer metric.
Creates a new timer metric.
the name of the timer
(deprecated) the scope of the timer or null for no scope
(Since version 4.0.3) Please use timer(name+"."+scope)(f)
instead. The scope parameter has been deprecated and will be removed in v5.0.0.
Builds and registers metrics.