@ThreadSafe public interface LongUpDownSumObserver extends AsynchronousInstrument<LongUpDownSumObserver.ResultLongUpDownSumObserver>
"Sum" appears in the name to remind that it is used to capture sums directly. Use a UpDownSumObserver to capture any value that starts at zero and rises or falls throughout the process lifetime.
A UpDownSumObserver 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.getMeterRegistry().get("my_library_name");
private static final LongUpDownSumObserver memoryObserver =
meter.
.longUpDownSumObserverBuilder("memory_usage")
.setDescription("System memory usage")
.setUnit("by")
.build();
void init() {
memoryObserver.setCallback(
new LongUpDownSumObserver.Callback<LongObserver.ResultLongObserver>() {
{@literal @}Override
public void update(ResultLongUpDownSumObserver result) {
// Get system memory usage
result.observe(memoryUsed, "state", "used");
result.observe(memoryFree, "state", "free");
}
});
}
}
| Modifier and Type | Interface and Description |
|---|---|
static interface |
LongUpDownSumObserver.Builder
Builder class for
LongUpDownSumObserver. |
static interface |
LongUpDownSumObserver.ResultLongUpDownSumObserver
The result for the
Callback. |
AsynchronousInstrument.Callback<R>| Modifier and Type | Method and Description |
|---|---|
void |
setCallback(AsynchronousInstrument.Callback<LongUpDownSumObserver.ResultLongUpDownSumObserver> callback)
Sets a callback that gets executed every collection interval.
|
void setCallback(AsynchronousInstrument.Callback<LongUpDownSumObserver.ResultLongUpDownSumObserver> callback)
AsynchronousInstrumentEvaluation is deferred until needed, if this AsynchronousInstrument metric is not
exported then it will never be called.
setCallback in interface AsynchronousInstrument<LongUpDownSumObserver.ResultLongUpDownSumObserver>callback - the callback to be executed before export.