Skip to content

Instantly share code, notes, and snippets.

@ezbz
Created June 12, 2012 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezbz/2919431 to your computer and use it in GitHub Desktop.
Save ezbz/2919431 to your computer and use it in GitHub Desktop.
Creating a timer in code
// inject this
private final MetricFactory metricFactory;
public MyBean(final MetricFactory metricFactory) {
this.metricFactory = metricFactory;
}
// Use the factory to create metrics objects like Timer or Counter:
final Timer timer = metricFactory.createTimer(componentName, methodName);
final TimerContext timerContext = timer.time();
try{
// do some stuff
finally {
timerContext.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment