Object
Metric
MetricWithFixedMetadata
Counter
- All Implemented Interfaces:
CounterDataPoint,DataPoint,Collector
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();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Counter.Builderbuilder()static Counter.Builderbuilder(PrometheusProperties config) voidclear()Reset the metric (remove all data points).CounterSnapshotcollect()doubleget()Get the current value.longGet the current value as along.voidinc(double amount) Addamount.voidinc(long amount) Addamount.voidincWithExemplar(double amount, Labels labels) Addamount, and create a custom exemplar with the given labels.voidincWithExemplar(long amount, Labels labels) Addamount, and create a custom exemplar with the given labels.voidinitLabelValues(String... labelValues) Initialize label values.labelValues(String... labelValues) voidRemove the data point with the given label values.Methods inherited from class MetricWithFixedMetadata
getPrometheusNameMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collector
collect, collect, collectMethods inherited from interface CounterDataPoint
inc, incWithExemplar
-
Method Details
-
inc
- Specified by:
incin interfaceCounterDataPoint
-
inc
- Specified by:
incin interfaceCounterDataPoint
-
incWithExemplar
Addamount, and create a custom exemplar with the given labels. Throws anIllegalArgumentExceptionifamountis negative.- Specified by:
incWithExemplarin interfaceCounterDataPoint
-
incWithExemplar
Addamount, and create a custom exemplar with the given labels. Throws anIllegalArgumentExceptionifamountis negative.- Specified by:
incWithExemplarin interfaceCounterDataPoint
-
get
Get the current value.- Specified by:
getin interfaceCounterDataPoint
-
getLongValue
Get the current value as along. Decimal places will be discarded.- Specified by:
getLongValuein interfaceCounterDataPoint
-
collect
- Specified by:
collectin interfaceCollector
-
builder
-
builder
-
initLabelValues
Initialize label values.Example: Imagine you have a counter for payments as follows
payment_transactions_total{payment_type="credit card"} 7.0 payment_transactions_total{payment_type="paypal"} 3.0Now, the data points for thepayment_typelabel values get initialized when they are first used, i.e. the first time you call
the data point with labelcounter.labelValues("paypal").inc();payment_type="paypal"will go from non-existent to having value1.0.In some cases this is confusing, and you want to have data points initialized on application start with an initial value of
0.0:payment_transactions_total{payment_type="credit card"} 0.0 payment_transactions_total{payment_type="paypal"} 0.0initLabelValues(...)can be used to initialize label value, so that the data points show up in the exposition format with an initial value of zero. -
labelValues
-
remove
Remove the data point with the given label values. See https://prometheus.io/docs/instrumenting/writing_clientlibs/#labels. -
clear
public void clear()Reset the metric (remove all data points).
-