Here’s a quick tutorial on how to implement counter metrics from codahale that resets after being reported.
Register a gauge that increments a Counter and returns the current value while decrementing that value from the existing counter. This operation is thread safe.
1 2 3 4 5 6 7 8 9
Note: You will have to make sure this is only registered once in your application lifecycle as repeated calls for the same gauge name will result in an Exception being thrown.
Step 2 (Optional)
You can also prevent the actual Counter metric from being reported as well, so as to not clutter up your metrics view by adding a filter.
1 2 3 4 5 6