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 TypeMethodDescriptiondoubleget()Get the current value.longGet the current value as along.default voidinc()Add one.voidinc(double amount) Addamount.default voidinc(long amount) Addamount.voidincWithExemplar(double amount, Labels labels) Addamount, and create a custom exemplar with the given labels.default voidincWithExemplar(long amount, Labels labels) Addamount, and create a custom exemplar with the given labels.default voidincWithExemplar(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 anIllegalArgumentExceptionifamountis negative. -
incWithExemplar
Addamount, and create a custom exemplar with the given labels. Throws anIllegalArgumentExceptionifamountis negative. -
get
double get()Get the current value. -
getLongValue
long getLongValue()Get the current value as along. Decimal places will be discarded.
-