Package com.codahale.metrics
Class NoopMetricRegistry
- java.lang.Object
-
- com.codahale.metrics.MetricRegistry
-
- com.codahale.metrics.NoopMetricRegistry
-
public final class NoopMetricRegistry extends MetricRegistry
A registry of metric instances which never creates or registers any metrics and returns no-op implementations of any metric type.- Since:
- 4.1.17
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.codahale.metrics.MetricRegistry
MetricRegistry.MetricSupplier<T extends Metric>
-
-
Constructor Summary
Constructors Constructor Description NoopMetricRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(MetricRegistryListener listener)Adds aMetricRegistryListenerto a collection of listeners that will be notified on metric creation.protected ConcurrentMap<String,Metric>buildMap()Creates a newConcurrentMapimplementation for use inside the registry.Countercounter(String name)Countercounter(String name, MetricRegistry.MetricSupplier<Counter> supplier)<T extends Gauge>
Tgauge(String name)Return theGaugeregistered under this name; or create and register a newSettableGaugeif none is registered.<T extends Gauge>
Tgauge(String name, MetricRegistry.MetricSupplier<T> supplier)SortedMap<String,Counter>getCounters()Returns a map of all the counters in the registry and their names.SortedMap<String,Counter>getCounters(MetricFilter filter)Returns a map of all the counters in the registry and their names which match the given filter.SortedMap<String,Gauge>getGauges()Returns a map of all the gauges in the registry and their names.SortedMap<String,Gauge>getGauges(MetricFilter filter)Returns a map of all the gauges in the registry and their names which match the given filter.SortedMap<String,Histogram>getHistograms()Returns a map of all the histograms in the registry and their names.SortedMap<String,Histogram>getHistograms(MetricFilter filter)Returns a map of all the histograms in the registry and their names which match the given filter.SortedMap<String,Meter>getMeters()Returns a map of all the meters in the registry and their names.SortedMap<String,Meter>getMeters(MetricFilter filter)Returns a map of all the meters in the registry and their names which match the given filter.Map<String,Metric>getMetrics()A map of metric names to metrics.SortedSet<String>getNames()Returns a set of the names of all the metrics in the registry.SortedMap<String,Timer>getTimers()Returns a map of all the timers in the registry and their names.SortedMap<String,Timer>getTimers(MetricFilter filter)Returns a map of all the timers in the registry and their names which match the given filter.Histogramhistogram(String name)Histogramhistogram(String name, MetricRegistry.MetricSupplier<Histogram> supplier)Metermeter(String name)Metermeter(String name, MetricRegistry.MetricSupplier<Meter> supplier)<T extends Metric>
Tregister(String name, T metric)Given aMetric, registers it under the given name.voidregisterAll(MetricSet metrics)Given a metric set, registers them.voidregisterAll(String prefix, MetricSet metrics)Given a metric set, registers them with the given prefix prepended to their names.booleanremove(String name)Removes the metric with the given name.voidremoveListener(MetricRegistryListener listener)Removes aMetricRegistryListenerfrom this registry's collection of listeners.voidremoveMatching(MetricFilter filter)Removes all metrics which match the given filter.Timertimer(String name)Timertimer(String name, MetricRegistry.MetricSupplier<Timer> supplier)-
Methods inherited from class com.codahale.metrics.MetricRegistry
name, name, registerGauge
-
-
-
-
Method Detail
-
buildMap
protected ConcurrentMap<String,Metric> buildMap()
Creates a newConcurrentMapimplementation for use inside the registry. Override this to create aMetricRegistrywith space- or time-bounded metric lifecycles, for example.- Overrides:
buildMapin classMetricRegistry- Returns:
- a new
ConcurrentMap
-
register
public <T extends Metric> T register(String name, T metric) throws IllegalArgumentException
Given aMetric, registers it under the given name.- Overrides:
registerin classMetricRegistry- Type Parameters:
T- the type of the metric- Parameters:
name- the name of the metricmetric- the metric- Returns:
metric- Throws:
IllegalArgumentException- if the name is already registered or metric variable is null
-
registerAll
public void registerAll(MetricSet metrics) throws IllegalArgumentException
Given a metric set, registers them.- Overrides:
registerAllin classMetricRegistry- Parameters:
metrics- a set of metrics- Throws:
IllegalArgumentException- if any of the names are already registered
-
counter
public Counter counter(String name)
Return theCounterregistered under this name; or create and register a newCounterif none is registered.- Overrides:
counterin classMetricRegistry- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Counter
-
counter
public Counter counter(String name, MetricRegistry.MetricSupplier<Counter> supplier)
Return theCounterregistered under this name; or create and register a newCounterusing the provided MetricSupplier if none is registered.- Overrides:
counterin classMetricRegistry- Parameters:
name- the name of the metricsupplier- a MetricSupplier that can be used to manufacture a counter.- Returns:
- a new or pre-existing
Counter
-
histogram
public Histogram histogram(String name)
Return theHistogramregistered under this name; or create and register a newHistogramif none is registered.- Overrides:
histogramin classMetricRegistry- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Histogram
-
histogram
public Histogram histogram(String name, MetricRegistry.MetricSupplier<Histogram> supplier)
Return theHistogramregistered under this name; or create and register a newHistogramusing the provided MetricSupplier if none is registered.- Overrides:
histogramin classMetricRegistry- Parameters:
name- the name of the metricsupplier- a MetricSupplier that can be used to manufacture a histogram- Returns:
- a new or pre-existing
Histogram
-
meter
public Meter meter(String name)
Return theMeterregistered under this name; or create and register a newMeterif none is registered.- Overrides:
meterin classMetricRegistry- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Meter
-
meter
public Meter meter(String name, MetricRegistry.MetricSupplier<Meter> supplier)
Return theMeterregistered under this name; or create and register a newMeterusing the provided MetricSupplier if none is registered.- Overrides:
meterin classMetricRegistry- Parameters:
name- the name of the metricsupplier- a MetricSupplier that can be used to manufacture a Meter- Returns:
- a new or pre-existing
Meter
-
timer
public Timer timer(String name)
Return theTimerregistered under this name; or create and register a newTimerif none is registered.- Overrides:
timerin classMetricRegistry- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Timer
-
timer
public Timer timer(String name, MetricRegistry.MetricSupplier<Timer> supplier)
Return theTimerregistered under this name; or create and register a newTimerusing the provided MetricSupplier if none is registered.- Overrides:
timerin classMetricRegistry- Parameters:
name- the name of the metricsupplier- a MetricSupplier that can be used to manufacture a Timer- Returns:
- a new or pre-existing
Timer
-
gauge
public <T extends Gauge> T gauge(String name)
Return theGaugeregistered under this name; or create and register a newSettableGaugeif none is registered.- Overrides:
gaugein classMetricRegistry- Parameters:
name- the name of the metric- Returns:
- a pre-existing
Gaugeor a newSettableGauge - Since:
- 4.2
-
gauge
public <T extends Gauge> T gauge(String name, MetricRegistry.MetricSupplier<T> supplier)
Return theGaugeregistered under this name; or create and register a newGaugeusing the provided MetricSupplier if none is registered.- Overrides:
gaugein classMetricRegistry- Parameters:
name- the name of the metricsupplier- a MetricSupplier that can be used to manufacture a Gauge- Returns:
- a new or pre-existing
Gauge
-
remove
public boolean remove(String name)
Removes the metric with the given name.- Overrides:
removein classMetricRegistry- Parameters:
name- the name of the metric- Returns:
- whether or not the metric was removed
-
removeMatching
public void removeMatching(MetricFilter filter)
Removes all metrics which match the given filter.- Overrides:
removeMatchingin classMetricRegistry- Parameters:
filter- a filter
-
addListener
public void addListener(MetricRegistryListener listener)
Adds aMetricRegistryListenerto 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.
- Overrides:
addListenerin classMetricRegistry- Parameters:
listener- the listener that will be notified
-
removeListener
public void removeListener(MetricRegistryListener listener)
Removes aMetricRegistryListenerfrom this registry's collection of listeners.- Overrides:
removeListenerin classMetricRegistry- Parameters:
listener- the listener that will be removed
-
getNames
public SortedSet<String> getNames()
Returns a set of the names of all the metrics in the registry.- Overrides:
getNamesin classMetricRegistry- Returns:
- the names of all the metrics
-
getGauges
public SortedMap<String,Gauge> getGauges()
Returns a map of all the gauges in the registry and their names.- Overrides:
getGaugesin classMetricRegistry- Returns:
- all the gauges in the registry
-
getGauges
public SortedMap<String,Gauge> getGauges(MetricFilter filter)
Returns a map of all the gauges in the registry and their names which match the given filter.- Overrides:
getGaugesin classMetricRegistry- Parameters:
filter- the metric filter to match- Returns:
- all the gauges in the registry
-
getCounters
public SortedMap<String,Counter> getCounters()
Returns a map of all the counters in the registry and their names.- Overrides:
getCountersin classMetricRegistry- Returns:
- all the counters in the registry
-
getCounters
public SortedMap<String,Counter> getCounters(MetricFilter filter)
Returns a map of all the counters in the registry and their names which match the given filter.- Overrides:
getCountersin classMetricRegistry- Parameters:
filter- the metric filter to match- Returns:
- all the counters in the registry
-
getHistograms
public SortedMap<String,Histogram> getHistograms()
Returns a map of all the histograms in the registry and their names.- Overrides:
getHistogramsin classMetricRegistry- Returns:
- all the histograms in the registry
-
getHistograms
public SortedMap<String,Histogram> getHistograms(MetricFilter filter)
Returns a map of all the histograms in the registry and their names which match the given filter.- Overrides:
getHistogramsin classMetricRegistry- Parameters:
filter- the metric filter to match- Returns:
- all the histograms in the registry
-
getMeters
public SortedMap<String,Meter> getMeters()
Returns a map of all the meters in the registry and their names.- Overrides:
getMetersin classMetricRegistry- Returns:
- all the meters in the registry
-
getMeters
public SortedMap<String,Meter> getMeters(MetricFilter filter)
Returns a map of all the meters in the registry and their names which match the given filter.- Overrides:
getMetersin classMetricRegistry- Parameters:
filter- the metric filter to match- Returns:
- all the meters in the registry
-
getTimers
public SortedMap<String,Timer> getTimers()
Returns a map of all the timers in the registry and their names.- Overrides:
getTimersin classMetricRegistry- Returns:
- all the timers in the registry
-
getTimers
public SortedMap<String,Timer> getTimers(MetricFilter filter)
Returns a map of all the timers in the registry and their names which match the given filter.- Overrides:
getTimersin classMetricRegistry- Parameters:
filter- the metric filter to match- Returns:
- all the timers in the registry
-
registerAll
public void registerAll(String prefix, MetricSet metrics) throws IllegalArgumentException
Given a metric set, registers them with the given prefix prepended to their names.- Overrides:
registerAllin classMetricRegistry- Parameters:
prefix- a name prefixmetrics- a set of metrics- Throws:
IllegalArgumentException- if any of the names are already registered
-
getMetrics
public Map<String,Metric> getMetrics()
A map of metric names to metrics.- Specified by:
getMetricsin interfaceMetricSet- Overrides:
getMetricsin classMetricRegistry- Returns:
- the metrics
-
-