Class LongGauge

  • Direct Known Subclasses:
    LongGauge.NoopLongGauge, LongGaugeImpl

    @ThreadSafe
    public abstract class LongGauge
    extends java.lang.Object
    Long Gauge metric, to report instantaneous measurement of an int64 value. Gauges can go both up and down. The gauges values can be negative.

    Example 1: Create a Gauge with default labels.

    
     class YourClass {
    
       private static final MetricRegistry metricRegistry = Metrics.getMetricRegistry();
    
       List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
    
       LongGauge gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
    
       // It is recommended to keep a reference of a point for manual operations.
       LongPoint defaultPoint = gauge.getDefaultTimeSeries();
    
       void doWork() {
          // Your code here.
          defaultPoint.add(10);
       }
    
     }
     

    Example 2: You can also use labels(keys and values) to track different types of metric.

    
     class YourClass {
    
       private static final MetricRegistry metricRegistry = Metrics.getMetricRegistry();
    
       List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
       List<LabelValue> labelValues = Arrays.asList(LabelValue.create("Inbound"));
    
       LongGauge gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
    
       // It is recommended to keep a reference of a point for manual operations.
       LongPoint inboundPoint = gauge.getOrCreateTimeSeries(labelValues);
    
       void doSomeWork() {
          // Your code here.
          inboundPoint.set(15);
       }
    
     }
     
    Since:
    0.17
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LongGauge.LongPoint
      The value of a single point in the Gauge.TimeSeries.
      private static class  LongGauge.NoopLongGauge
      No-op implementations of LongGauge class.
    • Constructor Summary

      Constructors 
      Constructor Description
      LongGauge()  
    • Constructor Detail

      • LongGauge

        public LongGauge()
    • Method Detail

      • getDefaultTimeSeries

        public abstract LongGauge.LongPoint getDefaultTimeSeries()
        Returns a LongPoint for a gauge with all labels not set, or default labels.
        Returns:
        a LongPoint for a gauge with all labels not set, or default labels.
        Since:
        0.17
      • removeTimeSeries

        public abstract void removeTimeSeries​(java.util.List<LabelValue> labelValues)
        Removes the TimeSeries from the gauge metric, if it is present. i.e. references to previous LongPoint objects are invalid (not part of the metric).
        Parameters:
        labelValues - the list of label values.
        Throws:
        java.lang.NullPointerException - if labelValues is null.
        Since:
        0.17
      • clear

        public abstract void clear()
        Removes all TimeSeries from the gauge metric. i.e. references to all previous LongPoint objects are invalid (not part of the metric).
        Since:
        0.17
      • newNoopLongGauge

        static LongGauge newNoopLongGauge​(java.lang.String name,
                                          java.lang.String description,
                                          java.lang.String unit,
                                          java.util.List<LabelKey> labelKeys)
        Returns the no-op implementation of the LongGauge.
        Returns:
        the no-op implementation of the LongGauge.
        Since:
        0.17