com.yammer.metrics.reporting
Class CsvReporter

java.lang.Object
  extended by com.yammer.metrics.reporting.AbstractReporter
      extended by com.yammer.metrics.reporting.AbstractPollingReporter
          extended by com.yammer.metrics.reporting.CsvReporter
All Implemented Interfaces:
MetricProcessor<CsvReporter.Context>, Runnable

public class CsvReporter
extends AbstractPollingReporter
implements MetricProcessor<CsvReporter.Context>

A reporter which periodically appends data from each metric to a metric-specific CSV file in an output directory.


Nested Class Summary
static interface CsvReporter.Context
          The context used to output metrics.
 
Constructor Summary
CsvReporter(MetricsRegistry metricsRegistry, File outputDir)
          Creates a new CsvReporter which will write all metrics from the given MetricsRegistry to CSV files in the given output directory.
CsvReporter(MetricsRegistry metricsRegistry, MetricPredicate predicate, File outputDir)
          Creates a new CsvReporter which will write metrics from the given MetricsRegistry which match the given MetricPredicate to CSV files in the given output directory.
CsvReporter(MetricsRegistry metricsRegistry, MetricPredicate predicate, File outputDir, Clock clock)
          Creates a new CsvReporter which will write metrics from the given MetricsRegistry which match the given MetricPredicate to CSV files in the given output directory.
 
Method Summary
protected  PrintStream createStreamForMetric(MetricName metricName)
          Returns an opened PrintStream for the given MetricName which outputs data to a metric-specific .csv file in the output directory.
static void enable(File outputDir, long period, TimeUnit unit)
          Enables the CSV reporter for the default metrics registry, and causes it to write to files in outputDir with the specified period.
static void enable(MetricsRegistry metricsRegistry, File outputDir, long period, TimeUnit unit)
          Enables the CSV reporter for the given metrics registry, and causes it to write to files in outputDir with the specified period.
 void processCounter(MetricName name, Counter counter, CsvReporter.Context context)
          Process the given counter.
 void processGauge(MetricName name, Gauge<?> gauge, CsvReporter.Context context)
          Process the given gauge.
 void processHistogram(MetricName name, Histogram histogram, CsvReporter.Context context)
          Process the given histogram.
 void processMeter(MetricName name, Metered meter, CsvReporter.Context context)
          Process the given Metered instance.
 void processTimer(MetricName name, Timer timer, CsvReporter.Context context)
          Process the given timer.
 void run()
          The method called when a a poll is scheduled to occur.
 void shutdown()
          Stops the reporter and closes any internal resources.
 void start(long period, TimeUnit unit)
          Starts the reporter polling at the given period.
 
Methods inherited from class com.yammer.metrics.reporting.AbstractPollingReporter
shutdown
 
Methods inherited from class com.yammer.metrics.reporting.AbstractReporter
getMetricsRegistry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvReporter

public CsvReporter(MetricsRegistry metricsRegistry,
                   File outputDir)
Creates a new CsvReporter which will write all metrics from the given MetricsRegistry to CSV files in the given output directory.

Parameters:
outputDir - the directory to which files will be written
metricsRegistry - the MetricsRegistry containing the metrics this reporter will report

CsvReporter

public CsvReporter(MetricsRegistry metricsRegistry,
                   MetricPredicate predicate,
                   File outputDir)
Creates a new CsvReporter which will write metrics from the given MetricsRegistry which match the given MetricPredicate to CSV files in the given output directory.

Parameters:
metricsRegistry - the MetricsRegistry containing the metrics this reporter will report
predicate - the MetricPredicate which metrics are required to match before being written to files
outputDir - the directory to which files will be written

CsvReporter

public CsvReporter(MetricsRegistry metricsRegistry,
                   MetricPredicate predicate,
                   File outputDir,
                   Clock clock)
Creates a new CsvReporter which will write metrics from the given MetricsRegistry which match the given MetricPredicate to CSV files in the given output directory.

