java.lang.Object
io.prometheus.metrics.core.metrics.Metric
io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
io.prometheus.metrics.core.metrics.StatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
io.prometheus.metrics.core.metrics.Gauge
- All Implemented Interfaces:
DataPoint,GaugeDataPoint,TimerApi,io.prometheus.metrics.model.registry.Collector
@StableApi
public class Gauge
extends StatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
implements GaugeDataPoint
Gauge metric.
Example usage:
Gauge currentActiveUsers = Gauge.builder()
.name("current_active_users")
.help("Number of users that are currently active")
.labelNames("region")
.register();
public void login(String region) {
currentActiveUsers.labelValues(region).inc();
// perform login
}
public void logout(String region) {
currentActiveUsers.labelValues(region).dec();
// perform logout
}
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
labelNames, metadataFields inherited from class io.prometheus.metrics.core.metrics.Metric
constLabels -
Method Summary
Modifier and TypeMethodDescriptionstatic Gauge.Builderbuilder()static Gauge.Builderbuilder(io.prometheus.metrics.config.PrometheusProperties config) io.prometheus.metrics.model.snapshots.GaugeSnapshotcollect()protected io.prometheus.metrics.model.snapshots.GaugeSnapshotcollect(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).doubleget()Get the current value.io.prometheus.metrics.model.registry.MetricTypeDeprecated.voidinc(double amount) Addamount.voidincWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels) Addamount, and create a custom exemplar with the given labels.protected io.prometheus.metrics.core.metrics.Gauge.DataPointvoidset(double value) Set the gauge tovalue.voidsetWithExemplar(double value, io.prometheus.metrics.model.snapshots.Labels labels) Set the gauge tovalue, and create a custom exemplar with the given labels.Methods 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
getLabelNames, getMetadata, getMetricFamilyDescriptor, 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.GaugeDataPoint
dec, dec, decWithExemplar, decWithExemplar, inc, incWithExemplar, startTimerMethods inherited from interface io.prometheus.metrics.core.datapoints.TimerApi
time, time, timeChecked
-
Method Details
-
inc
public void inc(double amount) Description copied from interface:GaugeDataPointAddamount.- Specified by:
incin interfaceGaugeDataPoint
-
get
public double get()Description copied from interface:GaugeDataPointGet the current value.- Specified by:
getin interfaceGaugeDataPoint
-
incWithExemplar
public void incWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels) Description copied from interface:GaugeDataPointAddamount, and create a custom exemplar with the given labels.- Specified by:
incWithExemplarin interfaceGaugeDataPoint
-
set
public void set(double value) Description copied from interface:GaugeDataPointSet the gauge tovalue.- Specified by:
setin interfaceGaugeDataPoint
-
setWithExemplar
public void setWithExemplar(double value, io.prometheus.metrics.model.snapshots.Labels labels) Description copied from interface:GaugeDataPointSet the gauge tovalue, and create a custom exemplar with the given labels.- Specified by:
setWithExemplarin interfaceGaugeDataPoint
-
collect
public io.prometheus.metrics.model.snapshots.GaugeSnapshot collect()- Specified by:
collectin interfaceio.prometheus.metrics.model.registry.Collector- Overrides:
collectin classStatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
-
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) 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<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
-
getMetricType
Deprecated.UseMetricWithFixedMetadata.getMetricFamilyDescriptor()instead.- Specified by:
getMetricTypein interfaceio.prometheus.metrics.model.registry.Collector
-
newDataPoint
protected io.prometheus.metrics.core.metrics.Gauge.DataPoint newDataPoint()- Specified by:
newDataPointin classStatefulMetric<GaugeDataPoint,io.prometheus.metrics.core.metrics.Gauge.DataPoint>
-
builder
-
builder
-
MetricWithFixedMetadata.getMetricFamilyDescriptor()instead.