timing single ocurence events (and reporting them)

43 views
Skip to first unread message

Bernd Eckenfels

unread,
Mar 18, 2015, 4:38:11 PM3/18/15
to metric...@googlegroups.com
Hello,

I have (in addition to regular event timers which are handled quite nicely with metrics) the need to also stop-watch the startup time of my server. It would be nice to have that one metric reported with the usual reporters, but it seems none of them are particular well suited for a single ocurence event?  I guess with a special oneshot reservoir it would be possible? Can this add another property to existing reporters (lastValue or sumValue).

I could of course set a gauge with the measured time (Timer.Context would return the duration) or use a traditional StopWatch class, but it feels like it would be better suited in the Timer?

    void main(args) {
        Context startupTime = metrics.timer(MetricRegistry.name(WebServer.class, "startup-time")).time();
        ...
        startupTime.stop();
        // wait for shutdown
        ...
    }

Gruss
Bernd

Matt Nelson

unread,
May 28, 2015, 4:41:11 PM5/28/15
to metric...@googlegroups.com
You could use a Counter and time the block of code manually then increment the counter by the time it took. This would avoid all the extras that come with Timer.
Reply all
Reply to author
Forward
0 new messages