Search in sources :

Example 61 with Counter

use of com.codahale.metrics.Counter in project metrics by dropwizard.

the class MetricsModuleTest method serializesCounters.

@Test
public void serializesCounters() throws Exception {
    final Counter counter = mock(Counter.class);
    when(counter.getCount()).thenReturn(100L);
    assertThat(mapper.writeValueAsString(counter)).isEqualTo("{\"count\":100}");
}
Also used : Counter(com.codahale.metrics.Counter) Test(org.junit.Test)

Example 62 with Counter

use of com.codahale.metrics.Counter in project metrics by dropwizard.

the class CollectdReporterTest method reportsCounters.

@Test
public void reportsCounters() throws Exception {
    Counter counter = mock(Counter.class);
    when(counter.getCount()).thenReturn(42L);
    reporter.report(map(), map("api.rest.requests.count", counter), map(), map(), map());
    ValueList data = receiver.next();
    assertThat(data.getValues()).containsExactly(42d);
}
Also used : Counter(com.codahale.metrics.Counter) ValueList(org.collectd.api.ValueList) Test(org.junit.Test)

Example 63 with Counter

use of com.codahale.metrics.Counter in project hive by apache.

the class Metrics method getOrCreateCounter.

/**
 * Get an existing counter or create a new one if the requested one does not yet exist.  Creation
 * is synchronized to assure that only one instance of the counter is created.
 * @param name name of the counter
 * @return new Counter, or existing one if it already exists.  This will return null if the
 * metrics have not been initialized.
 */
public static Counter getOrCreateCounter(String name) {
    if (self == null)
        return null;
    Map<String, Counter> counters = self.registry.getCounters();
    Counter counter = counters.get(name);
    if (counter != null)
        return counter;
    // Looks like it doesn't exist.  Lock so that two threads don't create it at once.
    synchronized (Metrics.class) {
        // Recheck to make sure someone didn't create it while we waited.
        counters = self.registry.getCounters();
        counter = counters.get(name);
        if (counter != null)
            return counter;
        return self.registry.counter(name);
    }
}
Also used : Counter(com.codahale.metrics.Counter)

Example 64 with Counter

use of com.codahale.metrics.Counter in project hive by apache.

the class TestMetrics method jsonReporter.

@Test
public void jsonReporter() throws Exception {
    File jsonReportFile = File.createTempFile("TestMetrics", ".json");
    String jsonFile = jsonReportFile.getAbsolutePath();
    Configuration conf = MetastoreConf.newMetastoreConf();
    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_REPORTERS, "json");
    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_LOCATION, jsonFile);
    MetastoreConf.setTimeVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_INTERVAL, REPORT_INTERVAL, TimeUnit.SECONDS);
    Metrics.initialize(conf);
    Counter counter = Metrics.getOrCreateCounter("my-counter");
    for (int i = 0; i < 5; i++) {
        counter.inc();
        // Make sure it has a chance to dump it.
        Thread.sleep(REPORT_INTERVAL * 1000 + REPORT_INTERVAL * 1000 / 2);
        String json = new String(MetricsTestUtils.getFileData(jsonFile, 200, 10));
        MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "my-counter", i + 1);
    }
}
Also used : Counter(com.codahale.metrics.Counter) Configuration(org.apache.hadoop.conf.Configuration) File(java.io.File) Test(org.junit.Test) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)

Example 65 with Counter

use of com.codahale.metrics.Counter in project janusgraph by JanusGraph.

the class JanusGraphOperationCountingTest method resetEdgeCacheCounts.

private void resetEdgeCacheCounts() {
    Counter counter = metric.getCounter(metricsPrefix, EDGESTORE_NAME + METRICS_CACHE_SUFFIX, CacheMetricsAction.RETRIEVAL.getName());
    counter.dec(counter.getCount());
    counter = metric.getCounter(metricsPrefix, EDGESTORE_NAME + METRICS_CACHE_SUFFIX, CacheMetricsAction.MISS.getName());
    counter.dec(counter.getCount());
}
Also used : Counter(com.codahale.metrics.Counter)

Aggregations

Counter (com.codahale.metrics.Counter)66 Test (org.junit.Test)31 Map (java.util.Map)15 MetricRegistry (com.codahale.metrics.MetricRegistry)14 Timer (com.codahale.metrics.Timer)14 Histogram (com.codahale.metrics.Histogram)11 HashMap (java.util.HashMap)11 Gauge (com.codahale.metrics.Gauge)10 Meter (com.codahale.metrics.Meter)9 Metric (com.codahale.metrics.Metric)9 Random (java.util.Random)8 SolrInfoBean (org.apache.solr.core.SolrInfoBean)6 SortedMap (java.util.SortedMap)5 IOException (java.io.IOException)4 TreeMap (java.util.TreeMap)4 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Description (com.google.gerrit.metrics.Description)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3