Package io.opencensus.metrics
Class LongGauge
java.lang.Object
io.opencensus.metrics.LongGauge
- Direct Known Subclasses:
LongGauge.NoopLongGauge
,LongGaugeImpl
Long Gauge metric, to report instantaneous measurement of an int64 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"));
LongGauge gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
// It is recommended to keep a reference of a point for manual operations.
LongPoint 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"));
LongGauge gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
// It is recommended to keep a reference of a point for manual operations.
LongPoint inboundPoint = gauge.getOrCreateTimeSeries(labelValues);
void doSomeWork() {
// Your code here.
inboundPoint.set(15);
}
}
- Since:
- 0.17
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The value of a single point in the Gauge.TimeSeries.private static final class
No-op implementations of LongGauge class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
clear()
Removes allTimeSeries
from the gauge metric.abstract LongGauge.LongPoint
Returns aLongPoint
for a gauge with all labels not set, or default labels.abstract LongGauge.LongPoint
getOrCreateTimeSeries
(List<LabelValue> labelValues) Creates aTimeSeries
and returns aLongPoint
if the specifiedlabelValues
is not already associated with this gauge, else returns an existingLongPoint
.(package private) static LongGauge
Returns the no-op implementation of theLongGauge
.abstract void
removeTimeSeries
(List<LabelValue> labelValues) Removes theTimeSeries
from the gauge metric, if it is present.
-
Constructor Details
-
LongGauge
public LongGauge()
-
-
Method Details
-
getOrCreateTimeSeries
Creates aTimeSeries
and returns aLongPoint
if the specifiedlabelValues
is not already associated with this gauge, else returns an existingLongPoint
.It is recommended to keep a reference to the LongPoint 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.addLongGauge(java.lang.String, java.lang.String, java.lang.String, java.util.List<io.opencensus.metrics.LabelKey>)
.- Returns:
- a
LongPoint
the value of single gauge. - Throws:
NullPointerException
- iflabelValues
is null OR any element oflabelValues
is null.IllegalArgumentException
- if number oflabelValues
s are not equal to the label keys passed toMetricRegistry.addLongGauge(java.lang.String, java.lang.String, java.lang.String, java.util.List<io.opencensus.metrics.LabelKey>)
.- Since:
- 0.17
-
getDefaultTimeSeries
Returns aLongPoint
for a gauge with all labels not set, or default labels.- Returns:
- a
LongPoint
for a gauge with all labels not set, or default labels. - Since:
- 0.17
-
removeTimeSeries
Removes theTimeSeries
from the gauge metric, if it is present. i.e. references to previousLongPoint
objects are invalid (not part of the metric).- Parameters:
labelValues
- the list of label values.- Throws:
NullPointerException
- iflabelValues
is null.- Since:
- 0.17
-
clear
public abstract void clear()Removes allTimeSeries
from the gauge metric. i.e. references to all previousLongPoint
objects are invalid (not part of the metric).- Since:
- 0.17
-
newNoopLongGauge
static LongGauge newNoopLongGauge(String name, String description, String unit, List<LabelKey> labelKeys) Returns the no-op implementation of theLongGauge
.- Returns:
- the no-op implementation of the
LongGauge
. - Since:
- 0.17
-