Graphite Tip - Counting Number of Metrics Reported

2013-05-27 13:59:50 by jdixon

There's been many a time when I've asked the question "I wonder how many hosts are sending this metric?" Unfortunately there's no built-in Graphite function for determining the number of hosts submitting a particular metric (or tree of metrics). But this morning I stumbled across a brilliant hack of a Graphite query by Jesse Newland (@jnewland) for rendering this value.

Jesse realized that we could count them simply by converting each value to 1 and then adding them up. We make this happen by first applying scale(0) to the series and then incrementing each by one with offset(1). Lastly we use sumSeries() to render our final tally.


And here is the resulting graph:


at 2013-05-27 15:59:00, Matt wrote in to say...

awesome! I have been trying to find a way to do this exact calculation in Graphite!

at 2013-05-27 16:09:53, Jilles Oldenbeuving wrote in to say...

And with a bit more fiddling, I'm sure you could group this by server pool (frontends, backends, etc)!

at 2014-01-23 19:58:05, Eugen wrote in to say...


at 2014-05-26 09:35:06, d_s wrote in to say...

Why not just countSeries(currentAbove(collectd.cdn.*.*.*.load.load.midterm,0)) ? It seems more logical for me.

at 2014-06-09 23:39:27, Jason Dixon wrote in to say...

@d_s - Because at the time of the writing countSeries() wasn't in an official release yet.

at 2015-04-15 11:06:04, zeridon wrote in to say...

Unfortunately countSeries takes into account all series that have data during the whole time frame you have selected. E.g. if you have 6 boxes at the start of the period but 4 at the end it will say there are 6 series.

This is of course valid but kind-of defeats the purpose of the graphs. This trick is much nicer.

Also it is good to add keepLastValue (for some reasonable period) to cover intermitent data senders.

at 2017-01-26 08:28:34, Dave Holland wrote in to say...

Brilliant trick. Thanks!

Add a comment:




max length 4000 chars