com.yammer.metrics.reporting
Class GraphiteReporter

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

public class GraphiteReporter
extends AbstractPollingReporter
implements MetricProcessor<Long>

A simple reporter which sends out application metrics to a Graphite server periodically.


Nested Class Summary
static class GraphiteReporter.DefaultSocketProvider
           
 
Field Summary
protected  Clock clock
           
protected  Locale locale
           
protected  MetricPredicate predicate
           
protected  String prefix
           
 boolean printVMMetrics
           
protected  SocketProvider socketProvider
           
protected  VirtualMachineMetrics vm
           
protected  Writer writer
           
 
Constructor Summary
GraphiteReporter(MetricsRegistry metricsRegistry, String host, int port, String prefix)
          Creates a new GraphiteReporter.
GraphiteReporter(MetricsRegistry metricsRegistry, String prefix, MetricPredicate predicate, SocketProvider socketProvider, Clock clock)
          Creates a new GraphiteReporter.
GraphiteReporter(MetricsRegistry metricsRegistry, String prefix, MetricPredicate predicate, SocketProvider socketProvider, Clock clock, VirtualMachineMetrics vm)
          Creates a new GraphiteReporter.
GraphiteReporter(MetricsRegistry metricsRegistry, String prefix, MetricPredicate predicate, SocketProvider socketProvider, Clock clock, VirtualMachineMetrics vm, String name)
          Creates a new GraphiteReporter.
GraphiteReporter(String host, int port, String prefix)
          Creates a new GraphiteReporter.
 
Method Summary
static void enable(long period, TimeUnit unit, String host, int port)
          Enables the graphite reporter to send data for the default metrics registry to graphite server with the specified period.
static void enable(long period, TimeUnit unit, String host, int port, String prefix)
          Enables the graphite reporter to send data to graphite server with the specified period.
static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String host, int port)
          Enables the graphite reporter to send data for the given metrics registry to graphite server with the specified period.
static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String host, int port, String prefix)
          Enables the graphite reporter to send data to graphite server with the specified period.
static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String host, int port, String prefix, MetricPredicate predicate)
          Enables the graphite reporter to send data to graphite server with the specified period.
protected  void printRegularMetrics(Long epoch)
           
protected  void printVmMetrics(long epoch)
           
 void processCounter(MetricName name, Counter counter, Long epoch)
           
 void processGauge(MetricName name, Gauge<?> gauge, Long epoch)
           
 void processHistogram(MetricName name, Histogram histogram, Long epoch)
           
 void processMeter(MetricName name, Metered meter, Long epoch)
           
 void processTimer(MetricName name, Timer timer, Long epoch)
           
 void run()
           
protected  String sanitizeName(MetricName name)
           
protected  String sanitizeString(String s)
           
protected  void sendFloat(long timestamp, String name, String valueName, double value)
           
protected  void sendInt(long timestamp, String name, String valueName, long value)
           
protected  void sendObjToGraphite(long timestamp, String name, String valueName, Object value)
           
protected  void sendSampling(long epoch, String sanitizedName, Sampling metric)
           
protected  void sendSummarizable(long epoch, String sanitizedName, Summarizable metric)
           
protected  void sendToGraphite(long timestamp, String name, String value)
           
 
Methods inherited from class com.yammer.metrics.reporting.AbstractPollingReporter
shutdown, shutdown, start
 
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
 

Field Detail

prefix

protected final String prefix

predicate

protected final MetricPredicate predicate

locale

protected final Locale locale

clock

protected final Clock clock

socketProvider

protected final SocketProvider socketProvider

vm

protected final VirtualMachineMetrics vm

writer

protected Writer writer

printVMMetrics

public boolean printVMMetrics
Constructor Detail

GraphiteReporter

public GraphiteReporter(String host,
                        int port,
                        String prefix)
                 throws IOException
Creates a new GraphiteReporter.

Parameters:
host - is graphite server
port - is port on which graphite server is running
prefix - is prepended to all names reported to graphite
Throws:
IOException - if there is an error connecting to the Graphite server

GraphiteReporter

public GraphiteReporter(MetricsRegistry metricsRegistry,
                        String host,
                        int port,
                        String prefix)
                 throws IOException
Creates a new GraphiteReporter.

Parameters:
metricsRegistry - the metrics registry
host - is graphite server
port - is port on which graphite server is running
prefix - is prepended to all names reported to graphite
Throws:
IOException - if there is an error connecting to the Graphite server

GraphiteReporter

public GraphiteReporter(MetricsRegistry metricsRegistry,
                        String prefix,
                        MetricPredicate predicate,
                        SocketProvider socketProvider,
                        Clock clock)
                 throws IOException
Creates a new GraphiteReporter.

Parameters:
metricsRegistry - the metrics registry
prefix - is prepended to all names reported to graphite
predicate - filters metrics to be reported
socketProvider - a GraphiteReporter.DefaultSocketProvider instance
clock - a Clock instance
Throws:
IOException - if there is an error connecting to the Graphite server

GraphiteReporter

public GraphiteReporter(MetricsRegistry metricsRegistry,
                        String prefix,
                        MetricPredicate predicate,
                        SocketProvider socketProvider,
                        Clock clock,
                        VirtualMachineMetrics vm)
                 throws IOException
Creates a new GraphiteReporter.

