Skip to content

Instantly share code, notes, and snippets.

@paxinla
Created August 20, 2018 08:02
Show Gist options
  • Save paxinla/39e19a4d30f4bb74c87c5dacc884165d to your computer and use it in GitHub Desktop.
Save paxinla/39e19a4d30f4bb74c87c5dacc884165d to your computer and use it in GitHub Desktop.
An example of riemann configuration file.
; -*- mode: clojure; -*-
; vim: filetype=clojure
; 日志
(logging/init {:console true
:file "/var/log/riemann/riemann.log"})
; 端口
(let [host "127.0.0.1"]
(tcp-server {:host host
:port 5555})
(udp-server {:host host
:port 5555})
(ws-server {:host host
:port 5556}))
; 各种阈值
(def TSH-WARN-LONGTXN-VAL 1)
(def TSH-ERR-LONGTXN-VAL 5)
(def TSH-WARN-DISK-INFO 70.0)
(def TSH-ERR-DISK-INFO 90.0)
; 主体处理部分
(periodically-expire 5)
(let [index (default :ttl 30 (index))]
(streams
(not-expired
; 一般指标都用灰色展示
(where* (fn [e]
(let [service-name (:service e)]
(and (not (tagged-any? ["disk_info"] e))
(not= service-name "long_transaction_5sec"))))
(with :state nil index))
(where (tagged "disk_info")
(smap (fn [e]
(let [new-metric (if (= (:service e) "disk_percent")
(:metric e)
(/ (:metric e) 1024 1024 1024))]
(event {:host (:host e)
:service (:service e)
:tags (:tags e)
:time (:time e)
:metric new-metric
:mountpoint (str (:host e) ":" (get (:tags e) 1))
:state (if (= (:service e) "disk_percent")
(condp #(%1 %2) new-metric
(fn [x] (>= x TSH-ERR-DISK-INFO)) "critical"
(fn [x] (and (>= x TSH-WARN-DISK-INFO)
(< x TSH-ERR-DISK-INFO))) "warning"
"ok")
(identity nil))})))
index))
(where (service "long_transaction_5sec")
(smap (fn [e]
(assoc e :state (condp #(%1 %2) (:metric e)
(fn [x] (>= x TSH-ERR-LONGTXN-VAL)) "critical"
(fn [x] (and (>= x TSH-WARN-LONGTXN-VAL)
(< x TSH-ERR-LONGTXN-VAL))) "warning"
"ok" )))
index))
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment