Skip to content

Instantly share code, notes, and snippets.

@danostrowski
Created October 9, 2012 20:58
Show Gist options
  • Save danostrowski/3861381 to your computer and use it in GitHub Desktop.
Save danostrowski/3861381 to your computer and use it in GitHub Desktop.
Quick attempt at sum-for-x-events in Riemann
(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