public class MetricsManager extends java.lang.Object implements MetricsService
private final MetricsManager.MetricsComponent COMPONENT =
MetricsManager.registerComponent("Topology");
private final MetricsManager.MetricsFeature FEATURE =
COMPONENT.registerFeature("Counters");
private final Counter counterTopologyUpdates =
MetricsManager.createCounter(COMPONENT, FEATURE, "TopologyUpdates");
Gauges are slightly different because they are not created directly in
this class, but are allocated by the caller and passed in for registration:
private final Gauge<Long> gauge =
new Gauge<Long>() {
@Override
public Long getValue() {
return gaugeValue;
}
};
MetricsManager.registerMetric(COMPONENT, FEATURE, GAUGE_NAME, gauge);
Constructor and Description |
---|
MetricsManager() |
Modifier and Type | Method and Description |
---|---|
protected void |
clear()
Clears the internal state.
|
com.codahale.metrics.Counter |
createCounter(MetricsComponent component,
MetricsFeature feature,
java.lang.String metricName)
Creates a Counter metric.
|
com.codahale.metrics.Histogram |
createHistogram(MetricsComponent component,
MetricsFeature feature,
java.lang.String metricName)
Creates a Histogram metric.
|
com.codahale.metrics.Meter |
createMeter(MetricsComponent component,
MetricsFeature feature,
java.lang.String metricName)
Creates a Meter metric.
|
com.codahale.metrics.Timer |
createTimer(MetricsComponent component,
MetricsFeature feature,
java.lang.String metricName)
Creates a Timer metric.
|
java.util.Map<java.lang.String,com.codahale.metrics.Counter> |
getCounters(com.codahale.metrics.MetricFilter filter)
Fetches the existing Counters.
|
java.util.Map<java.lang.String,com.codahale.metrics.Gauge> |
getGauges(com.codahale.metrics.MetricFilter filter)
Fetches the existing Gauges.
|
java.util.Map<java.lang.String,com.codahale.metrics.Histogram> |
getHistograms(com.codahale.metrics.MetricFilter filter)
Fetches the existing Histograms.
|
java.util.Map<java.lang.String,com.codahale.metrics.Meter> |
getMeters(com.codahale.metrics.MetricFilter filter)
Fetches the existing Meters.
|
com.codahale.metrics.MetricRegistry |
getMetricRegistry()
Fetches existing metric registry.
|
java.util.Map<java.lang.String,com.codahale.metrics.Metric> |
getMetrics()
Fetches the existing Meters.
|
java.util.Map<java.lang.String,com.codahale.metrics.Timer> |
getTimers(com.codahale.metrics.MetricFilter filter)
Fetches the existing Timers.
|
void |
notifyReporters()
Notifies the changes on metric registry to all registered reporters.
|
MetricsComponent |
registerComponent(java.lang.String name)
Registers a component.
|
<T extends com.codahale.metrics.Metric> |
registerMetric(MetricsComponent component,
MetricsFeature feature,
java.lang.String metricName,
T metric)
Registers an already created Metric.
|
void |
registerReporter(MetricsReporter reporter)
Registers a reporter to receive any changes on metric registry.
|
void |
removeMatching(com.codahale.metrics.MetricFilter filter)
Removes all Metrics that match a given filter.
|
boolean |
removeMetric(MetricsComponent component,
MetricsFeature feature,
java.lang.String metricName)
Removes the metric with the given name.
|
void |
unregisterReporter(MetricsReporter reporter)
Unregisters the given metric reporter.
|
protected void clear()
public MetricsComponent registerComponent(java.lang.String name)
registerComponent
in interface MetricsService
name
- name of the Component to registerpublic com.codahale.metrics.MetricRegistry getMetricRegistry()
getMetricRegistry
in interface MetricsService
public com.codahale.metrics.Counter createCounter(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
createCounter
in interface MetricsService
component
- component the Counter is defined infeature
- feature the Counter is defined inmetricName
- local name of the metricpublic com.codahale.metrics.Histogram createHistogram(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
createHistogram
in interface MetricsService
component
- component the Histogram is defined infeature
- feature the Histogram is defined inmetricName
- local name of the metricpublic com.codahale.metrics.Timer createTimer(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
createTimer
in interface MetricsService
component
- component the Timer is defined infeature
- feature the Timer is defined inmetricName
- local name of the metricpublic com.codahale.metrics.Meter createMeter(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
createMeter
in interface MetricsService
component
- component the Meter is defined infeature
- feature the Meter is defined inmetricName
- local name of the metricpublic <T extends com.codahale.metrics.Metric> T registerMetric(MetricsComponent component, MetricsFeature feature, java.lang.String metricName, T metric)
registerMetric
in interface MetricsService
T
- Metric typecomponent
- component the Metric is defined infeature
- feature the Metric is defined inmetricName
- local name of the metricmetric
- Metric to registerpublic void registerReporter(MetricsReporter reporter)
registerReporter
in interface MetricsService
reporter
- metric reporterpublic void unregisterReporter(MetricsReporter reporter)
unregisterReporter
in interface MetricsService
reporter
- metric reporterpublic void notifyReporters()
notifyReporters
in interface MetricsService
public boolean removeMetric(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
removeMetric
in interface MetricsService
component
- component the Metric is defined infeature
- feature the Metric is defined inmetricName
- local name of the metricpublic java.util.Map<java.lang.String,com.codahale.metrics.Timer> getTimers(com.codahale.metrics.MetricFilter filter)
getTimers
in interface MetricsService
filter
- filter to use to select Timerspublic java.util.Map<java.lang.String,com.codahale.metrics.Gauge> getGauges(com.codahale.metrics.MetricFilter filter)
getGauges
in interface MetricsService
filter
- filter to use to select Gaugespublic java.util.Map<java.lang.String,com.codahale.metrics.Counter> getCounters(com.codahale.metrics.MetricFilter filter)
getCounters
in interface MetricsService
filter
- filter to use to select Counterspublic java.util.Map<java.lang.String,com.codahale.metrics.Meter> getMeters(com.codahale.metrics.MetricFilter filter)
getMeters
in interface MetricsService
filter
- filter to use to select Meterspublic java.util.Map<java.lang.String,com.codahale.metrics.Histogram> getHistograms(com.codahale.metrics.MetricFilter filter)
getHistograms
in interface MetricsService
filter
- filter to use to select Histogramspublic void removeMatching(com.codahale.metrics.MetricFilter filter)
removeMatching
in interface MetricsService
filter
- filter to use to select the Metrics to remove.public java.util.Map<java.lang.String,com.codahale.metrics.Metric> getMetrics()
getMetrics
in interface MetricsService