Package io.opencensus.metrics
Class DerivedDoubleCumulative
- java.lang.Object
-
- io.opencensus.metrics.DerivedDoubleCumulative
-
- Direct Known Subclasses:
DerivedDoubleCumulative.NoopDerivedDoubleCumulative,DerivedDoubleCumulativeImpl
@ThreadSafe public abstract class DerivedDoubleCumulative extends java.lang.ObjectDerived Double Cumulative metric, to report cumulative 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: Create a Cumulative with an object and a callback function.
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")); DerivedDoubleCumulative cumulative = metricRegistry.addDerivedDoubleCumulative( "processed_jobs", "Processed jobs in a queue", "1", labelKeys); QueueManager queueManager = new QueueManager(); cumulative.createTimeSeries(labelValues, queueManager, new ToDoubleFunction<QueueManager>() { {@literal @}Override public double applyAsDouble(QueueManager queue) { return queue.size(); } }); void doWork() { // Your code here. } }- Since:
- 0.21
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDerivedDoubleCumulative.NoopDerivedDoubleCumulativeNo-op implementations of DerivedDoubleCumulative class.
-
Constructor Summary
Constructors Constructor Description DerivedDoubleCumulative()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclear()Removes allTimeSeriesfrom the cumulative metric.abstract <T> voidcreateTimeSeries(java.util.List<LabelValue> labelValues, T obj, ToDoubleFunction<T> function)Creates aTimeSeries.(package private) static DerivedDoubleCumulativenewNoopDerivedDoubleCumulative(java.lang.String name, java.lang.String description, java.lang.String unit, java.util.List<LabelKey> labelKeys)Returns the no-op implementation of theDerivedDoubleCumulative.abstract voidremoveTimeSeries(java.util.List<LabelValue> labelValues)Removes theTimeSeriesfrom the cumulative metric, if it is present.
-
-
-
Method Detail
-
createTimeSeries
public abstract <T> void createTimeSeries(java.util.List<LabelValue> labelValues, T obj, ToDoubleFunction<T> function)
Creates aTimeSeries. The value of a single point in the TimeSeries is observed from a callback function. This function is invoked whenever metrics are collected, meaning the reported value is up-to-date. It keeps aWeakReferenceto the object and it is the user's responsibility to manage the lifetime of the object.- Type Parameters:
T- the type of the object upon which the function derives a measurement.- Parameters:
labelValues- the list of label values.obj- the state object from which the function derives a measurement.function- the function to be called.- Throws:
java.lang.NullPointerException- iflabelValuesis null OR any element oflabelValuesis null ORfunctionis null.java.lang.IllegalArgumentException- if different time series with the same labels already exists OR if number oflabelValuess are not equal to the label keys.- Since:
- 0.21
-
removeTimeSeries
public abstract void removeTimeSeries(java.util.List<LabelValue> labelValues)
Removes theTimeSeriesfrom the cumulative metric, if it is present.- Parameters:
labelValues- the list of label values.- Throws:
java.lang.NullPointerException- iflabelValuesis null.- Since:
- 0.21
-
clear
public abstract void clear()
Removes allTimeSeriesfrom the cumulative metric.- Since:
- 0.21
-
newNoopDerivedDoubleCumulative
static DerivedDoubleCumulative newNoopDerivedDoubleCumulative(java.lang.String name, java.lang.String description, java.lang.String unit, java.util.List<LabelKey> labelKeys)
Returns the no-op implementation of theDerivedDoubleCumulative.- Returns:
- the no-op implementation of the
DerivedDoubleCumulative. - Since:
- 0.21
-
-