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