public class MetricsRegistry extends Object
Constructor and Description |
---|
MetricsRegistry()
Creates a new
MetricsRegistry . |
MetricsRegistry(Clock clock)
Creates a new
MetricsRegistry with the given Clock instance. |
Modifier and Type | Method and Description |
---|---|
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.
|
protected MetricName |
createName(Class<?> klass,
String name,
String scope)
Override to customize how
MetricName s are created. |
protected <T extends Metric> |
getOrAdd(MetricName name,
T metric)
Gets any existing metric with the given name or, if none exists, adds the given metric.
|
SortedMap<String,SortedMap<MetricName,Metric>> |
groupedMetrics()
Returns a grouped and sorted map of all registered metrics.
|
SortedMap<String,SortedMap<MetricName,Metric>> |
groupedMetrics(MetricPredicate predicate)
Returns a grouped and sorted map of all registered metrics which match then given
MetricPredicate . |
Counter |
newCounter(Class<?> klass,
String name)
Creates a new
Counter and registers it under the given class and name. |
Counter |
newCounter(Class<?> klass,
String name,
String scope)
Creates a new
Counter and registers it under the given class and name. |
Counter |
newCounter(MetricName metricName)
Creates a new
Counter and registers it under the given metric name. |
<T> Gauge<T> |
newGauge(Class<?> klass,
String name,
Gauge<T> metric)
Given a new
Gauge , registers it under the given class and name. |
<T> Gauge<T> |
newGauge(Class<?> klass,
String name,
String scope,
Gauge<T> metric)
Given a new
Gauge , registers it under the given class and name. |
<T> Gauge<T> |
newGauge(MetricName metricName,
Gauge<T> metric)
Given a new
Gauge , registers it under the given metric name. |
Histogram |
newHistogram(Class<?> klass,
String name)
Creates a new non-biased
Histogram and registers it under the given class and name. |
Histogram |
newHistogram(Class<?> klass,
String name,
boolean biased)
Creates a new
Histogram and registers it under the given class and name. |
Histogram |
newHistogram(Class<?> klass,
String name,
String scope)
Creates a new non-biased
Histogram and registers it under the given class, name, and
scope. |
Histogram |
newHistogram(Class<?> klass,
String name,
String scope,
boolean biased)
Creates a new
Histogram and registers it under the given class, name, and scope. |
Histogram |
newHistogram(MetricName metricName,
boolean biased)
Creates a new
Histogram and registers it under the given metric name. |
Meter |
newMeter(Class<?> klass,
String name,
String scope,
String eventType,
TimeUnit unit)
Creates a new
Meter and registers it under the given class, name, and scope. |
Meter |
newMeter(Class<?> klass,
String name,
String eventType,
TimeUnit unit)
Creates a new
Meter and registers it under the given class and name. |
Meter |
newMeter(MetricName metricName,
String eventType,
TimeUnit unit)
Creates a new
Meter and registers it under the given metric name. |
protected ConcurrentMap<MetricName,Metric> |
newMetricsMap()
Returns a new
ConcurrentMap implementation. |
ScheduledExecutorService |
newScheduledThreadPool(int poolSize,
String name)
Creates a new scheduled thread pool of a given size with the given name, or returns an
existing thread pool if one was already created with the same name.
|
Timer |
newTimer(Class<?> klass,
String name)
Creates a new
Timer and registers it under the given class and name, measuring
elapsed time in milliseconds and invocations per second. |
Timer |
newTimer(Class<?> klass,
String name,
String scope)
Creates a new
Timer and registers it under the given class, name, and scope,
measuring elapsed time in milliseconds and invocations per second. |
Timer |
newTimer(Class<?> klass,
String name,
String scope,
TimeUnit durationUnit,
TimeUnit rateUnit)
Creates a new
Timer and registers it under the given class, name, and scope. |
Timer |
newTimer(Class<?> klass,
String name,
TimeUnit durationUnit,
TimeUnit rateUnit)
Creates a new
Timer and registers it under the given class and name. |
Timer |
newTimer(MetricName metricName,
TimeUnit durationUnit,
TimeUnit rateUnit)
Creates a new
Timer 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.
|
void |
shutdown()
Shut down this registry's thread pools.
|
public MetricsRegistry()
MetricsRegistry
.public MetricsRegistry(Clock clock)
MetricsRegistry
with the given Clock
instance.clock
- a Clock
instancepublic <T> Gauge<T> newGauge(Class<?> klass, String name, Gauge<T> metric)
Gauge
, registers it under the given class and name.T
- the type of the value returned by the metricklass
- the class which owns the metricname
- the name of the metricmetric
- the metricmetric
public <T> Gauge<T> newGauge(Class<?> klass, String name, String scope, Gauge<T> metric)
Gauge
, registers it under the given class and name.T
- the type of the value returned by the metricklass
- the class which owns the metricname
- the name of the metricscope
- the scope of the metricmetric
- the metricmetric
public <T> Gauge<T> newGauge(MetricName metricName, Gauge<T> metric)
Gauge
, registers it under the given metric name.T
- the type of the value returned by the metricmetricName
- the name of the metricmetric
- the metricmetric
public Counter newCounter(Class<?> klass, String name)
Counter
and registers it under the given class and name.klass
- the class which owns the metricname
- the name of the metricCounter
public Counter newCounter(Class<?> klass, String name, String scope)
Counter
and registers it under the given class and name.klass
- the class which owns the metricname
- the name of the metricscope
- the scope of the metricCounter
public Counter newCounter(MetricName metricName)
Counter
and registers it under the given metric name.metricName
- the name of the metricCounter
public Histogram newHistogram(Class<?> klass, String name, boolean biased)
Histogram
and registers it under the given class and name.klass
- the class which owns the metricname
- the name of the metricbiased
- whether or not the histogram should be biasedHistogram
public Histogram newHistogram(Class<?> klass, String name, String scope, boolean biased)
Histogram
and registers it under the given class, name, and scope.klass
- the class which owns the metricname
- the name of the metricscope
- the scope of the metricbiased
- whether or not the histogram should be biasedHistogram
public Histogram newHistogram(Class<?> klass, String name)
Histogram
and registers it under the given class and name.klass
- the class which owns the metricname
- the name of the metricHistogram
public Histogram newHistogram(Class<?> klass, String name, String scope)
Histogram
and registers it under the given class, name, and
scope.klass
- the class which owns the metricname
- the name of the metricscope
- the scope of the metricHistogram
public Histogram newHistogram(MetricName metricName, boolean biased)
Histogram
and registers it under the given metric name.metricName
- the name of the metricbiased
- whether or not the histogram should be biasedHistogram
public Meter newMeter(Class<?> klass, String name, String eventType, TimeUnit unit)
Meter
and registers it under the given class and name.klass
- the class which owns the metricname
- the name of the metriceventType
- the plural name of the type of events the meter is measuring (e.g., "requests"
)unit
- the rate unit of the new meterMeter
public Meter newMeter(Class<?> klass, String name, String scope, String eventType, TimeUnit unit)
Meter
and registers it under the given class, name, and scope.klass
- the class which owns the metricname
- the name of the metricscope
- the scope of the metriceventType
- the plural name of the type of events the meter is measuring (e.g., "requests"
)unit
- the rate unit of the new meterMeter
public Meter newMeter(MetricName metricName, String eventType, TimeUnit unit)
Meter
and registers it under the given metric name.metricName
- the name of the metriceventType
- the plural name of the type of events the meter is measuring (e.g., "requests"
)unit
- the rate unit of the new meterMeter
public Timer newTimer(Class<?> klass, String name)
Timer
and registers it under the given class and name, measuring
elapsed time in milliseconds and invocations per second.klass
- the class which owns the metricname
- the name of the metricTimer
public Timer newTimer(Class<?> klass, String name, TimeUnit durationUnit, TimeUnit rateUnit)
Timer
and registers it under the given class and name.klass
- the class which owns the metricname
- the name of the metricdurationUnit
- the duration scale unit of the new timerrateUnit
- the rate scale unit of the new timerTimer
public Timer newTimer(Class<?> klass, String name, String scope)
Timer
and registers it under the given class, name, and scope,
measuring elapsed time in milliseconds and invocations per second.klass
- the class which owns the metricname
- the name of the metricscope
- the scope of the metricTimer
public Timer newTimer(Class<?> klass, String name, String scope, TimeUnit durationUnit, TimeUnit rateUnit)
Timer
and registers it under the given class, name, and scope.klass
- the class which owns the metricname
- the name of the metricscope
- the scope of the metricdurationUnit
- the duration scale unit of the new timerrateUnit
- the rate scale unit of the new timerTimer
public Timer newTimer(MetricName metricName, TimeUnit durationUnit, TimeUnit rateUnit)
Timer
and registers it under the given metric name.metricName
- the name of the metricdurationUnit
- the duration scale unit of the new timerrateUnit
- the rate scale unit of the new timerTimer
public Map<MetricName,Metric> allMetrics()
public SortedMap<String,SortedMap<MetricName,Metric>> groupedMetrics()
public SortedMap<String,SortedMap<MetricName,Metric>> groupedMetrics(MetricPredicate predicate)
MetricPredicate
.predicate
- a predicate which metrics have to match to be in the resultspredicate
, sorted by namepublic void shutdown()
public ScheduledExecutorService newScheduledThreadPool(int poolSize, String name)
poolSize
- the number of threads to createname
- the name of the poolScheduledExecutorService
public void removeMetric(Class<?> klass, String name)
klass
- the klass the metric is associated withname
- the name of the metricpublic void removeMetric(Class<?> klass, String name, String scope)
klass
- the klass the metric is associated withname
- the name of the metricscope
- the scope of the metricpublic void removeMetric(MetricName name)
name
- the name of the metricpublic void addListener(MetricsRegistryListener listener)
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.listener
- the listener that will be notifiedpublic void removeListener(MetricsRegistryListener listener)
MetricsRegistryListener
from this registry's collection of listeners.listener
- the listener that will be removedprotected MetricName createName(Class<?> klass, String name, String scope)
MetricName
s are created.klass
- the class which owns the metricname
- the name of the metricscope
- the metric's scopeprotected ConcurrentMap<MetricName,Metric> newMetricsMap()
ConcurrentMap
implementation. Subclass this to do weird things with
your own MetricsRegistry
implementation.ConcurrentMap
protected final <T extends Metric> T getOrAdd(MetricName name, T metric)
T
- the type of the metricname
- the metric's namemetric
- the new metricmetric
Copyright © 2014. All Rights Reserved.