- 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 voidObserve the duration of thefunccall.default <T> TLiketime(Runnable), but returns the return value offunc.default <T> TtimeChecked(Callable<T> func)
-
Method Details
-
startTimer
Timer 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 thefunccall. 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
-