Trait

nl.grons.metrics.scala

DefaultInstrumented

Related Doc: package scala

Permalink

trait DefaultInstrumented extends InstrumentedBuilder with CheckedBuilder

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.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DefaultInstrumented
  2. CheckedBuilder
  3. InstrumentedBuilder
  4. BaseBuilder
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. def healthCheck[T](name: String, unhealthyMessage: String = "Health check failed")(checker: ⇒ T)(implicit toMagnet: (ByName[T]) ⇒ HealthCheckMagnet): HealthCheck

    Permalink

    Converts a code block to a com.codahale.metrics.health.HealthCheck and registers it.

    Converts a code block to a com.codahale.metrics.health.HealthCheck and registers it.

    Use it as follows:

    object Application {
      // The application wide health check registry.
      val healthCheckRegistry = new com.codahale.metrics.health.HealthCheckRegistry()
    }
    trait Checked extends CheckedBuilder {
      val registry = Application.healthCheckRegistry
    }
    
    class ExampleWorker extends Checked {
      healthCheck("alive") { workerThreadIsActive() }
    }

    The code block must have a result of type Boolean, Try, Either, Future, com.codahale.metrics.health.HealthCheck.Result, or simply Unit.

    • A check result of true indicates healthy, false indicates unhealthy.
    • A check result of type Success indicates healthy, Failure indicates unhealthy. The embedded value (after applying .toString) or throwable is used as (un)healthy message.
    • A check result of type Future will have 3 seconds to execute (by default). The result of the execution will be treated as Success or Failure.
    • A check result of type Right indicates healthy, Left[Any] or Left[Throwable] indicates unhealthy. The embedded value (after applying .toString) or throwable is used as (un)healthy message.
    • If the check result is of type com.codahale.metrics.health.HealthCheck.Result, the result is passed unchanged.
    • A check result of type Unit indicates healthy.
    • If a checker throws an exception, the result is considered unhealthy with the throwable as unhealthy message.

    It is also possible to override the health check base name. For example:

    class ExampleWorker extends Checked {
      override lazy val metricBaseName = MetricName("Overridden.Base.Name")
      healthCheck("alive") { workerThreadIsActive() }
    }

    To change the timeout for Future execution, set an implicit duration:

    class ExampleWorker extends Checked {
      implicit private val timeout = 10.seconds
      healthCheck("alive")(Future { workerThreadIsActive() })
    }
    name

    the name of the health check

    unhealthyMessage

    the unhealthy message for checkers that return false, defaults to "Health check failed"

    checker

    the code block that does the health check

    Definition Classes
    CheckedBuilder
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. lazy val metricBaseName: MetricName

    Permalink

    The base name for all metrics created from this builder.

    The base name for all metrics created from this builder.

    Definition Classes
    BaseBuilder
  14. lazy val metricBuilder: MetricBuilder

    Permalink
    Attributes
    protected
    Definition Classes
    InstrumentedBuilder
  15. val metricRegistry: MetricRegistry

    Permalink

    The MetricRegistry where created metrics are registered.

    The MetricRegistry where created metrics are registered.

    Definition Classes
    DefaultInstrumentedInstrumentedBuilder
  16. def metrics: MetricBuilder

    Permalink

    The MetricBuilder that can be used for creating timers, counters, etc.

    The MetricBuilder that can be used for creating timers, counters, etc.

    Definition Classes
    InstrumentedBuilder
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. val registry: HealthCheckRegistry

    Permalink

    The com.codahale.metrics.health.HealthCheckRegistry where created metrics are registered.

    The com.codahale.metrics.health.HealthCheckRegistry where created metrics are registered.

    Definition Classes
    DefaultInstrumentedCheckedBuilder
  21. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  22. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  23. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from CheckedBuilder

Inherited from InstrumentedBuilder

Inherited from BaseBuilder

Inherited from AnyRef

Inherited from Any

Ungrouped