com.yammer.metrics.core
Class MetricsRegistry

java.lang.Object
  extended by com.yammer.metrics.core.MetricsRegistry

public class MetricsRegistry
extends Object

A registry of metric instances.


Constructor Summary
MetricsRegistry()
           
 
Method Summary
 void addListener(MetricsRegistryListener listener)
          Adds a MetricsRegistryListener to a collection of listeners that will be notified on metric creation.
 Map<MetricName,Metric> allMetrics()
          Returns an unmodifiable map of all metrics and their names.
 MetricName createName(Class<?> klass, String name, String scope)
          Override to customize how MetricNames are created.
protected
<T extends Metric>
T
getOrAdd(MetricName name, T metric)
           
 CounterMetric newCounter(Class<?> klass, String name)
          Creates a new CounterMetric and registers it under the given class and name.
 CounterMetric newCounter(Class<?> klass, String name, String scope)
          Creates a new CounterMetric and registers it under the given class and name.
 CounterMetric newCounter(MetricName metricName)
          Creates a new CounterMetric and registers it under the given metric name.
<T> GaugeMetric<T>
newGauge(Class<?> klass, String name, GaugeMetric<T> metric)
          Given a new GaugeMetric, registers it under the given class and name.
<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.
<T> GaugeMetric<T>
newGauge(MetricName metricName, GaugeMetric<T> metric)
          Given a new GaugeMetric, registers it under the given metric name.
 HistogramMetric newHistogram(Class<?> klass, String name)
          Creates a new non-biased HistogramMetric and registers it under the given class and name.
 HistogramMetric newHistogram(Class<?> klass, String name, boolean biased)
          Creates a new HistogramMetric and registers it under the given class and name.
 HistogramMetric newHistogram(Class<?> klass, String name, String scope)
          Creates a new non-biased HistogramMetric and registers it under the given class, name, and scope.
 HistogramMetric newHistogram(Class<?> klass, String name, String scope, boolean biased)
          Creates a new HistogramMetric and registers it under the given class, name, and scope.
 HistogramMetric newHistogram(MetricName metricName, boolean biased)
          Creates a new HistogramMetric and registers it under the given metric name.
 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.
 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.
 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.
 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.
 MeterMetric newMeter(Class<?> klass, String name, String eventType, TimeUnit unit)
          Creates a new MeterMetric and registers it under the given class and name.
 MeterMetric newMeter(MetricName metricName, String eventType, TimeUnit unit)
          Creates a new MeterMetric and registers it under the given metric name.
 ScheduledExecutorService newMeterTickThreadPool()
           
protected  ConcurrentMap<MetricName,Metric> newMetricsMap()
          Returns a new ConcurrentMap implementation.
 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.
 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.
 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.
 TimerMetric newTimer(Class<?> klass, String name, TimeUnit durationUnit, TimeUnit rateUnit)
          Creates a new TimerMetric and registers it under the given class and name.
 TimerMetric newTimer(MetricName metricName, TimeUnit durationUnit, TimeUnit rateUnit)
          Creates a new TimerMetric and registers it under the given metric name.
 void removeListener(MetricsRegistryListener listener)
          Removes a MetricsRegistryListener from this registry's collection of listeners.
 void removeMetric(Class<?> klass, String name)
          Removes the metric for the given class with the given name.
 void removeMetric(Class<?> klass, String name, String scope)
          Removes the metric for the given class with the given name and scope.
 void removeMetric(MetricName name)
          Removes the metric with the given name.
 ThreadPools threadPools()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetricsRegistry

public MetricsRegistry()
Method Detail

newGauge

public <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 <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 <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 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 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 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 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 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 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 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 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 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 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 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

newMeter

public 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 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 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 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 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 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 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 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

createName

public MetricName createName(Class<?> klass,
                             String name,
                             String scope)
Override to customize how MetricNames are created.

Parameters:
klass - the class which owns the metric
name - the name of the metric
scope - the metric's scope
Returns:
the metric's full name

allMetrics

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

Returns:
an unmodifiable map of all metrics and their names

threadPools

public ThreadPools threadPools()

newMeterTickThreadPool

public ScheduledExecutorService newMeterTickThreadPool()

removeMetric

public 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 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

removeMetric

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

Parameters:
name - the name of the metric

newMetricsMap

protected ConcurrentMap<MetricName,Metric> newMetricsMap()
Returns a new ConcurrentMap implementation. Subclass this to do weird things with your own MetricsRegistry implementation.

Returns:
a new ConcurrentMap

getOrAdd

protected final <T extends Metric> T getOrAdd(MetricName name,
                                              T metric)

addListener

public void addListener(MetricsRegistryListener listener)
Adds a MetricsRegistryListener to a collection of listeners that will be notified on metric creation. Listeners will be notified in the order in which they are added.

N.B.: The listener will be notified of all existing metrics when it first registers.

Parameters:
listener - the listener that will be notified

removeListener

public void removeListener(MetricsRegistryListener listener)
Removes a MetricsRegistryListener from this registry's collection of listeners.

Parameters:
listener - the listener that will be removed


Copyright © 2011. All Rights Reserved.