com.yammer.metrics.reporting
Class GangliaReporter

java.lang.Object
  extended by com.yammer.metrics.reporting.AbstractReporter
      extended by com.yammer.metrics.reporting.AbstractPollingReporter
          extended by com.yammer.metrics.reporting.GangliaReporter
All Implemented Interfaces:
MetricsProcessor<String>, Runnable

public class GangliaReporter
extends AbstractPollingReporter
implements MetricsProcessor<String>

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

NOTE: this reporter only works with Ganglia 3.1 and greater. The message protocol for earlier versions of Ganglia is different.

This code heavily borrows from GangliaWriter in JMXTrans which is based on GangliaContext31 from Hadoop.


Field Summary
 boolean printVMMetrics
           
 
Fields inherited from class com.yammer.metrics.reporting.AbstractReporter
metricsRegistry
 
Constructor Summary
GangliaReporter(MetricsRegistry metricsRegistry, String gangliaHost, int port, String groupPrefix)
          Creates a new GangliaReporter.
GangliaReporter(MetricsRegistry metricsRegistry, String gangliaHost, int port, String groupPrefix, MetricPredicate predicate)
          Creates a new GangliaReporter.
GangliaReporter(MetricsRegistry metricsRegistry, String gangliaHost, int port, String groupPrefix, MetricPredicate predicate, boolean compressPackageNames)
          Creates a new GangliaReporter.
GangliaReporter(MetricsRegistry metricsRegistry, String groupPrefix, MetricPredicate predicate, boolean compressPackageNames, GangliaMessageBuilder gangliaMessageBuilder)
          Creates a new GangliaReporter.
GangliaReporter(String gangliaHost, int port)
          Creates a new GangliaReporter.
GangliaReporter(String gangliaHost, int port, boolean compressPackageNames)
          Creates a new GangliaReporter.
 
Method Summary
static void enable(long period, TimeUnit unit, String gangliaHost, int port)
          Enables the ganglia reporter to send data for the default metrics registry to ganglia server with the specified period.
static void enable(long period, TimeUnit unit, String gangliaHost, int port, boolean compressPackageNames)
          Enables the ganglia reporter to send data for the default metrics registry to ganglia server with the specified period.
static void enable(long period, TimeUnit unit, String gangliaHost, int port, String groupPrefix)
          Enables the ganglia reporter to send data for the default metrics registry to ganglia server with the specified period.
static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String gangliaHost, int port, String groupPrefix)
          Enables the ganglia reporter to send data for the given metrics registry to ganglia server with the specified period.
static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String gangliaHost, int port, String groupPrefix, MetricPredicate predicate)
          Enables the ganglia reporter to send data to ganglia server with the specified period.
static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String gangliaHost, int port, String groupPrefix, MetricPredicate predicate, boolean compressPackageNames)
          Enables the ganglia reporter to send data to ganglia server with the specified period.
 void processCounter(MetricName name, CounterMetric counter, String x)
           
 void processGauge(MetricName name, GaugeMetric<?> gauge, String x)
           
 void processHistogram(MetricName name, HistogramMetric histogram, String x)
           
 void processMeter(MetricName name, Metered meter, String x)
           
 void processTimer(MetricName name, TimerMetric timer, String x)
           
 void run()
           
protected  String sanitizeName(MetricName name)
           
 
Methods inherited from class com.yammer.metrics.reporting.AbstractPollingReporter
shutdown, shutdown, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printVMMetrics

public boolean printVMMetrics
Constructor Detail

GangliaReporter

public GangliaReporter(String gangliaHost,
                       int port)
                throws IOException
Creates a new GangliaReporter.

Parameters:
gangliaHost - is ganglia server
port - is port on which ganglia server is running
Throws:
IOException - if there is an error connecting to the ganglia server

GangliaReporter

public GangliaReporter(String gangliaHost,
                       int port,
                       boolean compressPackageNames)
                throws IOException
Creates a new GangliaReporter.

Parameters:
gangliaHost - is ganglia server
port - is port on which ganglia server is running
compressPackageNames -
Throws:
IOException - if there is an error connecting to the ganglia server

GangliaReporter

public GangliaReporter(MetricsRegistry metricsRegistry,
                       String gangliaHost,
                       int port,
                       String groupPrefix)
                throws IOException
Creates a new GangliaReporter.

Parameters:
metricsRegistry - the metrics registry
gangliaHost - is ganglia server
port - is port on which ganglia server is running
groupPrefix - prefix to the ganglia group name (such as myapp_counter)
Throws:
IOException - if there is an error connecting to the ganglia server

GangliaReporter

public GangliaReporter(MetricsRegistry metricsRegistry,
                       String gangliaHost,
                       int port,
                       String groupPrefix,
                       MetricPredicate predicate)
                throws IOException
Creates a new GangliaReporter.

