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.Closeable
The 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 class
ScheduledReporter.NamedThreadFactory
A simple named thread factory.
-
Field Summary
Fields Modifier and Type Field Description private double
durationFactor
private java.lang.String
durationUnit
private java.util.concurrent.ScheduledExecutorService
executor
private MetricFilter
filter
private double
rateFactor
private java.lang.String
rateUnit
private MetricRegistry
registry
-
Constructor Summary
Constructors Modifier Constructor Description protected
ScheduledReporter(MetricRegistry registry, java.lang.String name, MetricFilter filter, java.util.concurrent.TimeUnit rateUnit, java.util.concurrent.TimeUnit durationUnit)
Creates a newScheduledReporter
instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private java.lang.String
calculateRateUnit(java.util.concurrent.TimeUnit unit)
void
close()
Stops the reporter and shuts down its thread of execution.protected double
convertDuration(double duration)
protected double
convertRate(double rate)
protected java.lang.String
getDurationUnit()
protected java.lang.String
getRateUnit()
void
report()
Report the current values of all metrics in the registry.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.void
start(long period, java.util.concurrent.TimeUnit unit)
Starts the reporter polling at the given period.void
stop()
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 newScheduledReporter
instance.- Parameters:
registry
- theMetricRegistry
containing 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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)
-
-