Clojure 仪表盘查询

Clojure Dashboard query

我正在尝试使用查询在 riemann-dashboard 上显示图表 "pingDelay > 0"。

我已经使用以下代码为我的数据编制了索引

(let [index (index)]
  (defn write-dht-metric [e]
    (let [dhtstate (re-find #"dht_status: health\.(\S+), msg count (\d+) \((\d+) bytes\).*peak \{ping = (\d+)" (:pgmsg e))]
      (if (not= dhtstate nil)
        (do
          (prn "RESULT>" dhtstate)
          (index {:host "dht-info"
                  :service (:service e)
                  :time (unix-time)
                  :dhtStatus (get dhtstate 1)
                  :msgCount (get dhtstate 2)
                  :pingDelay (get dhtstate 3)}
            )
          )
        )
      )
    )
  )

但是,我在图表上没有得到任何信息。早些时候,我认为可能是因为我的 "pingDelay" 在字符串“12345”中,所以,我也尝试了“:pingDelay #(Long. (get dhtstate 3))”,但没有成功。

任何人都可以帮助我了解我必须做些什么才能让它发挥作用吗?

此致

事实证明,我必须在“:metric 字段”中写入 pingDelay 的值。它现在开始工作了。

在函数调用中定义顶层形式有点奇怪。它之所以起作用,只是因为定义了一个 var returns 那个 var 到调用表单。更典型的写法是:

(defn write-dht-metric [e]
  (let [dhtstate (re-find #"dht_status: health\.(\S+), msg count (\d+) \((\d+) bytes\).*peak \{ping = (\d+)" (:pgmsg e))]
    (if (not= dhtstate nil)
      (do
        (prn "RESULT>" dhtstate)
        (index {:host "dht-info"
                :service (:service e)
                :time (unix-time)
                :dhtStatus (get dhtstate 1)
                :msgCount (get dhtstate 2)
                :pingDelay (get dhtstate 3)})))))

(let [index (index)]
  (streams
   write-dht-metric))

还有其他几种写法:

(defn write-dht-metric [e]
  (let [dhstate (:dhstate e)]
        (prn "RESULT>" dhtstate)
        (index {:host "dht-info"
                :service (:service e)
                :time (unix-time)
                :dhtStatus (get dhtstate 1)
                :msgCount (get dhtstate 2)
                :pingDelay (get dhtstate 3)})))

(let [index (index)]
  (streams
   (with :dhstate (re-find #"dht_status: health\.(\S+), msg count (\d+) \((\d+) bytes\).*peak \{ping = (\d+)" (:pgmsg event))
       (when :dhstate 
         write-dht-metric)))