Package io.opencensus.metrics
Class DoubleCumulative
- java.lang.Object
-
- io.opencensus.metrics.DoubleCumulative
-
- Direct Known Subclasses:
DoubleCumulative.NoopDoubleCumulative
,DoubleCumulativeImpl
@ThreadSafe public abstract class DoubleCumulative extends java.lang.Object
Double Cumulative metric, to report instantaneous measurement of a double 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")); DoubleCumulative cumulative = metricRegistry.addDoubleCumulative("processed_jobs", "Processed jobs", "1", labelKeys); // It is recommended to keep a reference of a point for manual operations. DoublePoint 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")); DoubleCumulative cumulative = metricRegistry.addDoubleCumulative("processed_jobs", "Processed jobs", "1", labelKeys); // It is recommended to keep a reference of a point for manual operations. DoublePoint inboundPoint = cumulative.getOrCreateTimeSeries(labelValues); void doSomeWork() { // Your code here. inboundPoint.set(15); } }
- Since:
- 0.21
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DoubleCumulative.DoublePoint
The value of a single point in the Cumulative.TimeSeries.private static class
DoubleCumulative.NoopDoubleCumulative
No-op implementations of DoubleCumulative class.
-
Constructor Summary
Constructors Constructor Description DoubleCumulative()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
clear()
Removes allTimeSeries
from the cumulative metric.abstract DoubleCumulative.DoublePoint
getDefaultTimeSeries()
Returns aDoublePoint
for a cumulative with all labels not set, or default labels.abstract DoubleCumulative.DoublePoint
getOrCreateTimeSeries(java.util.List<LabelValue> labelValues)
Creates aTimeSeries
and returns aDoublePoint
if the specifiedlabelValues
is not already associated with this cumulative, else returns an existingDoublePoint
.(package private) static DoubleCumulative
newNoopDoubleCumulative(java.lang.String name, java.lang.String description, java.lang.String unit, java.util.List<LabelKey> labelKeys)
Returns the no-op implementation of theDoubleCumulative
.abstract void
removeTimeSeries(java.util.List<LabelValue> labelValues)
Removes theTimeSeries
from the cumulative metric, if it is present.
-
-
-
Method Detail
-
getOrCreateTimeSeries
public abstract DoubleCumulative.DoublePoint getOrCreateTimeSeries(java.util.List<LabelValue> labelValues)
Creates aTimeSeries
and returns aDoublePoint
if the specifiedlabelValues
is not already associated with this cumulative, 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.addDoubleCumulative(java.lang.String, io.opencensus.metrics.MetricOptions)
.- Returns:
- a
DoublePoint
the value of single cumulative. - Throws:
java.lang.NullPointerException
- iflabelValues
is null OR any element oflabelValues
is null.java.lang.IllegalArgumentException
- if number oflabelValues
s are not equal to the label keys.- Since:
- 0.21
-
getDefaultTimeSeries
public abstract DoubleCumulative.DoublePoint getDefaultTimeSeries()
Returns aDoublePoint
for a cumulative with all labels not set, or default labels.- Returns:
- a
DoublePoint
for a cumulative with all labels not set, or default labels. - Since:
- 0.21
-
removeTimeSeries
public abstract void removeTimeSeries(java.util.List<LabelValue> labelValues)
Removes theTimeSeries
from the cumulative metric, if it is present. i.e. references to previousDoublePoint
objects are invalid (not part of the metric).- Parameters:
labelValues
- the list of label values.- Throws:
java.lang.NullPointerException
- iflabelValues
is null or any element oflabelValues
is null.- Since:
- 0.21
-
clear
public abstract void clear()
Removes allTimeSeries
from the cumulative metric. i.e. references to all previousDoublePoint
objects are invalid (not part of the metric).- Since:
- 0.21
-
newNoopDoubleCumulative
static DoubleCumulative newNoopDoubleCumulative(java.lang.String name, java.lang.String description, java.lang.String unit, java.util.List<LabelKey> labelKeys)
Returns the no-op implementation of theDoubleCumulative
.- Returns:
- the no-op implementation of the
DoubleCumulative
. - Since:
- 0.21
-
-