Class Gauge
java.lang.Object
io.prometheus.metrics.core.metrics.Metric
io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
io.prometheus.metrics.core.metrics.Gauge
- All Implemented Interfaces:
DataPoint
,GaugeDataPoint
,TimerApi
,io.prometheus.metrics.model.registry.Collector
Gauge metric.
Example usage:
Gauge currentActiveUsers = Gauge.newBuilder()
.withName("current_active_users")
.withHelp("Number of users that are currently active")
.withLabelNames("region")
.register();
public void login(String region) {
currentActiveUsers.withLabelValues(region).inc();
// perform login
}
public void logout(String region) {
currentActiveUsers.withLabelValues(region).dec();
// perform logout
}
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
labelNames
Fields inherited from class io.prometheus.metrics.core.metrics.Metric
constLabels
-
Method Summary
Modifier and TypeMethodDescriptionio.prometheus.metrics.model.snapshots.GaugeSnapshot
collect()
protected io.prometheus.metrics.model.snapshots.GaugeSnapshot
collect
(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<io.prometheus.metrics.core.metrics.Gauge.DataPoint> metricData) labels and metricData have the same size.protected <T> T
getConfigProperty
(io.prometheus.metrics.config.MetricsProperties[] properties, Function<io.prometheus.metrics.config.MetricsProperties, T> getter) protected io.prometheus.metrics.config.MetricsProperties[]
getMetricProperties
(io.prometheus.metrics.core.metrics.StatefulMetric.Builder builder, io.prometheus.metrics.config.PrometheusProperties prometheusProperties) protected io.prometheus.metrics.core.metrics.Gauge.DataPoint
void
inc
(double amount) Addamount
.void
incWithExemplar
(double amount, io.prometheus.metrics.model.snapshots.Labels labels) Addamount
, and create a custom exemplar with the given labels.void
initLabelValues
(String... labelValues) Initialize label values.protected boolean
static Gauge.Builder
static Gauge.Builder
newBuilder
(io.prometheus.metrics.config.PrometheusProperties config) protected io.prometheus.metrics.core.metrics.Gauge.DataPoint
void
void
set
(double value) Set the gauge tovalue
.void
setWithExemplar
(double value, io.prometheus.metrics.model.snapshots.Labels labels) Set the gauge tovalue
, and create a custom exemplar with the given labels.withLabelValues
(String... labelValues) Methods inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
getMetadata
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.prometheus.metrics.model.registry.Collector
collect, getPrometheusName
Methods inherited from interface io.prometheus.metrics.core.datapoints.GaugeDataPoint
dec, dec, decWithExemplar, decWithExemplar, inc, incWithExemplar, startTimer
Methods inherited from interface io.prometheus.metrics.core.datapoints.TimerApi
time, time, timeChecked
-
Method Details
-
inc
Addamount
.- Specified by:
inc
in interfaceGaugeDataPoint
-
incWithExemplar
Addamount
, and create a custom exemplar with the given labels.- Specified by:
incWithExemplar
in interfaceGaugeDataPoint
-
set
Set the gauge tovalue
.- Specified by:
set
in interfaceGaugeDataPoint
-
setWithExemplar
Set the gauge tovalue
, and create a custom exemplar with the given labels.- Specified by:
setWithExemplar
in interfaceGaugeDataPoint
-
collect
- Specified by:
collect
in interfaceio.prometheus.metrics.model.registry.Collector
-
collect
protected io.prometheus.metrics.model.snapshots.GaugeSnapshot collect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<io.prometheus.metrics.core.metrics.Gauge.DataPoint> metricData) labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i). -
newDataPoint
-
isExemplarsEnabled
-
newBuilder
-
newBuilder
-
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.0
Now, the data points for thepayment_type
label values get initialized when they are first used, i.e. the first time you call
the data point with labelcounter.withLabelValues("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.0
initLabelValues(...)
can be used to initialize label value, so that the data points show up in the exposition format with an initial value of zero. -
withLabelValues
-
remove
-
getNoLabels
protected io.prometheus.metrics.core.metrics.Gauge.DataPoint getNoLabels() -
getMetricProperties
protected io.prometheus.metrics.config.MetricsProperties[] getMetricProperties(io.prometheus.metrics.core.metrics.StatefulMetric.Builder builder, io.prometheus.metrics.config.PrometheusProperties prometheusProperties) -
getConfigProperty
protected <T> T getConfigProperty(io.prometheus.metrics.config.MetricsProperties[] properties, Function<io.prometheus.metrics.config.MetricsProperties, T> getter)
-