Class LongGauge

java.lang.Object
io.opencensus.metrics.LongGauge
Direct Known Subclasses:
LongGauge.NoopLongGauge, LongGaugeImpl

@ThreadSafe public abstract class LongGauge extends 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