All Implemented Interfaces:
DataPoint, GaugeDataPoint, TimerApi, io.prometheus.metrics.model.registry.Collector

public class Gauge extends StatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint> implements GaugeDataPoint
Gauge metric.

Example usage:


 Gauge currentActiveUsers = Gauge.builder()
     .name("current_active_users")
     .help("Number of users that are currently active")
     .labelNames("region")
     .register();

 public void login(String region) {
     currentActiveUsers.labelValues(region).inc();
     // perform login
 }

 public void logout(String region) {
     currentActiveUsers.labelValues(region).dec();
     // perform logout
 }
 
  • Method Details

    • inc

      public void inc(double amount)
      Description copied from interface: GaugeDataPoint
      Add amount.
      Specified by:
      inc in interface GaugeDataPoint
    • get

      public double get()
      Description copied from interface: GaugeDataPoint
      Get the current value.
      Specified by:
      get in interface GaugeDataPoint
    • incWithExemplar

      public void incWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels)
      Description copied from interface: GaugeDataPoint
      Add amount, and create a custom exemplar with the given labels.
      Specified by:
      incWithExemplar in interface GaugeDataPoint
    • set

      public void set(double value)
      Description copied from interface: GaugeDataPoint
      Set the gauge to value.
      Specified by:
      set in interface GaugeDataPoint
    • setWithExemplar

      public void setWithExemplar(double value, io.prometheus.metrics.model.snapshots.Labels labels)
      Description copied from interface: GaugeDataPoint
      Set the gauge to value, and create a custom exemplar with the given labels.
      Specified by:
      setWithExemplar in interface GaugeDataPoint
    • collect

      public io.prometheus.metrics.model.snapshots.GaugeSnapshot collect()
      Specified by:
      collect in interface io.prometheus.metrics.model.registry.Collector
      Overrides:
      collect in class StatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
    • collect

      protected io.prometheus.metrics.model.snapshots.GaugeSnapshot collect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<io.prometheus.metrics.core.metrics.Gauge.DataPoint> metricData)
      Description copied from class: StatefulMetric
      labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i).
      Specified by:
      collect in class StatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
    • newDataPoint

      protected io.prometheus.metrics.core.metrics.Gauge.DataPoint newDataPoint()
      Specified by:
      newDataPoint in class StatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
    • builder

      public static Gauge.Builder builder()
    • builder

      public static Gauge.Builder builder(io.prometheus.metrics.config.PrometheusProperties config)