Class StatefulMetric<D extends DataPoint, T extends D>
Object
Metric
MetricWithFixedMetadata
StatefulMetric<D,T>
- All Implemented Interfaces:
Collector
public abstract class StatefulMetric<D extends DataPoint, T extends D>
extends MetricWithFixedMetadata
There are two kinds of metrics:
- A
StatefulMetricactively maintains its current values, e.g. a stateful counter actively stores its current count. - A
CallbackMetricgets its values on demand when it is collected, e.g. a callback gauge representing the current heap size.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Reset the metric (remove all data points).collect()Called when the Prometheus server scrapes metrics.voidinitLabelValues(String... labelValues) Initialize label values.labelValues(String... labelValues) voidRemove the data point with the given label values.voidRemove the data points when the given function.Methods inherited from class MetricWithFixedMetadata
getLabelNames, getMetadata, getPrometheusNameMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collector
collect, collect, collect, getMetricType
-
Method Details
-
collect
-
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. -
removeIf
-
clear
Reset the metric (remove all data points).
-