Package io.opencensus.metrics
Class DerivedLongCumulative
java.lang.Object
io.opencensus.metrics.DerivedLongCumulative
- Direct Known Subclasses:
DerivedLongCumulative.NoopDerivedLongCumulative
,DerivedLongCumulativeImpl
Derived Long Cumulative metric, to report cumulative 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: 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"));
DerivedLongCumulative cumulative = metricRegistry.addDerivedLongCumulative(
"processed_jobs", "Total processed jobs in a queue", "1", labelKeys);
QueueManager queueManager = new QueueManager();
cumulative.createTimeSeries(labelValues, queueManager,
new ToLongFunction<QueueManager>() {
{@literal @}Override
public long applyAsLong(QueueManager queue) {
return queue.size();
}
});
void doWork() {
// Your code here.
}
}
- Since:
- 0.21
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
No-op implementations of DerivedLongCumulative class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
clear()
Removes allTimeSeries
from the cumulative metric.abstract <T> void
createTimeSeries
(List<LabelValue> labelValues, T obj, ToLongFunction<T> function) Creates aTimeSeries
.(package private) static DerivedLongCumulative
newNoopDerivedLongCumulative
(String name, String description, String unit, List<LabelKey> labelKeys) Returns the no-op implementation of theDerivedLongCumulative
.abstract void
removeTimeSeries
(List<LabelValue> labelValues) Removes theTimeSeries
from the cumulative metric, if it is present.
-
Constructor Details
-
DerivedLongCumulative
public DerivedLongCumulative()
-
-
Method Details
-
createTimeSeries
public abstract <T> void createTimeSeries(List<LabelValue> labelValues, T obj, ToLongFunction<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 aWeakReference
to 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:
NullPointerException
- iflabelValues
is null OR any element oflabelValues
is null ORfunction
is null.IllegalArgumentException
- if different time series with the same labels already exists OR if number oflabelValues
s are not equal to the label keys.- Since:
- 0.21
-
removeTimeSeries
Removes theTimeSeries
from the cumulative metric, if it is present.- Parameters:
labelValues
- the list of label values.- Throws:
NullPointerException
- iflabelValues
is null.- Since:
- 0.21
-
clear
public abstract void clear()Removes allTimeSeries
from the cumulative metric.- Since:
- 0.21
-
newNoopDerivedLongCumulative
static DerivedLongCumulative newNoopDerivedLongCumulative(String name, String description, String unit, List<LabelKey> labelKeys) Returns the no-op implementation of theDerivedLongCumulative
.- Returns:
- the no-op implementation of the
DerivedLongCumulative
. - Since:
- 0.21
-