11

I am using codahale metrics (now dropwizard metrics) to monitor a few 'events' happening in my system. I am using the counters metrics to keep track of number of time the 'event' happened.

I checked the values printed by the reporter for my counter metrics and it seems like the value keeps on increasing (and never goes down). This seems logical as I am always using metrics.inc() function whenever my 'event' occurs.

What I really want is to get count of my 'event' happening between two reporting times, for this I need to reset my counter every time I report my metrics, but I couldn't find any option in counter metrics to do that. Is there a way or general practice followed by codahale users to produce such metrics?

Current Behavior (reporting time 10 sec):

00:00:00 0
00:00:10 2 // event happened twice
00:00:20 2 // event did not occur
00:00:30 5 // event occured three times`

Expected metrics:

00:00:00 0
00:00:10 2
00:00:20 0
00:00:30 3
face
  • 1,503
  • 13
  • 27

2 Answers2

1

To sum up or calculate count(total) per arbitrary interval:

hitcount(perSecond(your.count), '1day')

Afaik it does all the black magic inside. Including but not limited to summarize(scaleToSeconds(nonNegativeDerivative(your.count),1), '1day') and also there should be scaling according to carbon's retention periods (one or many) that fall into chosen aggregation interval.

Sasha
  • 1,393
  • 16
  • 17
  • 1
    Could you explain what this syntax is? Were you using pseudo code? How would I actually incorporate your answer here into my code? – Scott G Nov 13 '20 at 16:34
  • 1
    @scottg489 this syntax is for graphite query functions, for example hitcount: https://graphite.readthedocs.io/en/stable/functions.html#graphite.render.functions.hitcount. So it would need to collect/report metrics to underlying graphite service and then you coud query it this way – Sasha Nov 16 '20 at 14:28
  • 1
    @scottg489 but these days I'd recommend using Prometheus as a metrics server rather than Graphite. – Sasha Nov 16 '20 at 17:41
0

I believe that counter is not correct metrics for your case. Consider using meter that will provide you rate per time interval:

while(...) {
    int stuffProcesssed = doStuff();
    meter.mark(stuffProcesssed);
}
Dmitry Erokhin
  • 863
  • 1
  • 7
  • 14
  • While mark.meter gives you recent minutes rates and overal rate (or from app start) afaik there is no ability to choose arbitrary interval. – Sasha Nov 23 '16 at 15:25