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

public class Counter extends StatefulMetric<CounterDataPoint,io.prometheus.metrics.core.metrics.Counter.DataPoint> implements CounterDataPoint
Counter metric.

Example usage:


 Counter requestCount = Counter.builder()
     .name("requests_total")
     .help("Total number of requests")
     .labelNames("path", "status")
     .register();
 requestCount.labelValues("/hello-world", "200").inc();
 requestCount.labelValues("/hello-world", "500").inc();
 
  • Method Details

    • inc

      public void inc(long amount)
      Description copied from interface: CounterDataPoint
      Add amount. Throws an IllegalArgumentException if amount is negative.
      Specified by:
      inc in interface CounterDataPoint
    • inc

      public void inc(double amount)
      Description copied from interface: CounterDataPoint
      Add amount. Throws an IllegalArgumentException if amount is negative.
      Specified by:
      inc in interface CounterDataPoint
    • incWithExemplar

      public void incWithExemplar(long amount, io.prometheus.metrics.model.snapshots.Labels labels)
      Description copied from interface: CounterDataPoint
      Add amount, and create a custom exemplar with the given labels. Throws an IllegalArgumentException if amount is negative.
      Specified by:
      incWithExemplar in interface CounterDataPoint
    • incWithExemplar

      public void incWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels)
      Description copied from interface: CounterDataPoint
      Add amount, and create a custom exemplar with the given labels. Throws an IllegalArgumentException if amount is negative.
      Specified by:
      incWithExemplar in interface CounterDataPoint
    • get

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

      public long getLongValue()
      Description copied from interface: CounterDataPoint
      Get the current value as a long. Decimal places will be discarded.
      Specified by:
      getLongValue in interface CounterDataPoint
    • collect

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

      protected io.prometheus.metrics.model.snapshots.CounterSnapshot collect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<io.prometheus.metrics.core.metrics.Counter.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<CounterDataPoint,io.prometheus.metrics.core.metrics.Counter.DataPoint>
    • newDataPoint

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

      public static Counter.Builder builder()
    • builder

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