Parameters:
metricsRegistry - the metrics registry
gangliaHost - is ganglia server
port - is port on which ganglia server is running
groupPrefix - prefix to the ganglia group name (such as myapp_counter)
predicate - filters metrics to be reported
Throws:
IOException - if there is an error connecting to the ganglia server

GangliaReporter

public GangliaReporter(MetricsRegistry metricsRegistry,
                       String gangliaHost,
                       int port,
                       String groupPrefix,
                       MetricPredicate predicate,
                       boolean compressPackageNames)
                throws IOException
Creates a new GangliaReporter.

Parameters:
metricsRegistry - the metrics registry
gangliaHost - is ganglia server
port - is port on which ganglia server is running
groupPrefix - prefix to the ganglia group name (such as myapp_counter)
predicate - filters metrics to be reported
compressPackageNames - if true reporter will compress package names e.g. com.foo.MetricName becomes c.f.MetricName
Throws:
IOException - if there is an error connecting to the ganglia server

GangliaReporter

public GangliaReporter(MetricsRegistry metricsRegistry,
                       String groupPrefix,
                       MetricPredicate predicate,
                       boolean compressPackageNames,
                       GangliaMessageBuilder gangliaMessageBuilder)
                throws IOException
Creates a new GangliaReporter.

Parameters:
metricsRegistry - the metrics registry
groupPrefix - prefix to the ganglia group name (such as myapp_counter)
predicate - filters metrics to be reported
compressPackageNames - if true reporter will compress package names e.g. com.foo.MetricName becomes c.f.MetricName
Throws:
IOException - if there is an error connecting to the ganglia server
Method Detail

enable

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

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

enable

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

Parameters:
period - the period between successive outputs
unit - the time unit of period
gangliaHost - the gangliaHost name of ganglia server (carbon-cache agent)
port - the port number on which the ganglia server is listening
groupPrefix - prefix to the ganglia group name (such as myapp_counter)

enable

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

Parameters:
period - the period between successive outputs
unit - the time unit of period
gangliaHost - the gangliaHost name of ganglia server (carbon-cache agent)
port - the port number on which the ganglia server is listening
compressPackageNames - if true reporter will compress package names e.g. com.foo.MetricName becomes c.f.MetricName

enable

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

Parameters:
metricsRegistry - the metrics registry
period - the period between successive outputs
unit - the time unit of period
gangliaHost - the gangliaHost name of ganglia server (carbon-cache agent)
port - the port number on which the ganglia server is listening
groupPrefix - prefix to the ganglia group name (such as myapp_counter)

enable

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

Parameters:
metricsRegistry - the metrics registry
period - the period between successive outputs
unit - the time unit of period
gangliaHost - the gangliaHost name of ganglia server (carbon-cache agent)
port - the port number on which the ganglia server is listening
groupPrefix - prefix to the ganglia group name (such as myapp_counter)
predicate - filters metrics to be reported

enable

public static void enable(MetricsRegistry metricsRegistry,
                          long period,
                          TimeUnit unit,
                          String gangliaHost,
                          int port,
                          String groupPrefix,
                          MetricPredicate predicate,
                          boolean compressPackageNames)
Enables the ganglia reporter to send data to ganglia server with the specified period.

Parameters:
metricsRegistry - the metrics registry
period - the period between successive outputs
unit - the time unit of period
gangliaHost - the gangliaHost name of ganglia server (carbon-cache agent)
port - the port number on which the ganglia server is listening
groupPrefix - prefix to the ganglia group name (such as myapp_counter)
predicate - filters metrics to be reported
compressPackageNames - if true reporter will compress package names e.g. com.foo.MetricName becomes c.f.MetricName

run

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

processGauge

public void processGauge(MetricName name,
                         GaugeMetric<?> gauge,
                         String x)
                  throws IOException
Specified by:
processGauge in interface MetricsProcessor<String>
Throws:
IOException

processCounter

public void processCounter(MetricName name,
                           CounterMetric counter,
                           String x)
                    throws IOException
Specified by:
processCounter in interface MetricsProcessor<String>
Throws:
IOException

processMeter

public void processMeter(MetricName name,
                         Metered meter,
                         String x)
                  throws IOException
Specified by:
processMeter in interface MetricsProcessor<String>
Throws:
IOException

processHistogram

public void processHistogram(MetricName name,
                             HistogramMetric histogram,
                             String x)
                      throws IOException
Specified by:
processHistogram in interface MetricsProcessor<String>
Throws:
IOException

processTimer

public void processTimer(MetricName name,
                         TimerMetric timer,
                         String x)
                  throws IOException
Specified by:
processTimer in interface MetricsProcessor<String>
Throws:
IOException

sanitizeName

protected String sanitizeName(MetricName name)


Copyright © 2011. All Rights Reserved.