Class LongCumulative
java.lang.Object
io.opencensus.metrics.LongCumulative
- Direct Known Subclasses:
LongCumulative.NoopLongCumulative, LongCumulativeImpl
Long Cumulative metric, to report instantaneous measurement of an int64 value. Cumulative values
can go up or stay the same, but can never go down. Cumulative values cannot be negative.
Example 1: Create a Cumulative with default labels.
class YourClass {
private static final MetricRegistry metricRegistry = Metrics.getMetricRegistry();
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc"));
LongCumulative cumulative = metricRegistry.addLongCumulative(
"processed_jobs", "Processed jobs", "1", labelKeys);
// It is recommended to keep a reference of a point for manual operations.
LongPoint defaultPoint = cumulative.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"));
LongCumulative cumulative = metricRegistry.addLongCumulative(
"processed_jobs", "Processed jobs", "1", labelKeys);
// It is recommended to keep a reference of a point for manual operations.
LongPoint inboundPoint = cumulative.getOrCreateTimeSeries(labelValues);
void doSomeWork() {
// Your code here.
inboundPoint.set(15);
}
}
- Since:
- 0.21
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe value of a single point in the Cumulative.TimeSeries.private static final classNo-op implementations of LongCumulative class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclear()Removes allTimeSeriesfrom the cumulative metric.abstract LongCumulative.LongPointReturns aLongPointfor a cumulative with all labels not set, or default labels.abstract LongCumulative.LongPointgetOrCreateTimeSeries(List<LabelValue> labelValues) Creates aTimeSeriesand returns aLongPointif the specifiedlabelValuesis not already associated with this cumulative, else returns an existingLongPoint.(package private) static LongCumulativeReturns the no-op implementation of theLongCumulative.abstract voidremoveTimeSeries(List<LabelValue> labelValues) Removes theTimeSeriesfrom the cumulative metric, if it is present.
-
Constructor Details
-
LongCumulative
public LongCumulative()
-
-
Method Details
-
getOrCreateTimeSeries
Creates aTimeSeriesand returns aLongPointif the specifiedlabelValuesis not already associated with this cumulative, 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.addLongCumulative(String, MetricOptions).- Returns:
- a
LongPointthe value of single cumulative. - Throws:
NullPointerException- iflabelValuesis null OR any element oflabelValuesis null.IllegalArgumentException- if number oflabelValuess are not equal to the label keys passed toMetricRegistry.addLongCumulative(String, MetricOptions).- Since:
- 0.21
-
getDefaultTimeSeries
Returns aLongPointfor a cumulative with all labels not set, or default labels.- Returns:
- a
LongPointfor a cumulative with all labels not set, or default labels. - Since:
- 0.21
-
removeTimeSeries
Removes theTimeSeriesfrom the cumulative metric, if it is present. i.e. references to previousLongPointobjects are invalid (not part of the metric).- Parameters:
labelValues- the list of label values.- Throws:
NullPointerException- iflabelValuesis null.- Since:
- 0.21
-
clear
public abstract void clear()Removes allTimeSeriesfrom the cumulative metric. i.e. references to all previousLongPointobjects are invalid (not part of the metric).- Since:
- 0.21
-
newNoopLongCumulative
-