public interface MetricCollector
MonitoringCenter with methods for collecting
metrics under a particular namespace. MetricCollector is analogous to a logger retrieved from SLF4J's LoggerFactory.
As such, a typical idiom for instantiating a MetricCollector is:
private static final MetricCollector metricCollector = MonitoringCenter.getMetricCollector(SampleService.class);
In addition to the ability to instantiate or retrieve Dropwizard's Metric implementations (e.g.,
Counter), this interface exposes high-level methods for registering and instrumenting collections, maps, caches,
executors, and data sources. The instrumentation methods return a proxy instance that has to be employed in lieu
of the original instance.
All metrics registered within a MetricCollector are prefixed with its namespace (defined when retrieving a
MetricCollector instance from MonitoringCenter; see MonitoringCenter.getMetricCollector(String, String...)).
A MetricCollector also enforces a metric naming policy specified in the MonitoringCenter's configuration
(see MetricNamePostfixPolicy). Thus, a histogram named "foo" may be
registered as "fooHistogram", given an appropriate MetricNamePostfixPolicy (e.g.,
MetricNamePostfixPolicy.ADD_COMPOSITE_TYPES).
In other words, all metrics registered with a MetricCollector will follow the naming schema below:
[MetricCollector's namespace].[name].[additionalNames][postfix as dictated by the MetricNamePostfixPolicy]
,
where "." is the separator character expressed by
MetricNamingUtil.SEPARATOR.
For instance, getMeter("requests", "errors", "400") registered with a MetricCollector named
"SampleServlet" and given
MetricNamePostfixPolicy.ADD_COMPOSITE_TYPES, will yield a meter
named "SampleServlet.requests.errors.400Meter".
Note that the node-specific prefix (such as "bidder.east.lb10-p2e.114") is appended on demand during the reporting stage.
MetricCollector abstracts away all the naming intricacies mentioned above, allowing the client to simply reference a metric by its short name ("coins" vs "SampleService.coinsMeter").
| Modifier and Type | Method and Description |
|---|---|
com.codahale.metrics.Counter |
getCounter(String topLevelName,
String... additionalNames)
Retrieves a counter, creating it if one does not exist.
|
com.codahale.metrics.Histogram |
getHistogram(String topLevelName,
String... additionalNames)
Retrieves a histogram, creating it if one does not exist.
|
com.codahale.metrics.Meter |
getMeter(String topLevelName,
String... additionalNames)
Retrieves a meter, creating it if one does not exist.
|
com.codahale.metrics.Timer |
getTimer(String topLevelName,
String... additionalNames)
Retrieves a timer, creating it if one does not exist.
|
<T> BlockingQueue<T> |
instrumentBlockingQueue(BlockingQueue<T> blockingQueue,
String topLevelName,
String... additionalNames)
Instruments a
BlockingQueue. |
DataSource |
instrumentDataSource(DataSource dataSource,
String topLevelName,
String... additionalNames)
Instruments a
DataSource, exposing the distribution of connection acquisition times. |
ExecutorService |
instrumentExecutorService(ExecutorService executorService,
String topLevelName,
String... additionalNames)
Instruments an
ExecutorService. |
ScheduledExecutorService |
instrumentScheduledExecutorService(ScheduledExecutorService scheduledExecutorService,
String topLevelName,
String... additionalNames)
Instruments a
ScheduledExecutorService. |
void |
registerC3P0DataSource(com.mchange.v2.c3p0.PooledDataSource pooledDataSource,
String topLevelName,
String... additionalNames)
Registers a C3P0 pool with the MetricCollector, exposing as gauges its various data points for connections,
threads, and statement cache.
|
void |
registerCollection(Collection<?> collection,
String topLevelName,
String... additionalNames)
Registers a
Collection with the MetricCollector, exposing its size as a gauge. |
<T> void |
registerGauge(com.codahale.metrics.Gauge<T> gauge,
String topLevelName,
String... additionalNames)
Registers a gauge.
|
void |
registerGuavaCache(com.google.common.cache.Cache<?,?> cache,
String topLevelName,
String... additionalNames)
Registers a Guava Cache with the MetricCollector, exposing its size and stats as gauges.
|
void |
registerMap(Map<?,?> map,
String topLevelName,
String... additionalNames)
Registers a
Map with the MetricCollector, exposing its size as a gauge. |
void |
registerMetric(com.codahale.metrics.Metric metric,
String topLevelName,
String... additionalNames)
Registers a metric.
|
void |
registerMetricSet(com.codahale.metrics.MetricSet metricSet,
String... names)
Registers all metrics contained in a MetricSet.
|
void |
removeAll()
Removes all metrics registered within this MetricCollector.
|
void |
removeMetric(com.codahale.metrics.Metric metric,
String topLevelName,
String... additionalNames)
Removes a metric from the MetricCollector, voiding its registration with the MonitoringCenter.
|
void |
removeMetricSet(com.codahale.metrics.MetricSet metricSet,
String... names)
Removes a metric set, effectively removing all metrics contained in it.
|
void |
replaceMetric(com.codahale.metrics.Metric metric,
String topLevelName,
String... additionalNames)
Replaces an existing metric with a new metric under the same name.
|
com.codahale.metrics.Counter getCounter(String topLevelName, String... additionalNames)
MetricNamePostfixPolicy configured in the MonitoringCenter.
MetricNamingUtil.join(String, String...).topLevelName - top-level part of the counter's name.additionalNames - additional parts of the counter's name.IllegalArgumentException - if top-level part of the name is blank.com.codahale.metrics.Timer getTimer(String topLevelName, String... additionalNames)
MetricNamePostfixPolicy configured in the MonitoringCenter.
MetricNamingUtil.join(String, String...).topLevelName - top-level part of the timer's name.additionalNames - additional parts of the timer's name.IllegalArgumentException - if top-level part of the name is blank.com.codahale.metrics.Meter getMeter(String topLevelName, String... additionalNames)
MetricNamePostfixPolicy configured in the MonitoringCenter.
MetricNamingUtil.join(String, String...).topLevelName - top-level part of the meter's name.additionalNames - additional parts of the meter's name.IllegalArgumentException - if top-level part of the name is blank.com.codahale.metrics.Histogram getHistogram(String topLevelName, String... additionalNames)
MetricNamePostfixPolicy configured in the MonitoringCenter.
MetricNamingUtil.join(String, String...).topLevelName - top-level part of the histogram's name.additionalNames - additional parts of the histogram's name.IllegalArgumentException - if top-level part of the name is blank.<T> void registerGauge(com.codahale.metrics.Gauge<T> gauge,
String topLevelName,
String... additionalNames)
MetricNamePostfixPolicy configured in the MonitoringCenter.
MetricNamingUtil.join(String, String...).T - type of the value returned by the gauge.gauge - a gauge to register.topLevelName - top-level part of the gauge's name.additionalNames - additional parts of the gauge's name.NullPointerException - if gauge is null.IllegalArgumentException - if top-level part of the name is blank.IllegalArgumentException - if a gauge with the same name has already been registered.void registerMetric(com.codahale.metrics.Metric metric,
String topLevelName,
String... additionalNames)
MetricNamePostfixPolicy configured in the MonitoringCenter.
MetricNamingUtil.join(String, String...).metric - a metric to register.topLevelName - top-level part of the metric's name.additionalNames - additional parts of the metric's name.NullPointerException - if metric is null.IllegalArgumentException - if top-level part of the name is blank.IllegalArgumentException - if a metric with the same name has already been registered.void registerMetricSet(com.codahale.metrics.MetricSet metricSet,
String... names)
registerMetric(Metric, String, String...)).
If a name is specified for the MetricSet, it will be employed as a namespace for all individual metrics
registered as a result of this method. Thus, the actual name of the individual metrics registered with the
MonitoringCenter will be prefixed with MetricCollector's namespace, MetricSet's namespace, and then, possibly,
postfixed with the type of the metric (e.g., Counter). The postfix enforcement is controlled by the
MetricNamePostfixPolicy configured in the MonitoringCenter.
MetricNamingUtil.join(String, String...).metricSet - a metric set to register.names - optional name parts that form the namespace for metrics in the metric set.NullPointerException - if metricSet is null.void removeAll()
void removeMetric(com.codahale.metrics.Metric metric,
String topLevelName,
String... additionalNames)
registerMetric(Metric, String, String...).metric - a metric to remove.topLevelName - top-level part of the metric's name.additionalNames - additional parts of the metric's name.NullPointerException - if metric is null.IllegalArgumentException - if top-level part of the name is blank.void removeMetricSet(com.codahale.metrics.MetricSet metricSet,
String... names)
registerMetricSet(MetricSet, String...).metricSet - a metric set to remove.names - optional name parts that form the namespace for metrics in the metric set.NullPointerException - if metricSet is null.void replaceMetric(com.codahale.metrics.Metric metric,
String topLevelName,
String... additionalNames)
metric - a metric to replace the existing metric with.topLevelName - top-level part of the metric's name.additionalNames - additional parts of the metric's name.NullPointerException - if metric is null.IllegalArgumentException - if top-level part of the name is blank.registerMetric(Metric, String, String...),
removeMetric(Metric, String, String...)void registerCollection(Collection<?> collection, String topLevelName, String... additionalNames)
Collection with the MetricCollector, exposing its size as a gauge.collection - a collection to register.topLevelName - top-level part of the collection's name.additionalNames - additional parts of the collection's name.NullPointerException - if collection is null.IllegalArgumentException - if top-level part of the name is blank.void registerMap(Map<?,?> map, String topLevelName, String... additionalNames)
Map with the MetricCollector, exposing its size as a gauge.map - a map to register.topLevelName - top-level part of the map's name.additionalNames - additional parts of the map's name.NullPointerException - if map is null.IllegalArgumentException - if top-level part of the name is blank.void registerGuavaCache(com.google.common.cache.Cache<?,?> cache,
String topLevelName,
String... additionalNames)
cache - a cache to register.topLevelName - top-level part of the cache's name.additionalNames - additional parts of the cache's name.NullPointerException - if cache is null.IllegalArgumentException - if top-level part of the name is blank.Cache.stats()void registerC3P0DataSource(com.mchange.v2.c3p0.PooledDataSource pooledDataSource,
String topLevelName,
String... additionalNames)
pooledDataSource - a C3P0 data source to register.topLevelName - top-level part of the data source's name.additionalNames - additional parts of the data source's name.NullPointerException - if pooledDataSource is null.IllegalArgumentException - if top-level part of the name is blank.<T> BlockingQueue<T> instrumentBlockingQueue(BlockingQueue<T> blockingQueue, String topLevelName, String... additionalNames)
BlockingQueue. This method registers the blocking queue with the MetricCollector, exposing
its size and capacity as gauges.T - type of the elements of the blocking queue.blockingQueue - a blocking queue to instrument.topLevelName - top-level part of the blocking queue's name.additionalNames - additional parts of the blocking queue's name.NullPointerException - if blockingQueue is null.IllegalArgumentException - if top-level part of the name is blank.ExecutorService instrumentExecutorService(ExecutorService executorService, String topLevelName, String... additionalNames)
ExecutorService. This method creates a proxy of a given executor service, exposing its
various statistics under this MetricCollector.executorService - an executor service to instrument.topLevelName - top-level part of the executor service's name.additionalNames - additional parts of the executor service's name.NullPointerException - if executorService is null.IllegalArgumentException - if top-level part of the name is blank.ScheduledExecutorService instrumentScheduledExecutorService(ScheduledExecutorService scheduledExecutorService, String topLevelName, String... additionalNames)
ScheduledExecutorService. This method creates a proxy of a given scheduled executor
service, exposing its various statistics under this MetricCollector.scheduledExecutorService - a scheduled executor service to instrument.topLevelName - top-level part of the scheduled executor service's name.additionalNames - additional parts of the scheduled executor service's name.NullPointerException - if scheduledExecutorService is null.IllegalArgumentException - if top-level part of the name is blank.DataSource instrumentDataSource(DataSource dataSource, String topLevelName, String... additionalNames)
DataSource, exposing the distribution of connection acquisition times.dataSource - a data source to instrument.topLevelName - top-level part of the data source's name.additionalNames - additional parts of the data source's name.NullPointerException - if dataSource is null.IllegalArgumentException - if top-level part of the name is blank.Copyright © 2016–2018. All rights reserved.