Skip to content

Instantly share code, notes, and snippets.

@dryman
Last active December 22, 2015 05:49
Show Gist options
  • Save dryman/6426741 to your computer and use it in GitHub Desktop.
Save dryman/6426741 to your computer and use it in GitHub Desktop.
Robust overshoot detection function for riemann
(defn overshoot-by-ratio
"Takes a list of event, emit an event if the overshoot events is over the ratio.
The emitted event will contain a description of the overshoot threshold and the ratio;
the metric of the emitted event will be the median of overshoot events. Example:
(moving-time-window 300 ; 5 min
(overshoot-by-ratio 1500 0.2 ; if the ratio of metrics which more than 1500
; is larger than 0.2, the below would be called
(throttle 1 500
(email \"[email protected]\"))))"
[threshold ratio & children]
(fn [events]
(when-let [over (->> events
(filter identity)
(filter #(> (:metric %) threshold)))]
(let [over-ratio (-> (count over)
(/ (count events))
(float))
mean-event (folds/mean over)]
(if (> over-ratio ratio)
(-> mean-event
(merge {:description
(str "overshoot threshold " threshold
" for ratio " over-ratio)
:metric (float (:metric mean-event))
:state "alert"})
(call-rescue children)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment