com.yammer.metrics
Class Metrics

java.lang.Object
  extended by com.yammer.metrics.Metrics

public class Metrics
extends Object

A set of factory methods for creating centrally registered metric instances.


Method Summary
static Map<MetricName,Metric> allMetrics()
          Returns an unmodifiable map of all metrics and their names.
static MetricsRegistry defaultRegistry()
          Returns the (static) default registry.
static void enableConsoleReporting(long period, TimeUnit unit)
          Deprecated. use ConsoleReporter.enable(long, java.util.concurrent.TimeUnit) instead
static CounterMetric newCounter(Class<?> klass, String name)
          Creates a new CounterMetric and registers it under the given class and name.
static CounterMetric newCounter(Class<?> klass, String name, String scope)
          Creates a new CounterMetric and registers it under the given class and name.
static CounterMetric newCounter(MetricName metricName)
          Creates a new CounterMetric and registers it under the given metric name.
static
<T> GaugeMetric<T>
newGauge(Class<?> klass, String name, GaugeMetric<T> metric)
          Given a new GaugeMetric, registers it under the given class and name.
static
<T> GaugeMetric<T>
newGauge(Class<?> klass, String name, String scope, GaugeMetric<T> metric)
          Given a new GaugeMetric, registers it under the given class and name.
static
<T> GaugeMetric<T>
newGauge(MetricName metricName, GaugeMetric<T> metric)
          Given a new GaugeMetric, registers it under the given metric name.
static HistogramMetric newHistogram(Class<?> klass, String name)
          Creates a new non-biased HistogramMetric and registers it under the given class and name.
static HistogramMetric newHistogram(Class<?> klass, String name, boolean biased)
          Creates a new HistogramMetric and registers it under the given class and name.
static HistogramMetric newHistogram(Class<?> klass, String name, String scope)
          Creates a new non-biased HistogramMetric and registers it under the given class, name, and scope.
static HistogramMetric newHistogram(Class<?> klass, String name, String scope, boolean biased)
          Creates a new HistogramMetric and registers it under the given class, name, and scope.
static HistogramMetric newHistogram(MetricName metricName)
          Creates a new non-biased HistogramMetric and registers it under the given metric name.
static HistogramMetric newHistogram(MetricName metricName, boolean biased)
          Creates a new HistogramMetric and registers it under the given metric name.
static JmxGauge newJmxGauge(Class<?> klass, String name, String objectName, String attribute)
          Given a JMX MBean's object name and an attribute name, registers a gauge for that attribute under the given class and name.
static JmxGauge newJmxGauge(Class<?> klass, String name, String scope, String objectName, String attribute)
          Given a JMX MBean's object name and an attribute name, registers a gauge for that attribute under the given class, name, and scope.
static JmxGauge newJmxGauge(MetricName metricName, String objectName, String attribute)
          Given a JMX MBean's object name and an attribute name, registers a gauge for that attribute under the given metric name.
static MeterMetric newMeter(Class<?> klass, String name, String scope, String eventType, TimeUnit unit)
          Creates a new MeterMetric and registers it under the given class, name, and scope.
static MeterMetric newMeter(Class<?> klass, String name, String eventType, TimeUnit unit)
          Creates a new MeterMetric and registers it under the given class and name.
static MeterMetric newMeter(MetricName metricName, String eventType, TimeUnit unit)
          Creates a new MeterMetric and registers it under the given metric name.
static TimerMetric newTimer(Class<?> klass, String name)
          Creates a new TimerMetric and registers it under the given class and name, measuring elapsed time in milliseconds and invocations per second.
static TimerMetric newTimer(Class<?> klass, String name, String scope)
          Creates a new TimerMetric and registers it under the given class, name, and scope, measuring elapsed time in milliseconds and invocations per second.
static TimerMetric newTimer(Class<?> klass, String name, String scope, TimeUnit durationUnit, TimeUnit rateUnit)
          Creates a new TimerMetric and registers it under the given class, name, and scope.
static TimerMetric newTimer(Class<?> klass, String name, TimeUnit durationUnit, TimeUnit rateUnit)
          Creates a new TimerMetric and registers it under the given class and name.
static TimerMetric newTimer(MetricName metricName, TimeUnit durationUnit, TimeUnit rateUnit)
          Creates a new TimerMetric and registers it under the given metric name.
static void removeMetric(Class<?> klass, String name)
          Removes the metric for the given class with the given name.
static void removeMetric(Class<?> klass, String name, String scope)
          Removes the metric for the given class with the given name and scope.
