Class MetricReceiver

java.lang.Object
com.yahoo.metrics.simple.MetricReceiver
Direct Known Subclasses:
MetricReceiver.MockReceiver

public class MetricReceiver extends Object
The reception point for measurements. This is the class users should inject in constructors for declaring instances of Counter and Gauge for the actual measurement of metrics.
Author:
Steinar Knutsen
  • Field Details

    • nullImplementation

      public static final MetricReceiver nullImplementation
  • Constructor Details

  • Method Details

    • update

      public void update(Sample sample)
      Update a metric. This API is not intended for clients for the simplemetrics API, declare a Counter or a Gauge using declareCounter(String), declareCounter(String, Point), declareGauge(String), or declareGauge(String, Point) instead.
      Parameters:
      sample - a single simple containing all meta data necessary to update a metric
    • declareCounter

      public Counter declareCounter(String name)
      Declare a counter metric without setting any default position.
      Parameters:
      name - the name of the metric
      Returns:
      a thread-safe counter
    • declareCounter

      public Counter declareCounter(String name, Point boundDimensions)
      Declare a counter metric, with default dimension values as given. Create the point argument by using a builder from pointBuilder().
      Parameters:
      name - the name of the metric
      boundDimensions - dimensions which have a fixed value in the life cycle of the metric object or null
      Returns:
      a thread-safe counter with given default values
    • declareGauge

      public Gauge declareGauge(String name)
      Declare a gauge metric with any default position.
      Parameters:
      name - the name of the metric
      Returns:
      a thread-safe gauge instance
    • declareGauge

      public Gauge declareGauge(String name, Point boundDimensions)
      Declare a gauge metric, with default dimension values as given. Create the point argument by using a builder from pointBuilder().
      Parameters:
      name - the name of the metric
      boundDimensions - dimensions which have a fixed value in the life cycle of the metric object or null
      Returns:
      a thread-safe gauge metric
    • declareGauge

      public Gauge declareGauge(String name, Optional<Point> boundDimensions, MetricSettings customSettings)
      Declare a gauge metric, with default dimension values as given. Create the point argument by using a builder from pointBuilder(). MetricSettings instances are built using MetricSettings.Builder.
      Parameters:
      name - the name of the metric
      boundDimensions - an optional of dimensions which have a fixed value in the life cycle of the metric object
      customSettings - any optional settings
      Returns:
      a thread-safe gauge metric
    • pointBuilder

      public PointBuilder pointBuilder()
      Create a PointBuilder instance with no default settings. PointBuilder instances are not thread-safe.
      Returns:
      an "empty" point builder instance
    • getSnapshot

      public Bucket getSnapshot()
      Fetch the latest metric values, aggregated over all threads for the configured sample history (by default five minutes). The values will be less than 1 second old, and this method has only a memory barrier as side effect.
      Returns:
      the latest five minutes of metrics