Interface TimerApi
- All Known Subinterfaces:
DistributionDataPoint
,GaugeDataPoint
- All Known Implementing Classes:
Gauge
,Histogram
,Histogram.DataPoint
,Summary
,Summary.DataPoint
public interface TimerApi
Convenience API for timing durations.
Durations are recorded in seconds. The Prometheus instrumentation guidelines say: "Metrics must use base units (e.g. seconds, bytes) and leave converting them to something more readable to graphing tools".
-
Method Summary
Modifier and TypeMethodDescriptionStart aTimer
.default void
Observe the duration of thefunc
call.default <T> T
Liketime(Runnable)
, but returns the return value offunc
.default <T> T
timeChecked
(Callable<T> func)
-
Method Details
-
startTimer
Start aTimer
. Example:
Durations are recorded in seconds. The Prometheus instrumentation guidelines say: "Metrics must use base units (e.g. seconds, bytes) and leave converting them to something more readable to graphing tools".Histogram histogram = Histogram.builder() .name("http_request_duration_seconds") .help("HTTP request service time in seconds") .unit(SECONDS) .labelNames("method", "path") .register(); try (Timer timer = histogram.labelValues("GET", "/").startTimer()) { // duration of this code block will be observed. }
-
time
Observe the duration of thefunc
call. Example:Histogram histogram = Histogram.builder() .name("request_duration_seconds") .help("HTTP request service time in seconds") .unit(SECONDS) .labelNames("method", "path") .register(); histogram2.labelValues("GET", "/").time(() -> { // duration of this code block will be observed. });
Durations are recorded in seconds. The Prometheus instrumentation guidelines say: "Metrics must use base units (e.g. seconds, bytes) and leave converting them to something more readable to graphing tools".
-
time
Liketime(Runnable)
, but returns the return value offunc
. -
timeChecked
- Throws:
Exception
-