Package io.micrometer.core.instrument
Interface Timer
- All Superinterfaces:
HistogramSupport,Meter
- All Known Implementing Classes:
AbstractTimer,CumulativeTimer,DropwizardTimer,NoopTimer,StepTimer
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 ClassesModifier and TypeInterfaceDescriptionstatic classFluent builder for timers.static classstatic classMaintains 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 TypeMethodDescriptionstatic Timer.BuilderCreate a timer builder from aTimedannotation.static Timer.Builderlongcount()default doublehistogramCountAtValue(long valueNanos)Deprecated.doubledefault doubledefault Iterable<Measurement>measure()Get a set of measurements.default doublepercentile(double percentile, TimeUnit unit)Deprecated.UseHistogramSupport.takeSnapshot()to retrieve bucket counts.voidUpdates the statistics kept by the timer with the specified amount.voidExecutes the runnablefand records the time taken.default voidUpdates the statistics kept by the timer with the specified amount.<T> TExecutes the Supplierfand records the time taken.<T> TrecordCallable(Callable<T> f)Executes the callablefand records the time taken.static Timer.ResourceSampleresource(MeterRegistry registry, String name)static Timer.Samplestart()Start a timing sample using theSystem clock.static Timer.SampleStart a timing sample.static Timer.Samplestart(MeterRegistry registry)Start a timing sample.doubledefault RunnableWrap aRunnableso that it is timed when invoked.default <T> Callable<T>Wrap aCallableso that it is timed when invoked.default <T> Supplier<T>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
-
resource
@Incubating(since="1.6.0") static Timer.ResourceSample resource(MeterRegistry registry, String name)- Parameters:
registry- A meter registry against which the timer will be registered.name- The name of the timer.- Returns:
- A timing builder that automatically records a timing on close.
- Since:
- 1.6.0
-
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
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
Updates the statistics kept by the timer with the specified amount.- Parameters:
duration- Duration of a single event being measured by this timer.
-
record
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
Executes the callablefand records the time taken. -
record
Executes the runnablefand records the time taken.- Parameters:
f- Function to execute and measure the execution time.
-
wrap
Wrap aRunnableso that it is timed when invoked.- Parameters:
f- The Runnable to time when it is invoked.- Returns:
- The wrapped Runnable.
-
wrap
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
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
- Parameters:
unit- The base unit of time to scale the total to.- Returns:
- The total time of recorded events.
-
mean
- Parameters:
unit- The base unit of time to scale the mean to.- Returns:
- The distribution average for all recorded events.
-
max
- 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.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.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
TimeUnit baseTimeUnit()- Returns:
- The base time unit of the timer to which all published metrics will be scaled
-
HistogramSupport.takeSnapshot()to retrieve bucket counts.