Search in sources :

Example 46 with Metric

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() {
    }));
}
Also used : MetricFilter(com.kixeye.chassis.support.metrics.MetricFilter) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Example 47 with 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() {
    }));
}
Also used : MetricFilter(com.kixeye.chassis.support.metrics.MetricFilter) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

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

Example 49 with Metric

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);
    }
}
Also used : Counter(com.codahale.metrics.Counter) Random(java.util.Random) Metric(com.codahale.metrics.Metric) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 50 with Metric

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

Aggregations

Metric (com.codahale.metrics.Metric)59 Test (org.junit.Test)27 MetricRegistry (com.codahale.metrics.MetricRegistry)17 Map (java.util.Map)16 HashMap (java.util.HashMap)15 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