@ThreadSafe public interface DerivedDoubleCumulative extends Metric
Example: Create a Cumulative with an object and a callback function.
class YourClass {
private static final Meter meter = Metrics.getMeter();
private static final MetricRegistry metricRegistry = meter.metricRegistryBuilder().build();
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.
}
}
| Modifier and Type | Interface and Description |
|---|---|
static interface |
DerivedDoubleCumulative.Builder
Builder class for
DerivedDoubleCumulative. |
| Modifier and Type | Method and Description |
|---|---|
<T> void |
createTimeSeries(List<LabelValue> labelValues,
T obj,
ToDoubleFunction<T> function)
Creates a
TimeSeries. |
clear, removeTimeSeries<T> void createTimeSeries(List<LabelValue> labelValues, T obj, ToDoubleFunction<T> function)
TimeSeries. 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 a WeakReference to the object and it is the
user's responsibility to manage the lifetime of the object.T - the type of the object upon which the function derives a measurement.labelValues - the list of label values.obj - the state object from which the function derives a measurement.function - the function to be called.NullPointerException - if labelValues is null OR any element of labelValues is null OR function is null.IllegalArgumentException - if different time series with the same labels already exists
OR if number of labelValuess are not equal to the label keys.