Search code examples
clojureriemann

Count riemann events in given time window


In riemann config for specific service I'm trying to assign to all its events metric=1, sum them within 5sec and send the result to influxdb.

I tried the following:

(streams
  (where (service "offers")
    (fixed-time-window 5
      (smap folds/sum (with :metric 1 index))))
  influx)

It doesn't really work, events stored in influx do not match this rule.


Solution

  • The built in folds/count function does this:

    (fixed-time-window 5
      (smap folds/count influx))            
    

    also the call to influx needs to be a child of the stream that does the counting so it's the counts that get indexed.

    If you want to fix your example using folds/sum you could move the call to (with :metric 1) outside, or upstream of, the call to sum so the metrics are set to one and then the new metrics are summed in the call to folds/sum. Then put the call to index and or influx as the child stream of smap so the summed items get indexed and forwarded.