@ThreadSafe public abstract class DoubleGauge extends Object
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);
}
}
Modifier and Type | Class and Description |
---|---|
static class |
DoubleGauge.DoublePoint
The value of a single point in the Gauge.TimeSeries.
|
Constructor and Description |
---|
DoubleGauge() |
Modifier and Type | Method and Description |
---|---|
abstract void |
clear()
Removes all
TimeSeries from the gauge metric. |
abstract DoubleGauge.DoublePoint |
getDefaultTimeSeries()
Returns a
DoublePoint for a gauge with all labels not set, or default labels. |
abstract DoubleGauge.DoublePoint |
getOrCreateTimeSeries(List<LabelValue> labelValues)
Creates a
TimeSeries and returns a DoublePoint if the specified labelValues is not already associated with this gauge, else returns an existing DoublePoint . |
abstract void |
removeTimeSeries(List<LabelValue> labelValues)
Removes the
TimeSeries from the gauge metric, if it is present. |
public abstract DoubleGauge.DoublePoint getOrCreateTimeSeries(List<LabelValue> labelValues)
TimeSeries
and returns a DoublePoint
if the specified labelValues
is not already associated with this gauge, else returns an existing DoublePoint
.
It is recommended to keep a reference to the DoublePoint instead of always calling this method for manual operations.
labelValues
- the list of label values. The number of label values must be the same to
that of the label keys passed to MetricRegistry.addDoubleGauge(java.lang.String, java.lang.String, java.lang.String, java.util.List<io.opencensus.metrics.LabelKey>)
.DoublePoint
the value of single gauge.NullPointerException
- if labelValues
is null OR any element of labelValues
is null.IllegalArgumentException
- if number of labelValues
s are not equal to the label
keys.public abstract DoubleGauge.DoublePoint getDefaultTimeSeries()
DoublePoint
for a gauge with all labels not set, or default labels.DoublePoint
for a gauge with all labels not set, or default labels.public abstract void removeTimeSeries(List<LabelValue> labelValues)
TimeSeries
from the gauge metric, if it is present. i.e. references to
previous DoublePoint
objects are invalid (not part of the metric).labelValues
- the list of label values.NullPointerException
- if labelValues
is null or any element of labelValues
is null.public abstract void clear()
TimeSeries
from the gauge metric. i.e. references to all previous DoublePoint
objects are invalid (not part of the metric).