Class Counter
- All Implemented Interfaces:
CounterDataPoint
,DataPoint
,Collector
public class Counter
extends StatefulMetric<CounterDataPoint,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 -
Method Summary
Modifier and TypeMethodDescriptionstatic Counter.Builder
builder()
static Counter.Builder
builder
(PrometheusProperties config) collect()
Called when the Prometheus server scrapes metrics.double
get()
Get the current value.long
Get the current value as along
.void
inc
(double amount) Addamount
.void
inc
(long amount) Addamount
.void
incWithExemplar
(double amount, Labels labels) Addamount
, and create a custom exemplar with the given labels.void
incWithExemplar
(long amount, Labels labels) Addamount
, and create a custom exemplar with the given labels.Methods inherited from class StatefulMetric
clear, initLabelValues, labelValues, remove, removeIf
Methods inherited from class MetricWithFixedMetadata
getPrometheusName
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface CounterDataPoint
inc, incWithExemplar
-
Method Details
-
inc
Description copied from interface:CounterDataPoint
- Specified by:
inc
in interfaceCounterDataPoint
-
inc
Description copied from interface:CounterDataPoint
- Specified by:
inc
in interfaceCounterDataPoint
-
incWithExemplar
Description copied from interface:CounterDataPoint
Addamount
, and create a custom exemplar with the given labels. Throws anIllegalArgumentException
ifamount
is negative.- Specified by:
incWithExemplar
in interfaceCounterDataPoint
-
incWithExemplar
Description copied from interface:CounterDataPoint
Addamount
, and create a custom exemplar with the given labels. Throws anIllegalArgumentException
ifamount
is negative.- Specified by:
incWithExemplar
in interfaceCounterDataPoint
-
get
Description copied from interface:CounterDataPoint
Get the current value.- Specified by:
get
in interfaceCounterDataPoint
-
getLongValue
Description copied from interface:CounterDataPoint
Get the current value as along
. Decimal places will be discarded.- Specified by:
getLongValue
in interfaceCounterDataPoint
-
collect
Description copied from interface:Collector
Called when the Prometheus server scrapes metrics.- Specified by:
collect
in interfaceCollector
- Overrides:
collect
in classStatefulMetric<CounterDataPoint,
Counter.DataPoint>
-
builder
-
builder
-