c

nl.grons.metrics4.scala

MetricBuilder

class MetricBuilder extends DeprecatedMetricBuilder

Builds and registers metrics.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MetricBuilder
  2. DeprecatedMetricBuilder
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new MetricBuilder(baseName: MetricName, registry: MetricRegistry)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. val baseName: MetricName
  6. 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()
      }
    }
    name

    the name of the gauge

    timeout

    the timeout

    f

    a code block that does a measurement

    Exceptions thrown

    IllegalArgumentException when a metric with the given name already exists

  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. def counter(name: String): Counter

    Creates a new counter metric.

    Creates a new counter metric.

    name

    the name of the counter

  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  12. 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()
      }
    }
    name

    the name of the gauge

    f

    a code block that does a measurement

    Exceptions thrown

    IllegalArgumentException when a metric with the given name already exists

  13. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. def histogram(name: String): Histogram

    Creates a new histogram metric.

    Creates a new histogram metric.

    name

    the name of the histogram

  16. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  17. def meter(name: String): Meter

    Creates a new meter metric.

    Creates a new meter metric.

    name

    the name of the meter

  18. def metricNameFor(name: String): String
    Attributes
    protected
  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. 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.

    name

    the name of the gauge

    startValue

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

  23. 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.

    name

    the name of the gauge

    defaultValue

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

    timeout

    the timeout

  24. val registry: MetricRegistry
  25. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  26. def timer(name: String): Timer

    Creates a new timer metric.

    Creates a new timer metric.

    name

    the name of the timer

  27. def toString(): String
    Definition Classes
    AnyRef → Any
  28. def unregisterGauges(): Unit

    Unregisters all gauges that were created through this builder.

  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def cachedGauge[A](name: String, timeout: FiniteDuration, scope: String = null)(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.

    name

    the name of the gauge

    timeout

    the timeout

    scope

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

    Definition Classes
    DeprecatedMetricBuilder
    Annotations
    @deprecated
    Deprecated

    (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.

  2. def counter(name: String, scope: String = null): Counter

    Creates a new counter metric.

    Creates a new counter metric.

    name

    the name of the counter

    scope

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

    Definition Classes
    DeprecatedMetricBuilder
    Annotations
    @deprecated
    Deprecated

    (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.

  3. def gauge[A](name: String, scope: String = null)(f: => A): Gauge[A]

    Registers a new gauge metric.

    Registers a new gauge metric.

    name

    the name of the gauge

    scope

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

    Definition Classes
    DeprecatedMetricBuilder
    Annotations
    @deprecated
    Deprecated

    (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.

  4. def histogram(name: String, scope: String = null): Histogram

    Creates a new histogram metric.

    Creates a new histogram metric.

    name

    the name of the histogram

    scope

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

    Definition Classes
    DeprecatedMetricBuilder
    Annotations
    @deprecated
    Deprecated

    (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.

  5. def meter(name: String, scope: String = null): Meter

    Creates a new meter metric.

    Creates a new meter metric.

    name

    the name of the meter

    scope

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

    Definition Classes
    DeprecatedMetricBuilder
    Annotations
    @deprecated
    Deprecated

    (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.

  6. def metricNameFor(name: String, scope: String = null): String
    Attributes
    protected
    Definition Classes
    DeprecatedMetricBuilder
    Annotations
    @deprecated
    Deprecated

    (Since version 4.0.3) Do not use metricNameFor, it is an internal API. This method will be removed in v5.0.0.

  7. def timer(name: String, scope: String = null): Timer

    Creates a new timer metric.

    Creates a new timer metric.

    name

    the name of the timer

    scope

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

    Definition Classes
    DeprecatedMetricBuilder
    Annotations
    @deprecated
    Deprecated

    (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.

Inherited from AnyRef

Inherited from Any

Ungrouped