Package com.codahale.metrics
Class ScheduledReporter
- java.lang.Object
-
- com.codahale.metrics.ScheduledReporter
-
- All Implemented Interfaces:
Reporter
,Closeable
,AutoCloseable
- Direct Known Subclasses:
CollectdReporter
,ConsoleReporter
,CsvReporter
,GraphiteReporter
,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:
ConsoleReporter
,CsvReporter
,Slf4jReporter
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit)
Creates a newScheduledReporter
instance.protected
ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor)
Creates a newScheduledReporter
instance.protected
ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor, boolean shutdownExecutorOnStop)
Creates a newScheduledReporter
instance.protected
ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor, boolean shutdownExecutorOnStop, Set<MetricAttribute> disabledMetricAttributes)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Stops the reporter and shuts down its thread of execution.protected double
convertDuration(double duration)
protected double
convertRate(double rate)
protected Set<MetricAttribute>
getDisabledMetricAttributes()
protected String
getDurationUnit()
protected String
getRateUnit()
protected boolean
isShutdownExecutorOnStop()
void
report()
Report the current values of all metrics in the registry.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.void
start(long initialDelay, long period, TimeUnit unit)
Starts the reporter polling at the given period.void
start(long period, TimeUnit unit)
Starts the reporter polling at the given period.void
stop()
Stops the reporter and if shutdownExecutorOnStop is true then shuts down its thread of execution.
-
-
-
Constructor Detail
-
ScheduledReporter
protected ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit)
Creates a newScheduledReporter
instance.- Parameters:
registry
- theMetricRegistry
containing the metrics this reporter will reportname
- the reporter's namefilter
- the filter for which metrics to reportrateUnit
- a unit of timedurationUnit
- a unit of time
-
ScheduledReporter
protected ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor)
Creates a newScheduledReporter
instance.- Parameters:
registry
- theMetricRegistry
containing the metrics this reporter will reportname
- the reporter's namefilter
- the filter for which metrics to reportexecutor
- the executor to use while scheduling reporting of metrics.
-
ScheduledReporter
protected ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor, boolean shutdownExecutorOnStop)
Creates a newScheduledReporter
instance.- Parameters:
registry
- theMetricRegistry
containing the metrics this reporter will reportname
- the reporter's namefilter
- the filter for which metrics to reportexecutor
- the executor to use while scheduling reporting of metrics.shutdownExecutorOnStop
- if true, then executor will be stopped in same time with this reporter
-
ScheduledReporter
protected ScheduledReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor, boolean shutdownExecutorOnStop, Set<MetricAttribute> disabledMetricAttributes)
-
-
Method Detail
-
start
public void start(long period, TimeUnit unit)
Starts the reporter polling at the given period.- Parameters:
period
- the amount of time between pollsunit
- the unit forperiod
-
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 executionperiod
- the amount of time between pollsunit
- the unit forperiod
andinitialDelay
-
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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 registrycounters
- all of the counters in the registryhistograms
- all of the histograms in the registrymeters
- all of the meters in the registrytimers
- 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()
-
-