Skip to content

Instantly share code, notes, and snippets.

@robkuz
Last active December 25, 2015 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robkuz/6918034 to your computer and use it in GitHub Desktop.
Save robkuz/6918034 to your computer and use it in GitHub Desktop.
I have an adjust-state fn which I use to, well adjust the state ;-) thru which I stream all my events. And then I have a changedx fn (basically its the riemann.streams.changed fn with added debug output). Now If I run this I get multiple outputs for every host/service combination event thou the state hasn't changed. If I stream events directly f…
(defn transform-event [event options]
(let [ event-path (event-to-vector event)
state-values (find-state-thresholds event-path options)
state (find-state (:metric event) state-values)
new-event (assoc event :state state)]
new-event))
(defn adjust-state [options & children]
(fn [e]
(let [ new-event (transform-event e options)]
(call-rescue new-event children))))
(defn changedx [pred & children]
(let [ options (first children)
previous (ref
(when (map? options)
(:init options)))
children (if (map? options)
(rest children)
children)]
(fn stream [event]
(when
(dosync
(let [ cur (pred event)
old (deref previous)
]
(when-not (= cur old)
(println (str "200: '" (:service event) "@" (:host event) ": " old "'='" cur "'"))
(ref-set previous cur)
true)))
(call-rescue event children)))))
(let [index (default :ttl 30 (update-index (index)))]
(streams
(adjust-state threshold-options
(where (host "monitoring-agent")
(changedx :state {:init "started"} notify-me-and-the-world))
index)))
;this works as expected
;but I need to stream thru adjust-state
(let [index (default :ttl 30 (update-index (index)))]
(streams
(where (host "monitoring-agent")
(changedx :state {:init "started"} notify-me-and-the-world))
(adjust-state threshold-options
index)))
200: 'load-15@monitoring-agent: ok'='critical' 200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical' 200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
200: 'load-15@monitoring-agent: ok'='critical'
200: '/@monitoring-agent: critical'='ok'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment