Created
October 9, 2012 20:58
-
-
Save danostrowski/3861381 to your computer and use it in GitHub Desktop.
Quick attempt at sum-for-x-events in Riemann
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sum-for-count | |
"Emit the sum of the last n events." | |
[n & children] | |
(let [window (ref (vec (repeat n 0)))] | |
(fn [event] | |
; here we guard against putting nils in our vector which doesn't work with (reduce + ... ) | |
(if (and (contains? event :metric) | |
(not (nil? (:metric event)))) | |
(do | |
(dosync (alter window pop) | |
(ref-set window (into [(:metric event)] @window))) | |
(call-rescue | |
(assoc event :description (str "Sum of last " n " events.") :metric (reduce + @window) :service (str (:service event) " sum")) | |
children)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment