Package com.codahale.metrics
Class ScheduledReporter
- java.lang.Object
-
- com.codahale.metrics.ScheduledReporter
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
ConsoleReporter,CsvReporter,GraphiteReporter,Slf4jReporter
public abstract class ScheduledReporter extends java.lang.Object implements java.io.CloseableThe abstract base class for all scheduled reporters (i.e., reporters which process a registry's metrics periodically).- See Also:
ConsoleReporter,CsvReporter,Slf4jReporter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classScheduledReporter.NamedThreadFactoryA simple named thread factory.
-
Field Summary
Fields Modifier and Type Field Description private doubledurationFactorprivate java.lang.StringdurationUnitprivate java.util.concurrent.ScheduledExecutorServiceexecutorprivate MetricFilterfilterprivate doublerateFactorprivate java.lang.StringrateUnitprivate MetricRegistryregistry
-
Constructor Summary
Constructors Modifier Constructor Description protectedScheduledReporter(MetricRegistry registry, java.lang.String name, MetricFilter filter, java.util.concurrent.TimeUnit rateUnit, java.util.concurrent.TimeUnit durationUnit)Creates a newScheduledReporterinstance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private java.lang.StringcalculateRateUnit(java.util.concurrent.TimeUnit unit)voidclose()Stops the reporter and shuts down its thread of execution.protected doubleconvertDuration(double duration)protected doubleconvertRate(double rate)protected java.lang.StringgetDurationUnit()protected java.lang.StringgetRateUnit()voidreport()Report the current values of all metrics in the registry.abstract voidreport(java.util.SortedMap<java.lang.String,Gauge> gauges, java.util.SortedMap<java.lang.String,Counter> counters, java.util.SortedMap<java.lang.String,Histogram> histograms, java.util.SortedMap<java.lang.String,Meter> meters, java.util.SortedMap<java.lang.String,Timer> timers)Called periodically by the polling thread.voidstart(long period, java.util.concurrent.TimeUnit unit)Starts the reporter polling at the given period.voidstop()Stops the reporter and shuts down its thread of execution.
-
-
-
Field Detail
-
registry
private final MetricRegistry registry
-
executor
private final java.util.concurrent.ScheduledExecutorService executor
-
filter
private final MetricFilter filter
-
durationFactor
private final double durationFactor
-
durationUnit
private final java.lang.String durationUnit
-
rateFactor
private final double rateFactor
-
rateUnit
private final java.lang.String rateUnit
-
-
Constructor Detail
-
ScheduledReporter
protected ScheduledReporter(MetricRegistry registry, java.lang.String name, MetricFilter filter, java.util.concurrent.TimeUnit rateUnit, java.util.concurrent.TimeUnit durationUnit)
Creates a newScheduledReporterinstance.- Parameters:
registry- theMetricRegistrycontaining the metrics this reporter will reportname- the reporter's namefilter- the filter for which metrics to report
-
-
Method Detail
-
start
public void start(long period, java.util.concurrent.TimeUnit unit)Starts the reporter polling at the given period.- Parameters:
period- the amount of time between pollsunit- the unit forperiod
-
stop
public void stop()
Stops the reporter and shuts down its thread of execution.
-
close
public void close()
Stops the reporter and shuts down its thread of execution.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
report
public void report()
Report the current values of all metrics in the registry.
-
report
public abstract void report(java.util.SortedMap<java.lang.String,Gauge> gauges, java.util.SortedMap<java.lang.String,Counter> counters, java.util.SortedMap<java.lang.String,Histogram> histograms, java.util.SortedMap<java.lang.String,Meter> meters, java.util.SortedMap<java.lang.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 java.lang.String getRateUnit()
-
getDurationUnit
protected java.lang.String getDurationUnit()
-
convertDuration
protected double convertDuration(double duration)
-
convertRate
protected double convertRate(double rate)
-
calculateRateUnit
private java.lang.String calculateRateUnit(java.util.concurrent.TimeUnit unit)
-
-