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
  • Field Details

    • clock

      protected final Clock clock
    • histogram

      protected final Histogram histogram
  • Constructor Details

    • AbstractTimer

      @Deprecated protected AbstractTimer(Meter.Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, 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, 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.
    • AbstractTimer

      protected AbstractTimer(Meter.Id id, Clock clock, PauseDetector pauseDetector, TimeUnit baseTimeUnit, Histogram histogram)
      Creates a new timer.
      Parameters:
      id - The timer's name and tags.
      clock - The clock used to measure latency.
      pauseDetector - Compensation for coordinated omission.
      baseTimeUnit - The time scale of this timer.
      histogram - Histogram.
      Since:
      1.11.0
  • Method Details

    • defaultHistogram

      protected static Histogram defaultHistogram(Clock clock, DistributionStatisticConfig distributionStatisticConfig, boolean supportsAggregablePercentiles)
      Creates a default histogram.
      Parameters:
      clock - The clock used to measure latency.
      distributionStatisticConfig - Configuration determining which distribution statistics are sent.
      supportsAggregablePercentiles - Indicates whether the registry supports percentile approximations from histograms.
      Returns:
      a default histogram
      Since:
      1.11.0
    • recordCallable

      public <T> T recordCallable(Callable<T> f) throws Exception
      Description copied from interface: Timer
      Executes the callable f and records the time taken.
      Specified by:
      recordCallable in interface Timer
      Type Parameters:
      T - The return type of the Callable.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
      Throws:
      Exception - Any exception bubbling up from the callable.
    • record

      public <T> T record(Supplier<T> f)
      Description copied from interface: Timer
      Executes the Supplier f and records the time taken.
      Specified by:
      record in interface Timer
      Type Parameters:
      T - The return type of the Supplier.
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
    • record

      public boolean record(BooleanSupplier f)
      Description copied from interface: Timer
      Executes the Supplier f and records the time taken.
      Specified by:
      record in interface Timer
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
    • record

      public int record(IntSupplier f)
      Description copied from interface: Timer
      Executes the Supplier f and records the time taken.
      Specified by:
      record in interface Timer
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
    • record

      public long record(LongSupplier f)
      Description copied from interface: Timer
      Executes the Supplier f and records the time taken.
      Specified by:
      record in interface Timer
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
    • record

      public double record(DoubleSupplier f)
      Description copied from interface: Timer
      Executes the Supplier f and records the time taken.
      Specified by:
      record in interface Timer
      Parameters:
      f - Function to execute and measure the execution time.
      Returns:
      The return value of f.
    • record

      public void record(Runnable f)
      Description copied from interface: Timer
      Executes the runnable f and records the time taken.
      Specified by:
      record in interface Timer
      Parameters:
      f - Function to execute and measure the execution time.
    • record

      public final void record(long amount, TimeUnit unit)
      Description copied from interface: Timer
      Updates the statistics kept by the timer with the specified amount.
      Specified by:
      record in interface Timer
      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.
    • recordNonNegative

      protected abstract void recordNonNegative(long amount, TimeUnit unit)
    • takeSnapshot

      public HistogramSnapshot takeSnapshot()
      Description copied from interface: HistogramSupport
      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.
      Specified by:
      takeSnapshot in interface HistogramSupport
      Returns:
      A snapshot of all distribution statistics at a point in time.
    • baseTimeUnit

      public TimeUnit baseTimeUnit()
      Specified by:
      baseTimeUnit in interface Timer
      Returns:
      The base time unit of the timer to which all published metrics will be scaled
    • close

      public void close()
      Specified by:
      close in interface Meter