use of com.codahale.metrics.MetricFilter in project metrics by dropwizard.
the class MetricsServlet method setupMetricsModule.
protected void setupMetricsModule(ServletContext context) {
final TimeUnit rateUnit = parseTimeUnit(context.getInitParameter(RATE_UNIT), TimeUnit.SECONDS);
final TimeUnit durationUnit = parseTimeUnit(context.getInitParameter(DURATION_UNIT), TimeUnit.SECONDS);
final boolean showSamples = Boolean.parseBoolean(context.getInitParameter(SHOW_SAMPLES));
MetricFilter filter = (MetricFilter) context.getAttribute(METRIC_FILTER);
if (filter == null) {
filter = MetricFilter.ALL;
}
this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, showSamples, filter));
}
use of com.codahale.metrics.MetricFilter in project openscoring by openscoring.
the class MetricResource method doMetrics.
private MetricRegistry doMetrics(final String prefix) {
MetricRegistry result = new MetricRegistry();
MetricFilter filter = new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return name.startsWith(prefix);
}
};
Map<String, Metric> metrics = this.metricRegistry.getMetrics();
Collection<Map.Entry<String, Metric>> entries = metrics.entrySet();
for (Map.Entry<String, Metric> entry : entries) {
String name = entry.getKey();
Metric metric = entry.getValue();
if (!filter.matches(name, metric)) {
continue;
}
// Strip prefix
name = name.substring(prefix.length());
result.register(name, metric);
}
return result;
}
use of com.codahale.metrics.MetricFilter in project instrumentation-java by census-instrumentation.
the class DropWizardMetricsTest method filter_GetMetrics.
@Test
public void filter_GetMetrics() {
MetricFilter filter = new MetricFilter() {
@Override
public boolean matches(String name, com.codahale.metrics.Metric metric) {
return name.startsWith("test");
}
};
dropWizardMetrics = new DropWizardMetrics(Collections.singletonList(metricRegistry), filter);
metricRegistry.timer("test_requests");
metricRegistry.timer("requests");
Collection<Metric> metrics = dropWizardMetrics.getMetrics();
assertThat(metrics).hasSize(1);
Metric value = metrics.iterator().next();
assertThat(value.getMetricDescriptor().getName()).isEqualTo("codahale_test_requests_timer");
}
Aggregations