Skip to content

Instantly share code, notes, and snippets.

@longdongjohn
Last active February 26, 2016 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save longdongjohn/2b274f1b6d786ce07373 to your computer and use it in GitHub Desktop.
Save longdongjohn/2b274f1b6d786ce07373 to your computer and use it in GitHub Desktop.
(include "globals.clj")
(def c-subj (atom ""))
(def temp1 (atom 0))
(def m1_flag (atom ""))
(def m2_flag (atom ""))
(def temp3 (atom 0))
(def flag (atom 0))
(def temp2 (atom 0))
(def email-c (mailer {:host "smtp.gmail.com"
:port 587
:user "asd@gmail.com"
:pass "pwd"
:tls "true"
:subject (fn [events](str "Cpu Threshold reached"))
:body (fn [eve](apply str @temp3 "Host " (get-in (first events) [:host])))
:from "xxx@gmail.com"}))
(defn user [& children]
(fn [e] (let [new-event (assoc e :warning "warning-limit-file")]
(reset! temp1 (get e :metric))
(reset! m1_flag 1)
)))
(defn system [& children]
(fn [e] (let [new-event (assoc e :warning "warning-limit-file")]
(reset! temp2 (get e :metric))
(reset! m2_flag 1)
)))
(defn gt [& children]
(fn [e]
(reset! c-subj (str (get e :host)))
(rollup 1 180 ((email-c "xxxx@gmail.com") e))
))
(streams
(by [:host :time]
(where (service #"aggregation-cpu-sum/cpu-user")
(user)
)
(where
(service #"aggregation-cpu-sum/cpu-system")
(system)
)
(where (and (= 1 @m2_flag) (= 1 @m1_flag) (false? (= @temp3 0)));
(reset! temp3 (+ @temp1 @temp2))
(reset! m2_flag 0)
(reset! m1_flag 0)
(if (< @temp3 cpu_threshold) (fn [& children] (prn @temp3))
(rollup 1 1800 (email-c "xxxxy@gmail.com")))
))))
@pyr
Copy link

pyr commented Feb 26, 2016

(streams
  (by [:host]
    (where 
     (project [(service "aggregation-cpu-sum/cpu-user") (service "aggregation-cpu-sum/cpu-system")]
        (smap folds/sum
           (where (> metric threshold)
              (rollup 1 180 email-c)))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment