Class 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 Detail

      • nullImplementation

        public static final MetricReceiver nullImplementation
    • Constructor Detail

    • Method Detail

      • 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