Parameters:
metricsRegistry - the MetricsRegistry containing the metrics this reporter will report
predicate - the MetricPredicate which metrics are required to match before being written to files
outputDir - the directory to which files will be written
clock - the clock used to measure time
Method Detail

enable

public static void enable(File outputDir,
                          long period,
                          TimeUnit unit)
Enables the CSV reporter for the default metrics registry, and causes it to write to files in outputDir with the specified period.

Parameters:
outputDir - the directory in which .csv files will be created
period - the period between successive outputs
unit - the time unit of period

enable

public static void enable(MetricsRegistry metricsRegistry,
                          File outputDir,
                          long period,
                          TimeUnit unit)
Enables the CSV reporter for the given metrics registry, and causes it to write to files in outputDir with the specified period.

Parameters:
metricsRegistry - the metrics registry
outputDir - the directory in which .csv files will be created
period - the period between successive outputs
unit - the time unit of period

createStreamForMetric

protected PrintStream createStreamForMetric(MetricName metricName)
                                     throws IOException
Returns an opened PrintStream for the given MetricName which outputs data to a metric-specific .csv file in the output directory.

Parameters:
metricName - the name of the metric
Returns:
an opened PrintStream specific to metricName
Throws:
IOException - if there is an error opening the stream

run

public void run()
Description copied from class: AbstractPollingReporter
The method called when a a poll is scheduled to occur.

Specified by:
run in interface Runnable
Specified by:
run in class AbstractPollingReporter

processMeter

public void processMeter(MetricName name,
                         Metered meter,
                         CsvReporter.Context context)
                  throws IOException
Description copied from interface: MetricProcessor
Process the given Metered instance.

Specified by:
processMeter in interface MetricProcessor<CsvReporter.Context>
Parameters:
name - the name of the meter
meter - the meter
context - the context of the meter
Throws:
IOException

processCounter

public void processCounter(MetricName name,
                           Counter counter,
                           CsvReporter.Context context)
                    throws IOException
Description copied from interface: MetricProcessor
Process the given counter.

Specified by:
processCounter in interface MetricProcessor<CsvReporter.Context>
Parameters:
name - the name of the counter
counter - the counter
context - the context of the meter
Throws:
IOException

processHistogram

public void processHistogram(MetricName name,
                             Histogram histogram,
                             CsvReporter.Context context)
                      throws IOException
Description copied from interface: MetricProcessor
Process the given histogram.

Specified by:
processHistogram in interface MetricProcessor<CsvReporter.Context>
Parameters:
name - the name of the histogram
histogram - the histogram
context - the context of the meter
Throws:
IOException

processTimer

public void processTimer(MetricName name,
                         Timer timer,
                         CsvReporter.Context context)
                  throws IOException
Description copied from interface: MetricProcessor
Process the given timer.

Specified by:
processTimer in interface MetricProcessor<CsvReporter.Context>
Parameters:
name - the name of the timer
timer - the timer
context - the context of the meter
Throws:
IOException

processGauge

public void processGauge(MetricName name,
                         Gauge<?> gauge,
                         CsvReporter.Context context)
                  throws IOException
Description copied from interface: MetricProcessor
Process the given gauge.

Specified by:
processGauge in interface MetricProcessor<CsvReporter.Context>
Parameters:
name - the name of the gauge
gauge - the gauge
context - the context of the meter
Throws:
IOException

start

public void start(long period,
                  TimeUnit unit)
Description copied from class: AbstractPollingReporter
Starts the reporter polling at the given period.

Overrides:
start in class AbstractPollingReporter
Parameters:
period - the amount of time between polls
unit - the unit for period

shutdown

public void shutdown()
Description copied from class: AbstractReporter
Stops the reporter and closes any internal resources.

Overrides:
shutdown in class AbstractPollingReporter


Copyright © 2012. All Rights Reserved.