Search in sources :

Example 6 with Metric

use of com.codahale.metrics.Metric in project opennms by OpenNMS.

the class DispatcherState method close.

@Override
public void close() throws Exception {
    final String prefix = MetricRegistry.name(module.getId());
    metrics.removeMatching(new MetricFilter() {

        @Override
        public boolean matches(String name, Metric metric) {
            return name.startsWith(prefix);
        }
    });
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) Metric(com.codahale.metrics.Metric)

Example 7 with Metric

use of com.codahale.metrics.Metric in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandlerTest method getMetrics.

@Test
public void getMetrics() {
    final int FILES_PINNED_TEST_VALUE = 100;
    String filesPinnedProperty = MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.FILES_PINNED);
    Gauge<Integer> filesPinnedGauge = new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return FILES_PINNED_TEST_VALUE;
        }
    };
    MetricSet mockMetricsSet = mock(MetricSet.class);
    Map<String, Metric> map = new HashMap<>();
    map.put(filesPinnedProperty, filesPinnedGauge);
    when(mockMetricsSet.getMetrics()).thenReturn(map);
    MetricsSystem.METRIC_REGISTRY.registerAll(mockMetricsSet);
    Response response = mHandler.getMetrics();
    try {
        assertNotNull("Response must be not null!", response);
        assertNotNull("Response must have a entry!", response.getEntity());
        assertTrue("Entry must be a SortedMap!", (response.getEntity() instanceof SortedMap));
        SortedMap<String, Long> metricsMap = (SortedMap<String, Long>) response.getEntity();
        assertFalse("Metrics Map must be not empty!", (metricsMap.isEmpty()));
        assertTrue("Map must contain key " + filesPinnedProperty + "!", metricsMap.containsKey(filesPinnedProperty));
        assertEquals(FILES_PINNED_TEST_VALUE, metricsMap.get(filesPinnedProperty).longValue());
    } finally {
        response.close();
    }
}
Also used : HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Gauge(com.codahale.metrics.Gauge) MetricSet(com.codahale.metrics.MetricSet) Response(javax.ws.rs.core.Response) SortedMap(java.util.SortedMap) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Example 8 with Metric

use of com.codahale.metrics.Metric in project chassis by Kixeye.

the class MetricFilterTest method exactMatchSingleMetric.

@Test
public void exactMatchSingleMetric() {
    MetricFilter filter = new MetricFilter("MyMetric=com.kixeye.MyMetric");
    Assert.assertTrue(filter.matches("com.kixeye.MyMetric", new Metric() {
    }));
}
Also used : MetricFilter(com.kixeye.chassis.support.metrics.MetricFilter) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Example 9 with Metric

use of com.codahale.metrics.Metric in project chassis by Kixeye.

the class MetricFilterTest method multiplePatternMatches.

@Test
public void multiplePatternMatches() {
    MetricFilter filter = new MetricFilter("MyMetric1=com.kixeye.MyMetric[0-9]:5m,MyMetric2=com.[a-zA-Z0-9]*.MyMetric[0-9]:15m");
    Assert.assertTrue(filter.matches("com.kixeye.MyMetric1", new Metric() {
    }));
    Assert.assertTrue(filter.matches("com.foo.MyMetric1", new Metric() {
    }));
    Assert.assertNotNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric1", Stat.RATE_5_MINUTE));
    Assert.assertNotNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric1", Stat.RATE_15_MINUTE));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.foo.MyMetric1", Stat.RATE_5_MINUTE));
    Assert.assertNotNull(filter.getMatchingMetricDescriptor("com.foo.MyMetric1", Stat.RATE_15_MINUTE));
}
Also used : MetricFilter(com.kixeye.chassis.support.metrics.MetricFilter) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Example 10 with Metric

use of com.codahale.metrics.Metric in project chassis by Kixeye.

the class MetricFilterTest method exactMatchMultipleMetricsWithStatsFilter.

@Test
public void exactMatchMultipleMetricsWithStatsFilter() {
    MetricFilter filter = new MetricFilter("MyMetric1=com.kixeye.MyMetric1:5m,MyMetric2=com.kixeye.MyMetric2:5m");
    Assert.assertTrue(filter.matches("com.kixeye.MyMetric1", new Metric() {
    }));
    Assert.assertTrue(filter.matches("com.kixeye.MyMetric2", new Metric() {
    }));
    Assert.assertFalse(filter.matches("com.kixeye.MyMetric3", new Metric() {
    }));
    Assert.assertNotNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric1", Stat.RATE_5_MINUTE));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric1", Stat.RATE_15_MINUTE));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric1", Stat.ALL));
    Assert.assertNotNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric2", Stat.RATE_5_MINUTE));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric2", Stat.RATE_15_MINUTE));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric2", Stat.ALL));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric3", Stat.RATE_5_MINUTE));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric3", Stat.RATE_15_MINUTE));
    Assert.assertNull(filter.getMatchingMetricDescriptor("com.kixeye.MyMetric3", Stat.ALL));
}
Also used : MetricFilter(com.kixeye.chassis.support.metrics.MetricFilter) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Aggregations

Metric (com.codahale.metrics.Metric)58 Test (org.junit.Test)27 MetricRegistry (com.codahale.metrics.MetricRegistry)16 Map (java.util.Map)16 HashMap (java.util.HashMap)13 Counter (com.codahale.metrics.Counter)10 Gauge (com.codahale.metrics.Gauge)10 Timer (com.codahale.metrics.Timer)10 MetricFilter (com.codahale.metrics.MetricFilter)8 MetricFilter (com.kixeye.chassis.support.metrics.MetricFilter)8 Meter (com.codahale.metrics.Meter)7 Histogram (com.codahale.metrics.Histogram)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 List (java.util.List)3 Random (java.util.Random)3 Collectors (java.util.stream.Collectors)3