full metrics name not know until timer is stopped

42 views
Skip to first unread message

Jan-Olav Eide

unread,
Nov 20, 2015, 1:26:39 PM11/20/15
to metrics-user
The metrics name is provided when a timer in started, however, I would like to add to that name some values that are only known when the timer is stopped. Is this possible ?

Ryan Rupp

unread,
Nov 20, 2015, 7:17:31 PM11/20/15
to metrics-user
You would have to do the timing piece manually but you can use the update method on the timer here - https://github.com/dropwizard/metrics/blob/master/metrics-core/src/main/java/io/dropwizard/metrics/Timer.java#L94 - so basically you could:

1) Start your timing manually e.g. long startTime = System.nanoTime();
2) End your timing manually, get the time difference. 
3) Now that you have your dynamic key at this point, get or create the timer from the Metric registry using that e.g. registry.timer(dynamicName)
4) Call timer.update with your time.

Jan-Olav Eide

unread,
Nov 21, 2015, 8:56:21 AM11/21/15
to metrics-user
Yes of course, thanks. It had overlooked that update call
Reply all
Reply to author
Forward
0 new messages