Package io.opentelemetry.api.metrics
Interface DoubleUpDownSumObserver
-
- All Superinterfaces:
AsynchronousInstrument<AsynchronousInstrument.DoubleResult>
,Instrument
@ThreadSafe public interface DoubleUpDownSumObserver extends AsynchronousInstrument<AsynchronousInstrument.DoubleResult>
UpDownSumObserver is the asynchronous instrument corresponding to UpDownCounter, used to capture a non-monotonic count with Observe(sum)."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.getMeterProvider().get("my_library_name"); private static final DoubleUpDownSumObserver memoryObserver = meter. .doubleUpDownSumObserverBuilder("memory_usage") .setDescription("System memory usage") .setUnit("by") .build(); void init() { memoryObserver.setCallback( new DoubleUpDownSumObserver.Callback<DoubleResult>() { {@literal @}Override public void update(DoubleResult result) { // Get system memory usage result.observe(memoryUsed, "state", "used"); result.observe(memoryFree, "state", "free"); } }); } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
DoubleUpDownSumObserver.Builder
Builder class forDoubleUpDownSumObserver
.-
Nested classes/interfaces inherited from interface io.opentelemetry.api.metrics.AsynchronousInstrument
AsynchronousInstrument.Callback<R extends AsynchronousInstrument.Result>, AsynchronousInstrument.DoubleResult, AsynchronousInstrument.LongResult, AsynchronousInstrument.Result
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
setCallback(AsynchronousInstrument.Callback<AsynchronousInstrument.DoubleResult> callback)
Sets a callback that gets executed every collection interval.
-
-
-
Method Detail
-
setCallback
void setCallback(AsynchronousInstrument.Callback<AsynchronousInstrument.DoubleResult> callback)
Description copied from interface:AsynchronousInstrument
Sets a callback that gets executed every collection interval.Evaluation is deferred until needed, if this
AsynchronousInstrument
metric is not exported then it will never be called.- Specified by:
setCallback
in interfaceAsynchronousInstrument<AsynchronousInstrument.DoubleResult>
- Parameters:
callback
- the callback to be executed before export.
-
-