Package io.dropwizard.metrics5
Class MetricRegistry
- java.lang.Object
-
- io.dropwizard.metrics5.MetricRegistry
-
- Direct Known Subclasses:
NoopMetricRegistry
public class MetricRegistry extends Object implements MetricSet
A registry of metric instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMetricRegistry.MetricSupplier<T extends Metric>
-
Constructor Summary
Constructors Constructor Description MetricRegistry()Creates a newMetricRegistry.
-
Method Summary
All Methods Static 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<MetricName,Metric>buildMap()Creates a newConcurrentMapimplementation for use inside the registry.Countercounter(MetricName name)<T extends Counter>
Tcounter(MetricName name, MetricRegistry.MetricSupplier<T> supplier)Countercounter(String name)<T extends Gauge>
Tgauge(MetricName name)Return theGaugeregistered under this name; or create and register a newSettableGaugeif none is registered.<T extends Gauge>
Tgauge(MetricName name, MetricRegistry.MetricSupplier<T> supplier)SortedMap<MetricName,Counter>getCounters()Returns a map of all the counters in the registry and their names.SortedMap<MetricName,Counter>getCounters(MetricFilter filter)Returns a map of all the counters in the registry and their names which match the given filter.SortedMap<MetricName,Gauge<?>>getGauges()Returns a map of all the gauges in the registry and their names.SortedMap<MetricName,Gauge<?>>getGauges(MetricFilter filter)Returns a map of all the gauges in the registry and their names which match the given filter.SortedMap<MetricName,Histogram>getHistograms()Returns a map of all the histograms in the registry and their names.SortedMap<MetricName,Histogram>getHistograms(MetricFilter filter)Returns a map of all the histograms in the registry and their names which match the given filter.SortedMap<MetricName,Meter>getMeters()Returns a map of all the meters in the registry and their names.SortedMap<MetricName,Meter>getMeters(MetricFilter filter)Returns a map of all the meters in the registry and their names which match the given filter.Map<MetricName,Metric>getMetrics()A map of metric names to metrics.SortedSet<MetricName>getNames()Returns a set of the names of all the metrics in the registry.SortedMap<MetricName,Timer>getTimers()Returns a map of all the timers in the registry and their names.SortedMap<MetricName,Timer>getTimers(MetricFilter filter)Returns a map of all the timers in the registry and their names which match the given filter.Histogramhistogram(MetricName name)Histogramhistogram(MetricName name, MetricRegistry.MetricSupplier<Histogram> supplier)Histogramhistogram(String name)Metermeter(MetricName name)Metermeter(MetricName name, MetricRegistry.MetricSupplier<Meter> supplier)Metermeter(String name)static MetricNamename(Class<?> klass, String... names)Concatenates a class name and elements to form a dotted name, eliding any null values or empty strings.static MetricNamename(String name, String... names)Concatenates elements to form a dotted name, eliding any null values or empty strings.<T extends Metric>
Tregister(MetricName name, T metric)Given aMetric, registers it under the given name.<T extends Metric>
Tregister(String name, T metric)voidregisterAll(MetricName prefix, MetricSet metrics)voidregisterAll(MetricSet metrics)Given a metric set, registers them.booleanremove(MetricName 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(MetricName name)Timertimer(MetricName name, MetricRegistry.MetricSupplier<Timer> supplier)Timertimer(String name)
-
-
-
Constructor Detail
-
MetricRegistry
public MetricRegistry()
Creates a newMetricRegistry.
-
-
Method Detail
-
name
public static MetricName name(String name, String... names)
Concatenates elements to form a dotted name, eliding any null values or empty strings.- Parameters:
name- the first element of the namenames- the remaining elements of the name- Returns:
nameandnamesconcatenated by periods
-
name
public static MetricName name(Class<?> klass, String... names)
Concatenates a class name and elements to form a dotted name, eliding any null values or empty strings.- Parameters:
klass- the first element of the namenames- the remaining elements of the name- Returns:
klassandnamesconcatenated by periods
-
buildMap
protected ConcurrentMap<MetricName,Metric> buildMap()
Creates a newConcurrentMapimplementation for use inside the registry. Override this to create aMetricRegistrywith space- or time-bounded metric lifecycles, for example.- Returns:
- a new
ConcurrentMap
-
register
public <T extends Metric> T register(String name, T metric) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
register
public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException
Given aMetric, registers it under the given name.- 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.- Parameters:
metrics- a set of metrics- Throws:
IllegalArgumentException- if any of the names are already registered
-
counter
public Counter counter(MetricName name)
Return theCounterregistered under this name; or create and register a newCounterif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Counter
-
counter
public <T extends Counter> T counter(MetricName name, MetricRegistry.MetricSupplier<T> supplier)
Return theCounterregistered under this name; or create and register a newCounterusing the provided MetricSupplier if none is registered.- 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(MetricName name)
Return theHistogramregistered under this name; or create and register a newHistogramif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Histogram
-
histogram
public Histogram histogram(MetricName name, MetricRegistry.MetricSupplier<Histogram> supplier)
Return theHistogramregistered under this name; or create and register a newHistogramusing the provided MetricSupplier if none is registered.- 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(MetricName name)
Return theMeterregistered under this name; or create and register a newMeterif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Meter
-
meter
public Meter meter(MetricName name, MetricRegistry.MetricSupplier<Meter> supplier)
Return theMeterregistered under this name; or create and register a newMeterusing the provided MetricSupplier if none is registered.- 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(MetricName name)
Return theTimerregistered under this name; or create and register a newTimerif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Timer
-
timer
public Timer timer(MetricName name, MetricRegistry.MetricSupplier<Timer> supplier)
Return theTimerregistered under this name; or create and register a newTimerusing the provided MetricSupplier if none is registered.- 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(MetricName name)
Return theGaugeregistered under this name; or create and register a newSettableGaugeif none is registered.- Parameters:
name- the name of the metric- Returns:
- a pre-existing
Gaugeor a newSettableGauge - Since:
- 4.2
-
gauge
public <T extends Gauge> T gauge(MetricName name, MetricRegistry.MetricSupplier<T> supplier)
Return theGaugeregistered under this name; or create and register a newGaugeusing the provided MetricSupplier if none is registered.- 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(MetricName name)
Removes the metric with the given name.- 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.- 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.
- Parameters:
listener- the listener that will be notified
-
removeListener
public void removeListener(MetricRegistryListener listener)
Removes aMetricRegistryListenerfrom this registry's collection of listeners.- Parameters:
listener- the listener that will be removed
-
getNames
public SortedSet<MetricName> getNames()
Returns a set of the names of all the metrics in the registry.- Returns:
- the names of all the metrics
-
getGauges
public SortedMap<MetricName,Gauge<?>> getGauges()
Returns a map of all the gauges in the registry and their names.- Returns:
- all the gauges in the registry
-
getGauges
public SortedMap<MetricName,Gauge<?>> getGauges(MetricFilter filter)
Returns a map of all the gauges in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the gauges in the registry
-
getCounters
public SortedMap<MetricName,Counter> getCounters()
Returns a map of all the counters in the registry and their names.- Returns:
- all the counters in the registry
-
getCounters
public SortedMap<MetricName,Counter> getCounters(MetricFilter filter)
Returns a map of all the counters in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the counters in the registry
-
getHistograms
public SortedMap<MetricName,Histogram> getHistograms()
Returns a map of all the histograms in the registry and their names.- Returns:
- all the histograms in the registry
-
getHistograms
public SortedMap<MetricName,Histogram> getHistograms(MetricFilter filter)
Returns a map of all the histograms in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the histograms in the registry
-
getMeters
public SortedMap<MetricName,Meter> getMeters()
Returns a map of all the meters in the registry and their names.- Returns:
- all the meters in the registry
-
getMeters
public SortedMap<MetricName,Meter> getMeters(MetricFilter filter)
Returns a map of all the meters in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the meters in the registry
-
getTimers
public SortedMap<MetricName,Timer> getTimers()
Returns a map of all the timers in the registry and their names.- Returns:
- all the timers in the registry
-
getTimers
public SortedMap<MetricName,Timer> getTimers(MetricFilter filter)
Returns a map of all the timers in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the timers in the registry
-
registerAll
public void registerAll(MetricName prefix, MetricSet metrics) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
getMetrics
public Map<MetricName,Metric> getMetrics()
Description copied from interface:MetricSetA map of metric names to metrics.- Specified by:
getMetricsin interfaceMetricSet- Returns:
- the metrics
-
-