java.lang.Object
io.prometheus.metrics.core.metrics.Metric
io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
io.prometheus.metrics.core.metrics.StatefulMetric<CounterDataPoint,io.prometheus.metrics.core.metrics.Counter.DataPoint>
io.prometheus.metrics.core.metrics.Counter
- All Implemented Interfaces:
CounterDataPoint,DataPoint,io.prometheus.metrics.model.registry.Collector
public class Counter
extends StatefulMetric<CounterDataPoint,io.prometheus.metrics.core.metrics.Counter.DataPoint>
implements CounterDataPoint
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 -
Field Summary
Fields inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
labelNamesFields inherited from class io.prometheus.metrics.core.metrics.Metric
constLabels -
Method Summary
Modifier and TypeMethodDescriptionstatic Counter.Builderbuilder()static Counter.Builderbuilder(io.prometheus.metrics.config.PrometheusProperties config) io.prometheus.metrics.model.snapshots.CounterSnapshotcollect()protected io.prometheus.metrics.model.snapshots.CounterSnapshotcollect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<io.prometheus.metrics.core.metrics.Counter.DataPoint> metricData) labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i).doubleget()Get the current value.longGet the current value as along.voidinc(double amount) Addamount.voidinc(long amount) Addamount.voidincWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels) Addamount, and create a custom exemplar with the given labels.voidincWithExemplar(long amount, io.prometheus.metrics.model.snapshots.Labels labels) Addamount, and create a custom exemplar with the given labels.protected io.prometheus.metrics.core.metrics.Counter.DataPointMethods inherited from class io.prometheus.metrics.core.metrics.StatefulMetric
clear, getConfigProperty, getMetricProperties, getNoLabels, initLabelValues, labelValues, remove, removeIfMethods inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
getMetadata, getPrometheusNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.prometheus.metrics.model.registry.Collector
collect, collect, collectMethods inherited from interface io.prometheus.metrics.core.datapoints.CounterDataPoint
inc, incWithExemplar
-
Method Details
-
inc
public void inc(long amount) Description copied from interface:CounterDataPoint- Specified by:
incin interfaceCounterDataPoint
-
inc
public void inc(double amount) Description copied from interface:CounterDataPoint- Specified by:
incin interfaceCounterDataPoint
-
incWithExemplar
public void incWithExemplar(long amount, io.prometheus.metrics.model.snapshots.Labels labels) Description copied from interface:CounterDataPointAddamount, and create a custom exemplar with the given labels. Throws anIllegalArgumentExceptionifamountis negative.- Specified by:
incWithExemplarin interfaceCounterDataPoint
-
incWithExemplar
public void incWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels) Description copied from interface:CounterDataPointAddamount, and create a custom exemplar with the given labels. Throws anIllegalArgumentExceptionifamountis negative.- Specified by:
incWithExemplarin interfaceCounterDataPoint
-
get
public double get()Description copied from interface:CounterDataPointGet the current value.- Specified by:
getin interfaceCounterDataPoint
-
getLongValue
public long getLongValue()Description copied from interface:CounterDataPointGet the current value as along. Decimal places will be discarded.- Specified by:
getLongValuein interfaceCounterDataPoint
-
collect
public io.prometheus.metrics.model.snapshots.CounterSnapshot collect()- Specified by:
collectin interfaceio.prometheus.metrics.model.registry.Collector- Overrides:
collectin classStatefulMetric<CounterDataPoint,io.prometheus.metrics.core.metrics.Counter.DataPoint>
-
collect
protected io.prometheus.metrics.model.snapshots.CounterSnapshot collect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<io.prometheus.metrics.core.metrics.Counter.DataPoint> metricData) Description copied from class:StatefulMetriclabels and metricData have the same size. labels.get(i) are the labels for metricData.get(i).- Specified by:
collectin classStatefulMetric<CounterDataPoint,io.prometheus.metrics.core.metrics.Counter.DataPoint>
-
newDataPoint
protected io.prometheus.metrics.core.metrics.Counter.DataPoint newDataPoint()- Specified by:
newDataPointin classStatefulMetric<CounterDataPoint,io.prometheus.metrics.core.metrics.Counter.DataPoint>
-
builder
-
builder
-