Counter for last 60 minutes only

80 views
Skip to first unread message

gg

unread,
May 24, 2016, 5:15:04 PM5/24/16
to metrics-user
I want to use the counter metrics in my code but I would like to only store and display the counts for last 60 minutes only. Is it possible to do this using the Counter metric or some other metric?

Thanks,
gg

Ben Tatham

unread,
Jun 15, 2016, 12:37:12 PM6/15/16
to metrics-user
Definitely not with Counter - that is just a continuous counter, with no record of times.  You would have to use a Reservoir of some sort (like in a Histogram), which I suspect would be way too much memory usage to get a full hour of counts, assuming your count gets ticked a lot.

Marshall Pierce

unread,
Jun 15, 2016, 11:11:52 PM6/15/16
to metric...@googlegroups.com
If you can live with 1-minute granularity, just create 60 LongAdders and use a different one each minute (zeroing and re-using as appropriate). Expose the sum as a Gauge<Long>.
> --
> You received this message because you are subscribed to the Google Groups "metrics-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to metrics-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Vladimir Bukhtoyarov

unread,
Oct 14, 2016, 3:16:51 AM10/14/16
to metrics-user
Try to use SmoothlyDecayingRollingCounter. In general it works as described by Marshall Pierce, but do zeroing of obsolete chunks a little bit better(smoothly).

<dependency>
    <groupId>com.github.metrics-core-addons</groupId>
    <artifactId>metrics-core-hdr</artifactId>
    <version>1.4.0</version>
</dependency>

// constructs the counter which divided by 10 chunks with 60 seconds time window.
WindowCounter counter = new SmoothlyDecayingRollingCounter(Duration.ofSeconds(60), 10);
registry.register("my-counter", new MetricsCounter(counter));

// ...
counter.add(42);



среда, 25 мая 2016 г., 0:15:04 UTC+3 пользователь gg написал:
Reply all
Reply to author
Forward
0 new messages