Created
October 9, 2012 20:59
-
-
Save danostrowski/3861390 to your computer and use it in GitHub Desktop.
A quick Riemann stream to emit an event when X events are zero
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 zero-for-count | |
"A sliding window of the last n events, emitting an event when all are zero." | |
[n & children] | |
(let [window (ref (vec (repeat n nil)))] | |
(fn [event] | |
(dosync (alter window pop) | |
(ref-set window (into [(:metric event)] @window))) | |
(when (every? (fnil zero? 1) @window) | |
(call-rescue | |
(assoc event :description (str "Last " n " metrics have been zero!") :state "warning") | |
children))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment