Class StatefulMetric<D extends DataPoint, T extends D>
java.lang.Object
io.prometheus.metrics.core.metrics.Metric
io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
io.prometheus.metrics.core.metrics.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classStatefulMetric.Builder<B extends StatefulMetric.Builder<B,M>, M extends StatefulMetric<?, ?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentHashMap<List<String>, T> Map label values to data points.private TShortcut for data.get(Collections.emptyList())Fields inherited from class MetricWithFixedMetadata
labelNamesFields inherited from class Metric
constLabels -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Reset the metric (remove all data points).collect()Called when the Prometheus server scrapes metrics.protected abstract MetricSnapshotlabels and metricData have the same size.protected <P> PgetConfigProperty(MetricsProperties[] properties, Function<MetricsProperties, P> getter) protected MetricsProperties[]getMetricProperties(StatefulMetric.Builder<?, ?> builder, PrometheusProperties prometheusProperties) Metric properties in effect by order of precedence with the highest precedence first.protected TvoidinitLabelValues(String... labelValues) Initialize label values.labelValues(String... labelValues) protected abstract TvoidRemove 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collector
collect, collect, collect, getMetricType
-
Field Details
-
data
Map label values to data points. -
noLabels
-
-
Constructor Details
-
StatefulMetric
-
-
Method Details
-
collect
labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i). -
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
public void clear()Reset the metric (remove all data points). -
newDataPoint
-
getNoLabels
-
getMetricProperties
protected MetricsProperties[] getMetricProperties(StatefulMetric.Builder<?, ?> builder, PrometheusProperties prometheusProperties) Metric properties in effect by order of precedence with the highest precedence first. If aMetricPropertiesis configured for the metric name it has higher precedence than the builder configuration. A special case is the settingStatefulMetric.Builder.withoutExemplars()via the builder, which cannot be overridden by any configuration. -
getConfigProperty
protected <P> P getConfigProperty(MetricsProperties[] properties, Function<MetricsProperties, P> getter)
-