Class ScheduledReporter

java.lang.Object
com.codahale.metrics.ScheduledReporter
All Implemented Interfaces:
Reporter, Closeable, AutoCloseable
Direct Known Subclasses:
ConsoleReporter, CsvReporter, Slf4jReporter

public abstract class ScheduledReporter extends Object implements Closeable, Reporter
The abstract base class for all scheduled reporters (i.e., reporters which process a registry's metrics periodically).
See Also:
  • Constructor Details

  • Method Details

    • start

      public void start(long period, TimeUnit unit)
      Starts the reporter polling at the given period.
      Parameters:
      period - the amount of time between polls
      unit - the unit for period
    • getScheduledFuture

      @Deprecated protected ScheduledFuture<?> getScheduledFuture(long initialDelay, long period, TimeUnit unit, Runnable runnable)
      Schedule the task, and return a future.
    • getScheduledFuture

      protected ScheduledFuture<?> getScheduledFuture(long initialDelay, long period, TimeUnit unit, Runnable runnable, ScheduledExecutorService executor)
      Schedule the task, and return a future. The current implementation uses scheduleWithFixedDelay, replacing scheduleWithFixedRate. This avoids queueing issues, but may cause some reporters to skip metrics, as scheduleWithFixedDelay introduces a growing delta from the original start point. Overriding this in a subclass to revert to the old behavior is permitted.
    • start

      public void start(long initialDelay, long period, TimeUnit unit)
      Starts the reporter polling at the given period.
      Parameters:
      initialDelay - the time to delay the first execution
      period - the amount of time between polls
      unit - the unit for period and initialDelay
    • stop

      public void stop()
      Stops the reporter and if shutdownExecutorOnStop is true then shuts down its thread of execution.

      Uses the shutdown pattern from http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html

    • close

      public void close()
      Stops the reporter and shuts down its thread of execution.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • report

      public void report()
      Report the current values of all metrics in the registry.
    • report

      public abstract void report(SortedMap<String,Gauge> gauges, SortedMap<String,Counter> counters, SortedMap<String,Histogram> histograms, SortedMap<String,Meter> meters, SortedMap<String,Timer> timers)
      Called periodically by the polling thread. Subclasses should report all the given metrics.
      Parameters:
      gauges - all of the gauges in the registry
      counters - all of the counters in the registry
      histograms - all of the histograms in the registry
      meters - all of the meters in the registry
      timers - all of the timers in the registry
    • getRateUnit

      protected String getRateUnit()
    • getDurationUnit

      protected String getDurationUnit()
    • convertDuration

      protected double convertDuration(double duration)
    • convertRate

      protected double convertRate(double rate)
    • isShutdownExecutorOnStop

      protected boolean isShutdownExecutorOnStop()
    • getDisabledMetricAttributes

      protected Set<MetricAttribute> getDisabledMetricAttributes()