Class DoubleGauge
java.lang.Object
io.opencensus.metrics.DoubleGauge
- Direct Known Subclasses:
DoubleGauge.NoopDoubleGauge, DoubleGaugeImpl
Double Gauge metric, to report instantaneous measurement of a double value. Gauges can go both up
and down. The gauges values can be negative.
Example 1: Create a Gauge with default labels.
class YourClass {
private static final MetricRegistry metricRegistry = Metrics.getMetricRegistry();
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
DoubleGauge gauge = metricRegistry.addDoubleGauge("queue_size",
"Pending jobs", "1", labelKeys);
// It is recommended to keep a reference of a point for manual operations.
DoublePoint defaultPoint = gauge.getDefaultTimeSeries();
void doWork() {
// Your code here.
defaultPoint.add(10);
}
}
Example 2: You can also use labels(keys and values) to track different types of metric.
class YourClass {
private static final MetricRegistry metricRegistry = Metrics.getMetricRegistry();
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
List<LabelValue> labelValues = Arrays.asList(LabelValue.create("Inbound"));
DoubleGauge gauge = metricRegistry.addDoubleGauge("queue_size",
"Pending jobs", "1", labelKeys);
// It is recommended to keep a reference of a point for manual operations.
DoublePoint inboundPoint = gauge.getOrCreateTimeSeries(labelValues);
void doSomeWork() {
// Your code here.
inboundPoint.set(15);
}
}
- Since:
- 0.17
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe value of a single point in the Gauge.TimeSeries.private static final classNo-op implementations of DoubleGauge class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclear()Removes allTimeSeriesfrom the gauge metric.abstract DoubleGauge.DoublePointReturns aDoublePointfor a gauge with all labels not set, or default labels.abstract DoubleGauge.DoublePointgetOrCreateTimeSeries(List<LabelValue> labelValues) Creates aTimeSeriesand returns aDoublePointif the specifiedlabelValuesis not already associated with this gauge, else returns an existingDoublePoint.(package private) static DoubleGaugeReturns the no-op implementation of theDoubleGauge.abstract voidremoveTimeSeries(List<LabelValue> labelValues) Removes theTimeSeriesfrom the gauge metric, if it is present.
-
Constructor Details
-
DoubleGauge
public DoubleGauge()
-
-
Method Details
-
getOrCreateTimeSeries
Creates aTimeSeriesand returns aDoublePointif the specifiedlabelValuesis not already associated with this gauge, else returns an existingDoublePoint.It is recommended to keep a reference to the DoublePoint instead of always calling this method for manual operations.
- Parameters:
labelValues- the list of label values. The number of label values must be the same to that of the label keys passed toMetricRegistry.addDoubleGauge(String, String, String, List).- Returns:
- a
DoublePointthe value of single gauge. - Throws:
NullPointerException- iflabelValuesis null OR any element oflabelValuesis null.IllegalArgumentException- if number oflabelValuess are not equal to the label keys.- Since:
- 0.17
-
getDefaultTimeSeries
Returns aDoublePointfor a gauge with all labels not set, or default labels.- Returns:
- a
DoublePointfor a gauge with all labels not set, or default labels. - Since:
- 0.17
-
removeTimeSeries
Removes theTimeSeriesfrom the gauge metric, if it is present. i.e. references to previousDoublePointobjects are invalid (not part of the metric).- Parameters:
labelValues- the list of label values.- Throws:
NullPointerException- iflabelValuesis null or any element oflabelValuesis null.- Since:
- 0.17
-
clear
public abstract void clear()Removes allTimeSeriesfrom the gauge metric. i.e. references to all previousDoublePointobjects are invalid (not part of the metric).- Since:
- 0.17
-
newNoopDoubleGauge
-