Interface CounterDataPoint
- All Superinterfaces:
DataPoint
- All Known Implementing Classes:
Counter
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 TypeMethodDescriptiondouble
get()
Get the current value.long
Get the current value as along
.default void
inc()
Add one.void
inc
(double amount) Addamount
.default void
inc
(long amount) Addamount
.void
incWithExemplar
(double amount, Labels labels) Addamount
, and create a custom exemplar with the given labels.default void
incWithExemplar
(long amount, Labels labels) Addamount
, and create a custom exemplar with the given labels.default void
incWithExemplar
(Labels labels) Add one, and create a custom exemplar with the given labels.
-
Method Details
-
inc
Add one. -
inc
-
inc
-
incWithExemplar
Add one, and create a custom exemplar with the given labels. -
incWithExemplar
Addamount
, and create a custom exemplar with the given labels. Throws anIllegalArgumentException
ifamount
is negative. -
incWithExemplar
Addamount
, and create a custom exemplar with the given labels. Throws anIllegalArgumentException
ifamount
is negative. -
get
double get()Get the current value. -
getLongValue
long getLongValue()Get the current value as along
. Decimal places will be discarded.
-