Parameters:
metricsRegistry - the metrics registry
prefix - is prepended to all names reported to graphite
predicate - filters metrics to be reported
socketProvider - a GraphiteReporter.DefaultSocketProvider instance
clock - a Clock instance
vm - a VirtualMachineMetrics instance
Throws:
IOException - if there is an error connecting to the Graphite server

GraphiteReporter

public GraphiteReporter(MetricsRegistry metricsRegistry,
                        String prefix,
                        MetricPredicate predicate,
                        SocketProvider socketProvider,
                        Clock clock,
                        VirtualMachineMetrics vm,
                        String name)
                 throws IOException
Creates a new GraphiteReporter.

Parameters:
metricsRegistry - the metrics registry
prefix - is prepended to all names reported to graphite
predicate - filters metrics to be reported
socketProvider - a GraphiteReporter.DefaultSocketProvider instance
clock - a Clock instance
vm - a VirtualMachineMetrics instance
Throws:
IOException - if there is an error connecting to the Graphite server
Method Detail

enable

public static void enable(long period,
                          TimeUnit unit,
                          String host,
                          int port)
Enables the graphite reporter to send data for the default metrics registry to graphite server with the specified period.

Parameters:
period - the period between successive outputs
unit - the time unit of period
host - the host name of graphite server (carbon-cache agent)
port - the port number on which the graphite server is listening

enable

public static void enable(MetricsRegistry metricsRegistry,
                          long period,
                          TimeUnit unit,
                          String host,
                          int port)
Enables the graphite reporter to send data for the given metrics registry to graphite server with the specified period.

Parameters:
metricsRegistry - the metrics registry
period - the period between successive outputs
unit - the time unit of period
host - the host name of graphite server (carbon-cache agent)
port - the port number on which the graphite server is listening

enable

public static void enable(long period,
                          TimeUnit unit,
                          String host,
                          int port,
                          String prefix)
Enables the graphite reporter to send data to graphite server with the specified period.

Parameters:
period - the period between successive outputs
unit - the time unit of period
host - the host name of graphite server (carbon-cache agent)
port - the port number on which the graphite server is listening
prefix - the string which is prepended to all metric names

enable

public static void enable(MetricsRegistry metricsRegistry,
                          long period,
                          TimeUnit unit,
                          String host,
                          int port,
                          String prefix)
Enables the graphite reporter to send data to graphite server with the specified period.

Parameters:
metricsRegistry - the metrics registry
period - the period between successive outputs
unit - the time unit of period
host - the host name of graphite server (carbon-cache agent)
port - the port number on which the graphite server is listening
prefix - the string which is prepended to all metric names

enable

public static void enable(MetricsRegistry metricsRegistry,
                          long period,
                          TimeUnit unit,
                          String host,
                          int port,
                          String prefix,
                          MetricPredicate predicate)
Enables the graphite reporter to send data to graphite server with the specified period.

Parameters:
metricsRegistry - the metrics registry
period - the period between successive outputs
unit - the time unit of period
host - the host name of graphite server (carbon-cache agent)
port - the port number on which the graphite server is listening
prefix - the string which is prepended to all metric names
predicate - filters metrics to be reported

run

public void run()
Specified by:
run in interface Runnable
Specified by:
run in class AbstractPollingReporter

printRegularMetrics

protected void printRegularMetrics(Long epoch)

sendInt

protected void sendInt(long timestamp,
                       String name,
                       String valueName,
                       long value)

sendFloat

protected void sendFloat(long timestamp,
                         String name,
                         String valueName,
                         double value)

sendObjToGraphite

protected void sendObjToGraphite(long timestamp,
                                 String name,
                                 String valueName,
                                 Object value)

sendToGraphite

protected void sendToGraphite(long timestamp,
                              String name,
                              String value)

sanitizeName

protected String sanitizeName(MetricName name)

sanitizeString

protected String sanitizeString(String s)

processGauge

public void processGauge(MetricName name,
                         Gauge<?> gauge,
                         Long epoch)
                  throws IOException
Specified by:
processGauge in interface MetricProcessor<Long>
Throws:
IOException

processCounter

public void processCounter(MetricName name,
                           Counter counter,
                           Long epoch)
                    throws IOException
Specified by:
processCounter in interface MetricProcessor<Long>
Throws:
IOException

processMeter

public void processMeter(MetricName name,
                         Metered meter,
                         Long epoch)
                  throws IOException
Specified by:
processMeter in interface MetricProcessor<Long>
Throws:
IOException

processHistogram

public void processHistogram(MetricName name,
                             Histogram histogram,
                             Long epoch)
                      throws IOException
Specified by:
processHistogram in interface MetricProcessor<Long>
Throws:
IOException

processTimer

public void processTimer(MetricName name,
                         Timer timer,
                         Long epoch)
                  throws IOException
Specified by:
processTimer in interface MetricProcessor<Long>
Throws:
IOException

sendSummarizable

protected void sendSummarizable(long epoch,
                                String sanitizedName,
                                Summarizable metric)
                         throws IOException
Throws:
IOException

sendSampling

protected void sendSampling(long epoch,
                            String sanitizedName,
                            Sampling metric)
                     throws IOException
Throws:
IOException

printVmMetrics

protected void printVmMetrics(long epoch)


Copyright © 2012. All Rights Reserved.