Skip to content

Instantly share code, notes, and snippets.

Last active Sep 10, 2016
What would you like to do?
Example of Riemann index lookup a la Nagios Herald
(require 'riemann.common)
(require 'clojure.pprint)
(let [host ""]
(graphite-server :host host
:port 5559)
(tcp-server :host host)
(udp-server :host host
:max-size 65000)
(repl-server :host host)
(ws-server :host host))
; Expire old events from the index every 1 minute
; NB changing this value dramatically alters Riemann's memory requirements
; use :keep-keys to pass tags onto expired events as well
(periodically-expire 60 {:keep-keys [:host :service :tags]})
(defn round
"Round numbers to 2 decimal places"
(clojure.pprint/cl-format nil "~,2f" metric)
(defn lookup
"Lookup events in the index"
[host service]
(riemann.index/lookup (:index @riemann.config/core) host service)
(defn search
"Search events in the index"
(->> '(= host host)
(riemann.index/search (:index @riemann.config/core)))
(defn print-context
"Print the event content"
(clojure.string/join "\n"
(fn [event]
"Service: " (:service event) " with metric: " (round (:metric event))))
(defn format-body
"Format the email body"
(clojure.string/join "\n\n\n"
(fn [event]
"Time: " (riemann.common/time-at (:time event)) "\n"
"Host: " (:host event) "\n"
"Service: " (:service event) "\n"
"State: " (:state event) "\n"
"Metric: " (if (ratio? (:metric event))
(double (:metric event))
(round (:metric event))) "\n"
"Additional context for host: " (:host event) "\n\n"
(print-context (search (:host event)))
(def email (mailer {:from ""
:body (fn [events] (format-body events))
(let [index (index)]
(default :ttl 60
; Index all events immediately.
(where (and (service #"^df-(.*)/percent_bytes-used") (<= metric 90.0))
(email "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment