Package io.dropwizard.metrics5
Class MetricRegistry
java.lang.Object
io.dropwizard.metrics5.MetricRegistry
- Direct Known Subclasses:
NoopMetricRegistry
A registry of metric instances.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
MetricRegistry.MetricSupplier<T extends Metric>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(MetricRegistryListener listener) Adds aMetricRegistryListener
to a collection of listeners that will be notified on metric creation.protected ConcurrentMap<MetricName,
Metric> buildMap()
Creates a newConcurrentMap
implementation for use inside the registry.counter
(MetricName name) <T extends Counter>
Tcounter
(MetricName name, MetricRegistry.MetricSupplier<T> supplier) <T extends Gauge>
Tgauge
(MetricName name) Return theGauge
registered under this name; or create and register a newSettableGauge
if none is registered.<T extends Gauge>
Tgauge
(MetricName name, MetricRegistry.MetricSupplier<T> supplier) Returns a map of all the counters in the registry and their names.getCounters
(MetricFilter filter) Returns a map of all the counters in the registry and their names which match the given filter.SortedMap<MetricName,
Gauge<?>> 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.Returns a map of all the histograms in the registry and their names.getHistograms
(MetricFilter filter) Returns a map of all the histograms in the registry and their names which match the given filter.Returns a map of all the meters in the registry and their names.getMeters
(MetricFilter filter) Returns a map of all the meters in the registry and their names which match the given filter.A map of metric names to metrics.getNames()
Returns a set of the names of all the metrics in the registry.Returns a map of all the timers in the registry and their names.getTimers
(MetricFilter filter) Returns a map of all the timers in the registry and their names which match the given filter.histogram
(MetricName name) histogram
(MetricName name, MetricRegistry.MetricSupplier<Histogram> supplier) meter
(MetricName name) meter
(MetricName name, MetricRegistry.MetricSupplier<Meter> supplier) static MetricName
Concatenates a class name and elements to form a dotted name, eliding any null values or empty strings.static MetricName
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.void
registerAll
(MetricName prefix, MetricSet metrics) void
registerAll
(MetricSet metrics) Given a metric set, registers them.<T> Gauge<T>
registerGauge
(MetricName name, Gauge<T> metric) Given aGauge
, registers it under the given name and returns it<T> Gauge<T>
registerGauge
(String name, Gauge<T> metric) boolean
remove
(MetricName name) Removes the metric with the given name.void
removeListener
(MetricRegistryListener listener) Removes aMetricRegistryListener
from this registry's collection of listeners.void
removeMatching
(MetricFilter filter) Removes all metrics which match the given filter.timer
(MetricName name) timer
(MetricName name, MetricRegistry.MetricSupplier<Timer> supplier)
-
Constructor Details
-
MetricRegistry
public MetricRegistry()Creates a newMetricRegistry
.
-
-
Method Details
-
name
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:
name
andnames
concatenated by periods
-
name
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:
klass
andnames
concatenated by periods
-
buildMap
Creates a newConcurrentMap
implementation for use inside the registry. Override this to create aMetricRegistry
with space- or time-bounded metric lifecycles, for example.- Returns:
- a new
ConcurrentMap
-
registerGauge
- Throws:
IllegalArgumentException
-
registerGauge
Given aGauge
, registers it under the given name and returns it- Type Parameters:
T
- the type of the gauge's value- Parameters:
name
- the name of the gauge- Returns:
- the registered
Gauge
- Throws:
IllegalArgumentException
- Since:
- 4.2.10
-
register
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
Given a metric set, registers them.- Parameters:
metrics
- a set of metrics- Throws:
IllegalArgumentException
- if any of the names are already registered
-
counter
-
counter
Return theCounter
registered under this name; or create and register a newCounter
if none is registered.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Counter
-
histogram
-
counter
Return theCounter
registered under this name; or create and register a newCounter
using 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
Return theHistogram
registered under this name; or create and register a newHistogram
if none is registered.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Histogram
-
meter
-
histogram
Return theHistogram
registered under this name; or create and register a newHistogram
using 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
Return theMeter
registered under this name; or create and register a newMeter
if none is registered.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Meter
-
timer
-
meter
Return theMeter
registered under this name; or create and register a newMeter
using 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
Return theTimer
registered under this name; or create and register a newTimer
if none is registered.- Parameters:
name
- the name of the metric- Returns:
- a new or pre-existing
Timer
-
timer
Return theTimer
registered under this name; or create and register a newTimer
using 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
Return theGauge
registered under this name; or create and register a newSettableGauge
if none is registered.- Parameters:
name
- the name of the metric- Returns:
- a pre-existing
Gauge
or a newSettableGauge
- Since:
- 4.2
-
gauge
Return theGauge
registered under this name; or create and register a newGauge
using 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
Removes the metric with the given name.- Parameters:
name
- the name of the metric- Returns:
- whether or not the metric was removed
-
removeMatching
Removes all metrics which match the given filter.- Parameters:
filter
- a filter
-
addListener
Adds aMetricRegistryListener
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
Removes aMetricRegistryListener
from this registry's collection of listeners.- Parameters:
listener
- the listener that will be removed
-
getNames
Returns a set of the names of all the metrics in the registry.- Returns:
- the names of all the metrics
-
getGauges
Returns a map of all the gauges in the registry and their names.- Returns:
- all the gauges in the registry
-
getGauges
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
Returns a map of all the counters in the registry and their names.- Returns:
- all the counters in the registry
-
getCounters
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
Returns a map of all the histograms in the registry and their names.- Returns:
- all the histograms in the registry
-
getHistograms
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
Returns a map of all the meters in the registry and their names.- Returns:
- all the meters in the registry
-
getMeters
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
Returns a map of all the timers in the registry and their names.- Returns:
- all the timers in the registry
-
getTimers
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
- Throws:
IllegalArgumentException
-
getMetrics
Description copied from interface:MetricSet
A map of metric names to metrics.- Specified by:
getMetrics
in interfaceMetricSet
- Returns:
- the metrics
-