Search in sources :

Example 26 with MetricFilter

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));
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) MetricsModule(com.codahale.metrics.json.MetricsModule) TimeUnit(java.util.concurrent.TimeUnit) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 27 with MetricFilter

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;
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) Map(java.util.Map)

Example 28 with MetricFilter

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");
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Aggregations

MetricFilter (com.codahale.metrics.MetricFilter)28 Metric (com.codahale.metrics.Metric)17 MetricRegistry (com.codahale.metrics.MetricRegistry)12 Counter (com.codahale.metrics.Counter)5 Map (java.util.Map)5 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)5 Gauge (com.codahale.metrics.Gauge)4 Histogram (com.codahale.metrics.Histogram)4 Timer (com.codahale.metrics.Timer)4 Test (org.junit.Test)4 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)3 HashSet (java.util.HashSet)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Meter (com.codahale.metrics.Meter)2 MetricsModule (com.codahale.metrics.json.MetricsModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 MethodHandles (java.lang.invoke.MethodHandles)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2