Interface CounterDataPoint

All Superinterfaces:
DataPoint
All Known Implementing Classes:
Counter

public interface CounterDataPoint extends DataPoint
Represents a single counter data point, i.e. a single line for a counter metric in Prometheus text format.

Example usage:


 Counter counter = Counter.builder()
     .name("tasks_total")
     .labelNames("status")
     .register();
 CounterDataPoint newTasks = counter.labelValues("new");
 CounterDataPoint pendingTasks = counter.labelValues("pending");
 CounterDataPoint completedTasks = counter.labelValues("completed");
 

Using DataPoint directly improves performance. If you increment a counter like this:


 counter.labelValues("pending").inc();
 
the label value "pending" needs to be looked up every single time. Using the CounterDataPoint like this:

 CounterDataPoint pendingTasks = counter.labelValues("pending");
 pendingTasks.inc();
 
allows you to look up the label value only once, and then use the CounterDataPoint directly. This is a worthwhile performance improvement when instrumenting a performance-critical code path.

If you have a counter without labels like this:


 Counter counterWithoutLabels = Counter.builder()
     .name("events_total")
     .register();
 
You can use it as a CounterDataPoint directly. So the following:

 CounterDataPoint counterData = counterWithoutLabels.labelValues(); // empty label values
 
is equivalent to

 CounterDataPoint counterData = counterWithoutLabels;
 
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    get()
    Get the current value.
    long
    Get the current value as a long.
    default void
    inc()
    Add one.
    void
    inc(double amount)
    Add amount.
    default void
    inc(long amount)
    Add amount.
    void
    incWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels)
    Add amount, and create a custom exemplar with the given labels.
    default void
    incWithExemplar(long amount, io.prometheus.metrics.model.snapshots.Labels labels)
    Add amount, and create a custom exemplar with the given labels.
    default void
    incWithExemplar(io.prometheus.metrics.model.snapshots.Labels labels)
    Add one, and create a custom exemplar with the given labels.
  • Method Details

    • inc

      default void inc()
      Add one.
    • inc

      default void inc(long amount)
      Add amount. Throws an IllegalArgumentException if amount is negative.
    • inc

      void inc(double amount)
      Add amount. Throws an IllegalArgumentException if amount is negative.
    • incWithExemplar

      default void incWithExemplar(io.prometheus.metrics.model.snapshots.Labels labels)
      Add one, and create a custom exemplar with the given labels.
    • incWithExemplar

      default void incWithExemplar(long amount, io.prometheus.metrics.model.snapshots.Labels labels)
      Add amount, and create a custom exemplar with the given labels. Throws an IllegalArgumentException if amount is negative.
    • incWithExemplar

      void incWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels)
      Add amount, and create a custom exemplar with the given labels. Throws an IllegalArgumentException if amount is negative.
    • get

      double get()
      Get the current value.
    • getLongValue

      long getLongValue()
      Get the current value as a long. Decimal places will be discarded.