use of com.codahale.metrics.Metric in project chassis by Kixeye.
the class MetricFilterTest method patternMatchSingleMetric.
@Test
public void patternMatchSingleMetric() {
MetricFilter filter = new MetricFilter("MyMetric=com.[a-zA-Z0-9]*.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 exactMatchMultipleMetrics.
@Test
public void exactMatchMultipleMetrics() {
MetricFilter filter = new MetricFilter("MyMetric1=com.kixeye.MyMetric1,MyMetric2=com.kixeye.MyMetric2");
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() {
}));
}
use of com.codahale.metrics.Metric in project alluxio by Alluxio.
the class WebInterfaceWorkerMetricsServlet method populateValues.
/**
* Populates key, value pairs for UI display.
*
* @param request The {@link HttpServletRequest} object
* @throws IOException if an I/O error occurs
*/
private void populateValues(HttpServletRequest request) throws IOException {
MetricRegistry mr = MetricsSystem.METRIC_REGISTRY;
Long workerCapacityTotal = (Long) mr.getGauges().get(MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.CAPACITY_TOTAL)).getValue();
Long workerCapacityUsed = (Long) mr.getGauges().get(MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.CAPACITY_USED)).getValue();
int workerCapacityUsedPercentage = (workerCapacityTotal > 0) ? (int) (100L * workerCapacityUsed / workerCapacityTotal) : 0;
request.setAttribute("workerCapacityUsedPercentage", workerCapacityUsedPercentage);
request.setAttribute("workerCapacityFreePercentage", 100 - workerCapacityUsedPercentage);
Map<String, Counter> counters = mr.getCounters(new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return !(name.endsWith("Ops"));
}
});
Map<String, Counter> rpcInvocations = mr.getCounters(new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return name.endsWith("Ops");
}
});
Map<String, Metric> operations = new TreeMap<>();
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
operations.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), entry.getValue());
}
String blockCachedProperty = MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.BLOCKS_CACHED);
operations.put(MetricsSystem.stripInstanceAndHost(blockCachedProperty), mr.getGauges().get(blockCachedProperty));
Map<String, Counter> rpcInvocationsUpdated = new TreeMap<>();
for (Map.Entry<String, Counter> entry : rpcInvocations.entrySet()) {
rpcInvocationsUpdated.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), entry.getValue());
}
populateCounterValues(operations, rpcInvocationsUpdated, request);
}
use of com.codahale.metrics.Metric in project lucene-solr by apache.
the class SolrMetricManagerTest method testSwapRegistries.
@Test
public void testSwapRegistries() throws Exception {
Random r = random();
SolrMetricManager metricManager = new SolrMetricManager();
Map<String, Counter> metrics1 = SolrMetricTestUtils.getRandomMetrics(r, true);
Map<String, Counter> metrics2 = SolrMetricTestUtils.getRandomMetrics(r, true);
String fromName = "from-" + TestUtil.randomSimpleString(r, 1, 10);
String toName = "to-" + TestUtil.randomSimpleString(r, 1, 10);
// register test metrics
for (Map.Entry<String, Counter> entry : metrics1.entrySet()) {
metricManager.register(null, fromName, entry.getValue(), false, entry.getKey(), "metrics1");
}
for (Map.Entry<String, Counter> entry : metrics2.entrySet()) {
metricManager.register(null, toName, entry.getValue(), false, entry.getKey(), "metrics2");
}
assertEquals(metrics1.size(), metricManager.registry(fromName).getMetrics().size());
assertEquals(metrics2.size(), metricManager.registry(toName).getMetrics().size());
// swap
metricManager.swapRegistries(fromName, toName);
// check metrics
Map<String, Metric> fromMetrics = metricManager.registry(fromName).getMetrics();
assertEquals(metrics2.size(), fromMetrics.size());
for (Map.Entry<String, Counter> entry : metrics2.entrySet()) {
Object value = fromMetrics.get(SolrMetricManager.mkName(entry.getKey(), "metrics2"));
assertNotNull(value);
assertEquals(entry.getValue(), value);
}
Map<String, Metric> toMetrics = metricManager.registry(toName).getMetrics();
assertEquals(metrics1.size(), toMetrics.size());
for (Map.Entry<String, Counter> entry : metrics1.entrySet()) {
Object value = toMetrics.get(SolrMetricManager.mkName(entry.getKey(), "metrics1"));
assertNotNull(value);
assertEquals(entry.getValue(), value);
}
}
use of com.codahale.metrics.Metric in project lucene-solr by apache.
the class MockMetricReporter method reportMetric.
public Metric reportMetric(String metricName) throws NoSuchElementException {
MetricRegistry registry = metricManager.registry(registryName);
Metric metric = registry.getMetrics().get(metricName);
if (metric == null) {
throw new NoSuchElementException("Metric was not found for metric name = " + metricName);
}
return metric;
}
Aggregations