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, Labels labels)
    Add amount, and create a custom exemplar with the given labels.
    default void
    incWithExemplar(long amount, Labels labels)
    Add amount, and create a custom exemplar with the given labels.
    default void
    Add one, and create a custom exemplar with the given labels.