Class MetricRegistry
java.lang.Object
com.codahale.metrics.MetricRegistry
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceMetricRegistry.MetricBuilder<T extends Metric>A quick and easy way of capturing the notion of default metrics. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<MetricRegistryListener> private final ConcurrentMap<String, Metric> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(MetricRegistryListener listener) Adds aMetricRegistryListenerto a collection of listeners that will be notified on metric creation.private static voidappend(StringBuilder builder, String part) protected ConcurrentMap<String, Metric> buildMap()Creates a newConcurrentMapimplementation for use inside the registry.Creates a newCounterand registers it under the given name.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.Returns a map of all the gauges in the registry and their names.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.getMetrics(Class<T> klass, MetricFilter filter) getNames()Returns a set of the names of all the metrics in the registry.private <T extends Metric>
TgetOrAdd(String name, MetricRegistry.MetricBuilder<T> builder) 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.Creates a newHistogramand registers it under the given name.Creates a newMeterand registers it under the given name.static StringConcatenates a class name and elements to form a dotted name, eliding any null values or empty strings.static StringConcatenates elements to form a dotted name, eliding any null values or empty strings.private voidnotifyListenerOfAddedMetric(MetricRegistryListener listener, Metric metric, String name) private voidnotifyListenerOfRemovedMetric(String name, Metric metric, MetricRegistryListener listener) private voidonMetricAdded(String name, Metric metric) private voidonMetricRemoved(String name, Metric metric) <T extends Metric>
TGiven aMetric, registers it under the given name.voidregisterAll(MetricSet metrics) Given a metric set, registers them.private voidregisterAll(String prefix, MetricSet metrics) booleanRemoves 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.Creates a newTimerand registers it under the given name.
-
Field Details
-
metrics
-
listeners
-
-
Constructor Details
-
MetricRegistry
public MetricRegistry()Creates a newMetricRegistry.
-
-
Method Details
-
name
-
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:
klassandnamesconcatenated by periods
-
append
-
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
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
-
registerAll
Given a metric set, registers them.- Parameters:
metrics- a set of metrics- Throws:
IllegalArgumentException- if any of the names are already registered
-
counter
-
histogram
-
meter
-
timer
-
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 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
Removes aMetricRegistryListenerfrom this registry's collection of listeners.- Parameters:
listener- the listener that will be removed
-
getNames
-
getGauges
-
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
-
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
-
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
-
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
-
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
-
getOrAdd
-
getMetrics
-
onMetricAdded
-
notifyListenerOfAddedMetric
private void notifyListenerOfAddedMetric(MetricRegistryListener listener, Metric metric, String name) -
onMetricRemoved
-
notifyListenerOfRemovedMetric
private void notifyListenerOfRemovedMetric(String name, Metric metric, MetricRegistryListener listener) -
registerAll
- Throws:
IllegalArgumentException
-
getMetrics
-