1

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

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

(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))”,但没有成功。

任何人都可以帮助我了解我必须做些什么才能使它工作吗?

问候

4

2 回答 2

1

在函数调用中定义顶级表单有点奇怪。它之所以起作用,只是因为定义一个 var 会将该 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)))
于 2015-11-03T21:55:21.700 回答
0

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

于 2015-11-03T21:01:47.673 回答