Package io.micrometer.core.instrument
Interface Timer
- All Superinterfaces:
HistogramSupport,Meter
- All Known Implementing Classes:
AbstractTimer,CumulativeTimer,DropwizardTimer,NoopTimer,StepTimer
public interface Timer extends Meter, HistogramSupport
Timer intended to track of a large number of short running events. Example would be something like
an HTTP request. Though "short running" is a bit subjective the assumption is that it should be
under a minute.
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classTimer.BuilderFluent builder for timers.static classTimer.SampleMaintains state on the clock's start position for a latency sample.Nested classes/interfaces inherited from interface io.micrometer.core.instrument.Meter
Meter.Id, Meter.Type -
Method Summary
Modifier and Type Method Description java.util.concurrent.TimeUnitbaseTimeUnit()static Timer.Builderbuilder(Timed timed, java.lang.String defaultName)Create a timer builder from aTimedannotation.static Timer.Builderbuilder(java.lang.String name)longcount()default doublehistogramCountAtValue(long valueNanos)Deprecated.UseHistogramSupport.takeSnapshot()to retrieve bucket counts.doublemax(java.util.concurrent.TimeUnit unit)default doublemean(java.util.concurrent.TimeUnit unit)default java.lang.Iterable<Measurement>measure()Get a set of measurements.default doublepercentile(double percentile, java.util.concurrent.TimeUnit unit)Deprecated.UseHistogramSupport.takeSnapshot()to retrieve bucket counts.voidrecord(long amount, java.util.concurrent.TimeUnit unit)Updates the statistics kept by the timer with the specified amount.voidrecord(java.lang.Runnable f)Executes the runnablefand records the time taken.default voidrecord(java.time.Duration duration)Updates the statistics kept by the timer with the specified amount.<T> Trecord(java.util.function.Supplier<T> f)Executes the Supplierfand records the time taken.<T> TrecordCallable(java.util.concurrent.Callable<T> f)Executes the callablefand records the time taken.static Timer.Samplestart()Start a timing sample using theSystem clock.static Timer.Samplestart(Clock clock)Start a timing sample.static Timer.Samplestart(MeterRegistry registry)Start a timing sample.doubletotalTime(java.util.concurrent.TimeUnit unit)default java.lang.Runnablewrap(java.lang.Runnable f)Wrap aRunnableso that it is timed when invoked.default <T> java.util.concurrent.Callable<T>wrap(java.util.concurrent.Callable<T> f)Wrap aCallableso that it is timed when invoked.default <T> java.util.function.Supplier<T>wrap(java.util.function.Supplier<T> f)Wrap aSupplierso that it is timed when invoked.Methods inherited from interface io.micrometer.core.instrument.distribution.HistogramSupport
takeSnapshot, takeSnapshot
-
Method Details
-
start
Start a timing sample using theSystem clock.- Returns:
- A timing sample with start time recorded.
- Since:
- 1.1.0
-
start
Start a timing sample.- Parameters:
registry- a meter registry whose clock is to be used- Returns:
- A timing sample with start time recorded.
-
start
Start a timing sample.- Parameters:
clock- a clock to be used- Returns:
- A timing sample with start time recorded.
-
builder
-
builder
Create a timer builder from aTimedannotation.- Parameters:
timed- The annotation instance to base a new timer on.defaultName- A default name to use in the event that the value attribute is empty.- Returns:
- This builder.
-
record
void record(long amount, java.util.concurrent.TimeUnit unit)Updates the statistics kept by the timer with the specified amount.- Parameters:
amount- Duration of a single event being measured by this timer. If the amount is less than 0 the value will be dropped.unit- Time unit for the amount being recorded.
-
record
default void record(java.time.Duration duration)Updates the statistics kept by the timer with the specified amount.- Parameters:
duration- Duration of a single event being measured by this timer.
-
record
<T> T record(java.util.function.Supplier<T> f)Executes the Supplierfand records the time taken.- Type Parameters:
T- The return type of theSupplier.- Parameters:
f- Function to execute and measure the execution time.- Returns:
- The return value of
f.
-
recordCallable
<T> T recordCallable(java.util.concurrent.Callable<T> f) throws java.lang.ExceptionExecutes the callablefand records the time taken.- Type Parameters:
T- The return type of theCallable.- Parameters:
f- Function to execute and measure the execution time.- Returns:
- The return value of
f. - Throws:
java.lang.Exception- Any exception bubbling up from the callable.
-
record
void record(java.lang.Runnable f)Executes the runnablefand records the time taken.- Parameters:
f- Function to execute and measure the execution time.
-
wrap
default java.lang.Runnable wrap(java.lang.Runnable f)Wrap aRunnableso that it is timed when invoked.- Parameters:
f- The Runnable to time when it is invoked.- Returns:
- The wrapped Runnable.
-
wrap
default <T> java.util.concurrent.Callable<T> wrap(java.util.concurrent.Callable<T> f)Wrap aCallableso that it is timed when invoked.- Type Parameters:
T- The return type of the callable.- Parameters:
f- The Callable to time when it is invoked.- Returns:
- The wrapped callable.
-
wrap
default <T> java.util.function.Supplier<T> wrap(java.util.function.Supplier<T> f)Wrap aSupplierso that it is timed when invoked.- Type Parameters:
T- The return type of theSupplierresult.- Parameters:
f- TheSupplierto time when it is invoked.- Returns:
- The wrapped supplier.
- Since:
- 1.2.0
-
count
long count()- Returns:
- The number of times that stop has been called on this timer.
-
totalTime
double totalTime(java.util.concurrent.TimeUnit unit)- Parameters:
unit- The base unit of time to scale the total to.- Returns:
- The total time of recorded events.
-
mean
default double mean(java.util.concurrent.TimeUnit unit)- Parameters:
unit- The base unit of time to scale the mean to.- Returns:
- The distribution average for all recorded events.
-
max
double max(java.util.concurrent.TimeUnit unit)- Parameters:
unit- The base unit of time to scale the max to.- Returns:
- The maximum time of a single event.
-
measure
Description copied from interface:MeterGet a set of measurements. Should always return the same number of measurements and in the same order, regardless of the level of activity or the lack thereof. -
histogramCountAtValue
@Deprecated default double histogramCountAtValue(long valueNanos)Deprecated.UseHistogramSupport.takeSnapshot()to retrieve bucket counts.Provides cumulative histogram counts.- Parameters:
valueNanos- The histogram bucket to retrieve a count for.- Returns:
- The count of all events less than or equal to the bucket. If valueNanos does not match a preconfigured bucket boundary, returns NaN.
-
percentile
@Deprecated default double percentile(double percentile, java.util.concurrent.TimeUnit unit)Deprecated.UseHistogramSupport.takeSnapshot()to retrieve bucket counts.- Parameters:
percentile- A percentile in the domain [0, 1]. For example, 0.5 represents the 50th percentile of the distribution.unit- The base unit of time to scale the percentile value to.- Returns:
- The latency at a specific percentile. This value is non-aggregable across dimensions. Returns NaN if percentile is not a preconfigured percentile that Micrometer is tracking.
-
baseTimeUnit
java.util.concurrent.TimeUnit baseTimeUnit()- Returns:
- The base time unit of the timer to which all published metrics will be scaled
-