static void removeMetric(MetricName name)
          Removes the metric with the given name.
static void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newGauge

public static <T> GaugeMetric<T> newGauge(Class<?> klass,
                                          String name,
                                          GaugeMetric<T> metric)
Given a new GaugeMetric, registers it under the given class and name.

Type Parameters:
T - the type of the value returned by the metric
Parameters:
klass - the class which owns the metric
name - the name of the metric
metric - the metric
Returns:
metric

newGauge

public static <T> GaugeMetric<T> newGauge(Class<?> klass,
                                          String name,
                                          String scope,
                                          GaugeMetric<T> metric)
Given a new GaugeMetric, registers it under the given class and name.

Type Parameters:
T - the type of the value returned by the metric
Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
metric - the metric
Returns:
metric

newGauge

public static <T> GaugeMetric<T> newGauge(MetricName metricName,
                                          GaugeMetric<T> metric)
Given a new GaugeMetric, registers it under the given metric name.

Type Parameters:
T - the type of the value returned by the metric
Parameters:
metricName - the name of the metric
metric - the metric
Returns:
metric

newJmxGauge

public static JmxGauge newJmxGauge(Class<?> klass,
                                   String name,
                                   String objectName,
                                   String attribute)
                            throws MalformedObjectNameException
Given a JMX MBean's object name and an attribute name, registers a gauge for that attribute under the given class and name.

Parameters:
klass - the class which owns the metric
name - the name of the metric
objectName - the object name of the MBean
attribute - the name of the bean's attribute
Returns:
a new JmxGauge
Throws:
MalformedObjectNameException - if the object name is malformed

newJmxGauge

public static JmxGauge newJmxGauge(Class<?> klass,
                                   String name,
                                   String scope,
                                   String objectName,
                                   String attribute)
                            throws MalformedObjectNameException
Given a JMX MBean's object name and an attribute name, registers a gauge for that attribute under the given class, name, and scope.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
objectName - the object name of the MBean
attribute - the name of the bean's attribute
Returns:
a new JmxGauge
Throws:
MalformedObjectNameException - if the object name is malformed

newJmxGauge

public static JmxGauge newJmxGauge(MetricName metricName,
                                   String objectName,
                                   String attribute)
                            throws MalformedObjectNameException
Given a JMX MBean's object name and an attribute name, registers a gauge for that attribute under the given metric name.

Parameters:
metricName - the name of the metric
objectName - the object name of the MBean
attribute - the name of the bean's attribute
Returns:
a new JmxGauge
Throws:
MalformedObjectNameException - if the object name is malformed

newCounter

public static CounterMetric newCounter(Class<?> klass,
                                       String name)
Creates a new CounterMetric and registers it under the given class and name.

Parameters:
klass - the class which owns the metric
name - the name of the metric
Returns:
a new CounterMetric

newCounter

public static CounterMetric newCounter(Class<?> klass,
                                       String name,
                                       String scope)
Creates a new CounterMetric and registers it under the given class and name.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
Returns:
a new CounterMetric

newCounter

public static CounterMetric newCounter(MetricName metricName)
Creates a new CounterMetric and registers it under the given metric name.

Parameters:
metricName - the name of the metric
Returns:
a new CounterMetric

newHistogram

public static HistogramMetric newHistogram(Class<?> klass,
                                           String name,
                                           boolean biased)
Creates a new HistogramMetric and registers it under the given class and name.

Parameters:
klass - the class which owns the metric
name - the name of the metric
biased - whether or not the histogram should be biased
Returns:
a new HistogramMetric

newHistogram

public static HistogramMetric newHistogram(Class<?> klass,
                                           String name,
                                           String scope,
                                           boolean biased)
Creates a new HistogramMetric and registers it under the given class, name, and scope.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
biased - whether or not the histogram should be biased
Returns:
a new HistogramMetric

newHistogram

public static HistogramMetric newHistogram(MetricName metricName,
                                           boolean biased)
Creates a new HistogramMetric and registers it under the given metric name.

Parameters:
metricName - the name of the metric
biased - whether or not the histogram should be biased
Returns:
a new HistogramMetric

newHistogram

public static HistogramMetric newHistogram(Class<?> klass,
                                           String name)
Creates a new non-biased HistogramMetric and registers it under the given class and name.

Parameters:
klass - the class which owns the metric
name - the name of the metric
Returns:
a new HistogramMetric

newHistogram

public static HistogramMetric newHistogram(Class<?> klass,
                                           String name,
                                           String scope)
