Package

nl.grons.metrics

scala

Permalink

package scala

Visibility
  1. Public
  2. All

Type Members

  1. trait ActorInstrumentedLifeCycle extends Actor

    Permalink

    Stackable Actor trait which links Gauge life cycles with the actor life cycle.

    Stackable Actor trait which links Gauge life cycles with the actor life cycle.

    When an actor is restarted, gauges can not be created again under the same name in the same metric registry. By mixing in this trait, all gauges created in this actor will be automatically unregistered before this actor restarts.

    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 ExampleActor extends Actor with Instrumented with ActorInstrumentedLifecycle {
    
      var counter = 0
    
      // The following gauge will automatically unregister before a restart of this actor.
      metrics.gauge("sample-gauge"){
        counter
      }
    
      override def receive = {
        case 'increment =>
          counter += 1
          doWork()
      }
    
      def doWork(): Unit = {
        // etc etc etc
      }
    }
  2. trait BaseBuilder extends AnyRef

    Permalink
  3. final class ByName[+T] extends () ⇒ T

    Permalink

    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.

    T

    Result type of the evaluated expression

  4. trait CheckedBuilder extends BaseBuilder

    Permalink

    The mixin trait for creating a class which creates health checks.

  5. class Counter extends AnyRef

    Permalink

    A Scala facade class for DropwizardCounter.

  6. trait DefaultInstrumented extends InstrumentedBuilder with CheckedBuilder

    Permalink

    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.

  7. class Gauge[T] extends AnyRef

    Permalink

    A Scala facade class for DropwizardGauge.

  8. class HdrMetricBuilder extends MetricBuilder

    Permalink

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

    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.

  9. sealed trait HealthCheckMagnet extends AnyRef

    Permalink

    Magnet for the checker.

  10. class Histogram extends AnyRef

    Permalink

    A Scala facade class for DropwizardHistogram.

  11. trait InstrumentedBuilder extends BaseBuilder

    Permalink

    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.

  12. class Meter extends AnyRef

    Permalink

    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
      }
    }
  13. class MetricBuilder extends AnyRef

    Permalink

    Builds and registering metrics.

  14. class MetricName extends AnyRef

    Permalink

    The (base)name of a metric.

    The (base)name of a metric.

    Constructed via the companion object, e.g. MetricName(getClass, "requests").

  15. trait ReceiveCounterActor extends Actor

    Permalink

    Stackable actor trait which counts received messages.

    Stackable actor trait which counts received messages.

    Metric name defaults to the class of the actor (e.g. ExampleActor below) + .receiveCounter

    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 ExampleActor extends Actor {
    
      def receive = {
        case _ => doWork()
      }
    }
    
    class InstrumentedExampleActor extends ExampleActor with ReceiveCounterActor with Instrumented
  16. trait ReceiveExceptionMeterActor extends Actor

    Permalink

    Stackable actor trait which meters thrown exceptions.

    Stackable actor trait which meters thrown exceptions.

    Metric name defaults to the class of the actor (e.g. ExampleActor below) + .receiveExceptionMeter

    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 ExampleActor extends Actor {
    
      def receive = {
        case _ => doWork()
      }
    }
    
    class InstrumentedExampleActor extends ExampleActor with ReceiveCounterActor with Instrumented
  17. trait ReceiveTimerActor extends Actor

    Permalink

    Stackable actor trait which times the message receipt.

    Stackable actor trait which times the message receipt.

    Metric name defaults to the class of the actor (e.g. ExampleActor below) + .receiveTimer

    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 ExampleActor extends Actor {
    
      def receive = {
        case _ => doWork()
      }
    }
    
    class InstrumentedExampleActor extends ExampleActor with ReceiveCounterActor with Instrumented
  18. class Timer extends AnyRef

    Permalink

    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)
      }
    }
  19. trait FutureMetrics extends AnyRef

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 3.5.4) Please use Timer.time() or Timer.timeFuture()

Value Members

  1. object ByName

    Permalink
  2. object Gauge

    Permalink
  3. object HealthCheckMagnet

    Permalink
  4. object Implicits

    Permalink
  5. object MetricName

    Permalink

Ungrouped