Permalink
Browse files

Enable customized metric names in MetricsRegistry.

Closes #107 and #46.
  • Loading branch information...
1 parent a26daad commit 90871c05f69562a08bcc616f492a6de43dd5971c @chids committed with codahale Sep 15, 2011
@@ -47,7 +47,7 @@
String name,
String scope,
GaugeMetric<T> metric) {
- return newGauge(new MetricName(klass, name, scope), metric);
+ return newGauge(createName(klass, name, scope), metric);
}
/**
@@ -99,7 +99,7 @@ public JmxGauge newJmxGauge(Class<?> klass,
String scope,
String objectName,
String attribute) throws MalformedObjectNameException {
- return newJmxGauge(new MetricName(klass, name, scope), objectName, attribute);
+ return newJmxGauge(createName(klass, name, scope), objectName, attribute);
}
/**
@@ -143,7 +143,7 @@ public CounterMetric newCounter(Class<?> klass,
public CounterMetric newCounter(Class<?> klass,
String name,
String scope) {
- return newCounter(new MetricName(klass, name, scope));
+ return newCounter(createName(klass, name, scope));
}
/**
@@ -186,7 +186,7 @@ public HistogramMetric newHistogram(Class<?> klass,
String name,
String scope,
boolean biased) {
- return newHistogram(new MetricName(klass, name, scope), biased);
+ return newHistogram(createName(klass, name, scope), biased);
}
/**
@@ -266,7 +266,7 @@ public MeterMetric newMeter(Class<?> klass,
String scope,
String eventType,
TimeUnit unit) {
- return newMeter(new MetricName(klass, name, scope), eventType, unit);
+ return newMeter(createName(klass, name, scope), eventType, unit);
}
/**
@@ -356,7 +356,7 @@ public TimerMetric newTimer(Class<?> klass,
String scope,
TimeUnit durationUnit,
TimeUnit rateUnit) {
- return newTimer(new MetricName(klass, name, scope), durationUnit, rateUnit);
+ return newTimer(createName(klass, name, scope), durationUnit, rateUnit);
}
/**
@@ -383,6 +383,20 @@ public TimerMetric newTimer(MetricName metricName,
}
return (TimerMetric) existingMetric;
}
+
+ /**
+ * Override to customize how {@link MetricName}s are created.
+ *
+ * @param klass
+ * @param name
+ * @param scope
+ * @return
+ */
+ public MetricName createName(Class<?> klass, String name, String scope)
+ {
+ return new MetricName(klass, name, scope);
+ }
+
/**
* Returns an unmodifiable map of all metrics and their names.
*
@@ -418,9 +432,10 @@ public void removeMetric(Class<?> klass,
* @param name the name of the metric
* @param scope the scope of the metric
*/
- public void removeMetric(Class<?> klass, String name,
+ public void removeMetric(Class<?> klass,
+ String name,
String scope) {
- removeMetric(new MetricName(klass, name, scope));
+ removeMetric(createName(klass, name, scope));
}
/**
@@ -20,7 +20,7 @@
public class InstrumentationModule extends AbstractModule {
@Override
protected void configure() {
- MetricsRegistry metricsRegistry = new MetricsRegistry();
+ MetricsRegistry metricsRegistry = createRegistry();
bind(MetricsRegistry.class).toInstance(metricsRegistry);
bind(HealthCheckRegistry.class).asEagerSingleton();
bind(JmxReporter.class).toProvider(JmxReporterProvider.class).asEagerSingleton();
@@ -29,4 +29,14 @@ protected void configure() {
bindListener(Matchers.any(), new GaugeListener(metricsRegistry));
bindListener(Matchers.any(), new ExceptionMeteredListener(metricsRegistry));
}
+
+ /**
+ * Override to provide a custom {@link MetricsRegistry}
+ *
+ * @return
+ */
+ protected MetricsRegistry createRegistry()
+ {
+ return new MetricsRegistry();
+ }
}

0 comments on commit 90871c0

Please sign in to comment.