use of com.codahale.metrics.Timer in project hive by apache.
the class CodahaleMetrics method getTimer.
// This method is necessary to synchronize lazy-creation to the timers.
private Timer getTimer(String name) {
String key = name;
try {
timersLock.lock();
Timer timer = timers.get(key);
return timer;
} catch (ExecutionException e) {
throw new IllegalStateException("Error retrieving timer " + name + " from the metric registry ", e);
} finally {
timersLock.unlock();
}
}
use of com.codahale.metrics.Timer in project metrics by dropwizard.
the class InstrumentedTimingCollectorTest method updatesTimerForTemplateFile.
@Test
public void updatesTimerForTemplateFile() throws Exception {
final StatementNameStrategy strategy = new SmartNameStrategy();
final InstrumentedTimingCollector collector = new InstrumentedTimingCollector(registry, strategy);
final StatementContext ctx = mock(StatementContext.class);
doReturn("SELECT 1").when(ctx).getRawSql();
doReturn("foo/bar.stg").when(ctx).getAttribute(NameStrategies.STATEMENT_GROUP);
doReturn("updatesTimerForTemplateFile").when(ctx).getAttribute(NameStrategies.STATEMENT_NAME);
collector.collect(TimeUnit.SECONDS.toNanos(4), ctx);
final String name = strategy.getStatementName(ctx);
final Timer timer = registry.timer(name);
assertThat(name).isEqualTo(name("foo", "bar", "updatesTimerForTemplateFile"));
assertThat(timer.getSnapshot().getMax()).isEqualTo(4000000000L);
}
use of com.codahale.metrics.Timer in project metrics by dropwizard.
the class SingletonMetricsJerseyTest method subresourcesFromLocatorsRegisterMetrics.
@Test
public void subresourcesFromLocatorsRegisterMetrics() {
assertThat(target("subresource/timed").request().get(String.class)).isEqualTo("yay");
final Timer timer = registry.timer(name(InstrumentedSubResource.class, "timed"));
assertThat(timer.getCount()).isEqualTo(1);
}
use of com.codahale.metrics.Timer in project metrics by dropwizard.
the class SingletonMetricsTimedPerClassJerseyTest method timedPerClassMethodsAreTimed.
@Test
public void timedPerClassMethodsAreTimed() {
assertThat(target("timedPerClass").request().get(String.class)).isEqualTo("yay");
final Timer timer = registry.timer(name(InstrumentedResourceTimedPerClass.class, "timedPerClass"));
assertThat(timer.getCount()).isEqualTo(1);
}
use of com.codahale.metrics.Timer in project metrics by dropwizard.
the class InstrumentedTimingCollector method collect.
@Override
public void collect(long elapsedTime, StatementContext ctx) {
final Timer timer = getTimer(ctx);
timer.update(elapsedTime, TimeUnit.NANOSECONDS);
}
Aggregations