Class MetricReceiver

  • Direct Known Subclasses:
    MetricReceiver.MockReceiver

    @Beta
    public class MetricReceiver
    extends java.lang.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
    • Constructor Summary

      Constructors 
      Constructor Description
      MetricReceiver​(com.yahoo.concurrent.ThreadLocalDirectory<Bucket,​Sample> metricsCollection, java.util.concurrent.atomic.AtomicReference<Bucket> currentSnapshot)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Counter declareCounter​(java.lang.String name)
      Declare a counter metric without setting any default position.
      Counter declareCounter​(java.lang.String name, Point boundDimensions)
      Declare a counter metric, with default dimension values as given.
      Gauge declareGauge​(java.lang.String name)
      Declare a gauge metric with any default position.
      Gauge declareGauge​(java.lang.String name, Point boundDimensions)
      Declare a gauge metric, with default dimension values as given.
      Gauge declareGauge​(java.lang.String name, java.util.Optional<Point> boundDimensions, MetricSettings customSettings)
      Declare a gauge metric, with default dimension values as given.
      Bucket getSnapshot()
      Fetch the latest metric values, aggregated over all threads for the configured sample history (by default five minutes).
      PointBuilder pointBuilder()
      Create a PointBuilder instance with no default settings.
      void update​(Sample s)
      Update a metric.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • nullImplementation

        public static final MetricReceiver nullImplementation
    • Constructor Detail

      • MetricReceiver

        public MetricReceiver​(com.yahoo.concurrent.ThreadLocalDirectory<Bucket,​Sample> metricsCollection,
                              java.util.concurrent.atomic.AtomicReference<Bucket> currentSnapshot)
    • Method Detail

      • declareCounter

        public Counter declareCounter​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String name,
                                  java.util.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