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);
}
});
}
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();
}
}
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() {
}));
}
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));
}
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));
}
Aggregations