@ThreadSafe public interface DoubleSumObserver extends AsynchronousInstrument<AsynchronousInstrument.DoubleResult>
SumObserver
is the asynchronous instrument corresponding to Counter, used to capture a
monotonic sum with Observe(sum).
"Sum" appears in the name to remind that it is used to capture sums directly. Use a SumObserver to capture any value that starts at zero and rises throughout the process lifetime and never falls.
A SumObserver
is a good choice in situations where a measurement is expensive to
compute, such that it would be wasteful to compute on every request.
Example:
class YourClass {
private static final Meter meter = OpenTelemetry.getMeterProvider().get("my_library_name");
private static final DoubleSumObserver cpuObserver =
meter.
.doubleSumObserverBuilder("cpu_time")
.setDescription("System CPU usage")
.setUnit("ms")
.build();
void init() {
cpuObserver.setCallback(
new DoubleSumObserver.Callback<DoubleResult>() {
{@literal @}Override
public void update(DoubleResult result) {
// Get system cpu usage
result.observe(cpuIdle, "state", "idle");
result.observe(cpuUser, "state", "user");
}
});
}
}
Modifier and Type | Interface and Description |
---|---|
static interface |
DoubleSumObserver.Builder
Builder class for
DoubleSumObserver . |
AsynchronousInstrument.Callback<R extends AsynchronousInstrument.Result>, AsynchronousInstrument.DoubleResult, AsynchronousInstrument.LongResult, AsynchronousInstrument.Result
Modifier and Type | Method and Description |
---|---|
void |
setCallback(AsynchronousInstrument.Callback<AsynchronousInstrument.DoubleResult> callback)
Sets a callback that gets executed every collection interval.
|
void setCallback(AsynchronousInstrument.Callback<AsynchronousInstrument.DoubleResult> callback)
AsynchronousInstrument
Evaluation is deferred until needed, if this AsynchronousInstrument
metric is not
exported then it will never be called.
setCallback
in interface AsynchronousInstrument<AsynchronousInstrument.DoubleResult>
callback
- the callback to be executed before export.