Class Gauge
java.lang.Object
io.prometheus.metrics.core.metrics.Metric
io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
io.prometheus.metrics.core.metrics.StatefulMetric<GaugeDataPoint,Gauge.DataPoint>
io.prometheus.metrics.core.metrics.Gauge
- All Implemented Interfaces:
DataPoint,GaugeDataPoint,TimerApi,Collector
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 ClassesModifier and TypeClassDescriptionstatic class(package private) static class -
Field Summary
FieldsFields inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
labelNamesFields inherited from class io.prometheus.metrics.core.metrics.Metric
constLabels -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateGauge(Gauge.Builder builder, PrometheusProperties prometheusProperties) -
Method Summary
Modifier and TypeMethodDescriptionstatic Gauge.Builderbuilder()static Gauge.Builderbuilder(PrometheusProperties config) collect()Called when the Prometheus server scrapes metrics.protected GaugeSnapshotcollect(List<Labels> labels, List<Gauge.DataPoint> metricData) labels and metricData have the same size.doubleget()Get the current value.Returns the metric type for registration-time validation.voidinc(double amount) Addamount.voidincWithExemplar(double amount, Labels labels) Addamount, and create a custom exemplar with the given labels.protected Gauge.DataPointvoidset(double value) Set the gauge tovalue.voidsetWithExemplar(double value, 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, 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
-
Field Details
-
exemplarSamplerConfig
-
-
Constructor Details
-
Gauge
-
-
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
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
Description copied from interface:GaugeDataPointSet the gauge tovalue, and create a custom exemplar with the given labels.- Specified by:
setWithExemplarin interfaceGaugeDataPoint
-
collect
Description copied from interface:CollectorCalled when the Prometheus server scrapes metrics.- Specified by:
collectin interfaceCollector- Overrides:
collectin classStatefulMetric<GaugeDataPoint,Gauge.DataPoint>
-
collect
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,Gauge.DataPoint>
-
getMetricType
Description copied from interface:CollectorReturns the metric type for registration-time validation.This is used to prevent different metric types (e.g., Counter and Gauge) from sharing the same name. Returning
nullmeans type validation is skipped for this collector.Validation is performed only at registration time. If this method returns
null, no type validation is performed for this collector, and duplicate or conflicting metrics may result in invalid exposition output.- Specified by:
getMetricTypein interfaceCollector- Returns:
- the metric type, or
nullto skip validation
-
newDataPoint
- Specified by:
newDataPointin classStatefulMetric<GaugeDataPoint,Gauge.DataPoint>
-
builder
-
builder
-