Creates a new non-biased HistogramMetric and registers it under the given class, name, and scope.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
Returns:
a new HistogramMetric

newHistogram

public static HistogramMetric newHistogram(MetricName metricName)
Creates a new non-biased HistogramMetric and registers it under the given metric name.

Parameters:
metricName - the name of the metric
Returns:
a new HistogramMetric

newMeter

public static MeterMetric newMeter(Class<?> klass,
                                   String name,
                                   String eventType,
                                   TimeUnit unit)
Creates a new MeterMetric and registers it under the given class and name.

Parameters:
klass - the class which owns the metric
name - the name of the metric
eventType - the plural name of the type of events the meter is measuring (e.g., "requests")
unit - the rate unit of the new meter
Returns:
a new MeterMetric

newMeter

public static MeterMetric newMeter(Class<?> klass,
                                   String name,
                                   String scope,
                                   String eventType,
                                   TimeUnit unit)
Creates a new MeterMetric and registers it under the given class, name, and scope.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
eventType - the plural name of the type of events the meter is measuring (e.g., "requests")
unit - the rate unit of the new meter
Returns:
a new MeterMetric

newMeter

public static MeterMetric newMeter(MetricName metricName,
                                   String eventType,
                                   TimeUnit unit)
Creates a new MeterMetric and registers it under the given metric name.

Parameters:
metricName - the name of the metric
eventType - the plural name of the type of events the meter is measuring (e.g., "requests")
unit - the rate unit of the new meter
Returns:
a new MeterMetric

newTimer

public static TimerMetric newTimer(Class<?> klass,
                                   String name,
                                   TimeUnit durationUnit,
                                   TimeUnit rateUnit)
Creates a new TimerMetric and registers it under the given class and name.

Parameters:
klass - the class which owns the metric
name - the name of the metric
durationUnit - the duration scale unit of the new timer
rateUnit - the rate scale unit of the new timer
Returns:
a new TimerMetric

newTimer

public static TimerMetric newTimer(Class<?> klass,
                                   String name)
Creates a new TimerMetric and registers it under the given class and name, measuring elapsed time in milliseconds and invocations per second.

Parameters:
klass - the class which owns the metric
name - the name of the metric
Returns:
a new TimerMetric

newTimer

public static TimerMetric newTimer(Class<?> klass,
                                   String name,
                                   String scope,
                                   TimeUnit durationUnit,
                                   TimeUnit rateUnit)
Creates a new TimerMetric and registers it under the given class, name, and scope.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
durationUnit - the duration scale unit of the new timer
rateUnit - the rate scale unit of the new timer
Returns:
a new TimerMetric

newTimer

public static TimerMetric newTimer(Class<?> klass,
                                   String name,
                                   String scope)
Creates a new TimerMetric and registers it under the given class, name, and scope, measuring elapsed time in milliseconds and invocations per second.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the scope of the metric
Returns:
a new TimerMetric

newTimer

public static TimerMetric newTimer(MetricName metricName,
                                   TimeUnit durationUnit,
                                   TimeUnit rateUnit)
Creates a new TimerMetric and registers it under the given metric name.

Parameters:
metricName - the name of the metric
durationUnit - the duration scale unit of the new timer
rateUnit - the rate scale unit of the new timer
Returns:
a new TimerMetric

removeMetric

public static void removeMetric(MetricName name)
Removes the metric with the given name.

Parameters:
name - the name of the metric

removeMetric

public static void removeMetric(Class<?> klass,
                                String name)
Removes the metric for the given class with the given name.

Parameters:
klass - the klass the metric is associated with
name - the name of the metric

removeMetric

public static void removeMetric(Class<?> klass,
                                String name,
                                String scope)
Removes the metric for the given class with the given name and scope.

Parameters:
klass - the klass the metric is associated with
name - the name of the metric
scope - the scope of the metric

enableConsoleReporting

@Deprecated
public static void enableConsoleReporting(long period,
                                                     TimeUnit unit)
Deprecated. use ConsoleReporter.enable(long, java.util.concurrent.TimeUnit) instead

Enables the console reporter and causes it to print to STDOUT with the specified period.

Parameters:
period - the period between successive outputs
unit - the time unit of period

allMetrics

public static Map<MetricName,Metric> allMetrics()
Returns an unmodifiable map of all metrics and their names.

Returns:
an unmodifiable map of all metrics and their names

defaultRegistry

public static MetricsRegistry defaultRegistry()
Returns the (static) default registry.

Returns:
the metrics registry

shutdown

public static void shutdown()


Copyright © 2011. All Rights Reserved.