Package io.opencensus.metrics
Class DerivedDoubleGauge
- java.lang.Object
-
- io.opencensus.metrics.DerivedDoubleGauge
-
- Direct Known Subclasses:
DerivedDoubleGauge.NoopDerivedDoubleGauge
,DerivedDoubleGaugeImpl
@ThreadSafe public abstract class DerivedDoubleGauge extends java.lang.Object
Derived Double Gauge metric, to report instantaneous measurement of a double value. Gauges can go both up and down. The gauges values can be negative.Example: Create a Gauge 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")); DerivedDoubleGauge gauge = metricRegistry.addDerivedDoubleGauge( "queue_size", "Pending jobs in a queue", "1", labelKeys); QueueManager queueManager = new QueueManager(); gauge.createTimeSeries(labelValues, queueManager, new ToDoubleFunction<QueueManager>() { {@literal @}Override public double applyAsDouble(QueueManager queue) { return queue.size(); } }); void doWork() { // Your code here. } }
- Since:
- 0.17
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DerivedDoubleGauge.NoopDerivedDoubleGauge
No-op implementations of DerivedDoubleGauge class.
-
Constructor Summary
Constructors Constructor Description DerivedDoubleGauge()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
clear()
Removes allTimeSeries
from the gauge metric.abstract <T> void
createTimeSeries(java.util.List<LabelValue> labelValues, T obj, ToDoubleFunction<T> function)
Creates aTimeSeries
.(package private) static DerivedDoubleGauge
newNoopDerivedDoubleGauge(java.lang.String name, java.lang.String description, java.lang.String unit, java.util.List<LabelKey> labelKeys)
Returns the no-op implementation of theDerivedDoubleGauge
.abstract void
removeTimeSeries(java.util.List<LabelValue> labelValues)
Removes theTimeSeries
from the gauge 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 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:
java.lang.NullPointerException
- iflabelValues
is null OR any element oflabelValues
is null ORfunction
is null.java.lang.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.17
-
removeTimeSeries
public abstract void removeTimeSeries(java.util.List<LabelValue> labelValues)
Removes theTimeSeries
from the gauge metric, if it is present.- Parameters:
labelValues
- the list of label values.- Throws:
java.lang.NullPointerException
- iflabelValues
is null.- Since:
- 0.17
-
clear
public abstract void clear()
Removes allTimeSeries
from the gauge metric.- Since:
- 0.17
-
newNoopDerivedDoubleGauge
static DerivedDoubleGauge newNoopDerivedDoubleGauge(java.lang.String name, java.lang.String description, java.lang.String unit, java.util.List<LabelKey> labelKeys)
Returns the no-op implementation of theDerivedDoubleGauge
.- Returns:
- the no-op implementation of the
DerivedDoubleGauge
. - Since:
- 0.17
-
-