Skip to content

Instantly share code, notes, and snippets.

@maxthoursie
Last active August 29, 2015 14:01
Show Gist options
  • Save maxthoursie/08386518fe411e871837 to your computer and use it in GitHub Desktop.
Save maxthoursie/08386518fe411e871837 to your computer and use it in GitHub Desktop.
(defn trigger-above-cancel-below
"Set state to \"critical\" when metric is > above for trigger_window seconds.
Reset to \"ok\" when metric is < below for cancel-window seconds."
[above trigger-window below cancel-window & children]
(let [changed-stream (changed-state {:init "ok"}
#(call-rescue % children))
;; Forward critical or ok if they are stable
stable-stream (sdo
(stable trigger-window :state
(where (state "critical") changed-stream))
(stable cancel-window :state
(where (state "ok") changed-stream)))]
;; Classify the metric into ok/middle/critical
(split
(> metric above) (with :state "critical" stable-stream)
(< metric below) (with :state "ok" stable-stream)
(with :state "middle" stable-stream))))
(defn trigger-above-cancel-below
"Set state to \"critical\" when metric is > above for trigger_window seconds.
Reset to \"ok\" when metric is < below for cancel-window seconds."
[above trigger-window below cancel-window & children]
(pipe --
(split
(> metric above) (with :state "critical" --)
(< metric below) (with :state "middle" --)
(with :state "ok" --))
(sdo
(stable trigger-window :state
(where (state "critical") --))
(stable cancel-window :state
(where (state "ok") --)))
(changed-state {:init "ok"}
#(call-rescue % children))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment