Package io.micrometer.core.instrument
Class AbstractTimer
java.lang.Object
io.micrometer.core.instrument.AbstractMeter
io.micrometer.core.instrument.AbstractTimer
- All Implemented Interfaces:
HistogramSupport,Meter,Timer
- Direct Known Subclasses:
CumulativeTimer,DropwizardTimer,StepTimer
public abstract class AbstractTimer extends AbstractMeter implements Timer
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micrometer.core.instrument.Meter
Meter.Builder, Meter.Id, Meter.TypeNested classes/interfaces inherited from interface io.micrometer.core.instrument.Timer
Timer.Builder, Timer.Sample -
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTimer(Meter.Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, java.util.concurrent.TimeUnit baseTimeUnit)Deprecated.Timer implementations should now declare at construction time whether they support aggregable percentiles or not.protectedAbstractTimer(Meter.Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, java.util.concurrent.TimeUnit baseTimeUnit, boolean supportsAggregablePercentiles)Creates a new timer. -
Method Summary
Modifier and Type Method Description java.util.concurrent.TimeUnitbaseTimeUnit()voidclose()booleanequals(java.lang.Object o)inthashCode()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.<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.protected abstract voidrecordNonNegative(long amount, java.util.concurrent.TimeUnit unit)HistogramSnapshottakeSnapshot()Summary statistics should be published off of a single snapshot instance so that, for example, there isn't disagreement between the distribution's bucket counts because more events continue to stream in.Methods inherited from class io.micrometer.core.instrument.AbstractMeter
getIdMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micrometer.core.instrument.distribution.HistogramSupport
takeSnapshot
-
Field Details
-
clock
-
histogram
-
-
Constructor Details
-
AbstractTimer
@Deprecated protected AbstractTimer(Meter.Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, java.util.concurrent.TimeUnit baseTimeUnit)Deprecated.Timer implementations should now declare at construction time whether they support aggregable percentiles or not. By declaring it up front, Micrometer can memory optimize the histogram structure used to store distribution statistics.Creates a new timer.- Parameters:
id- The timer's name and tags.clock- The clock used to measure latency.distributionStatisticConfig- Configuration determining which distribution statistics are sent.pauseDetector- Compensation for coordinated omission.baseTimeUnit- The time scale of this timer.
-
AbstractTimer
protected AbstractTimer(Meter.Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, java.util.concurrent.TimeUnit baseTimeUnit, boolean supportsAggregablePercentiles)Creates a new timer.- Parameters:
id- The timer's name and tags.clock- The clock used to measure latency.distributionStatisticConfig- Configuration determining which distribution statistics are sent.pauseDetector- Compensation for coordinated omission.baseTimeUnit- The time scale of this timer.supportsAggregablePercentiles- Indicates whether the registry supports percentile approximations from histograms.
-
-
Method Details
-
recordCallable
public <T> T recordCallable(java.util.concurrent.Callable<T> f) throws java.lang.ExceptionDescription copied from interface:TimerExecutes the callablefand records the time taken.- Specified by:
recordCallablein interfaceTimer- 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
public <T> T record(java.util.function.Supplier<T> f)Description copied from interface:TimerExecutes the Supplierfand records the time taken. -
record
public void record(java.lang.Runnable f)Description copied from interface:TimerExecutes the runnablefand records the time taken. -
record
public final void record(long amount, java.util.concurrent.TimeUnit unit)Description copied from interface:TimerUpdates the statistics kept by the timer with the specified amount. -
recordNonNegative
protected abstract void recordNonNegative(long amount, java.util.concurrent.TimeUnit unit) -
takeSnapshot
Description copied from interface:HistogramSupportSummary statistics should be published off of a single snapshot instance so that, for example, there isn't disagreement between the distribution's bucket counts because more events continue to stream in.- Specified by:
takeSnapshotin interfaceHistogramSupport- Returns:
- A snapshot of all distribution statistics at a point in time.
-
baseTimeUnit
public java.util.concurrent.TimeUnit baseTimeUnit()- Specified by:
baseTimeUnitin interfaceTimer- Returns:
- The base time unit of the timer to which all published metrics will be scaled
-
equals
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
close
public void close()
-