【问题标题】:Clojure Dashboard queryClojure 仪表板查询
【发布时间】:2015-11-03 19:02:38
【问题描述】:

我正在尝试使用查询在 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))”,但没有成功。

谁能帮我看看我必须做些什么才能让它工作?

问候

【问题讨论】:

    标签: clojure riemann riemann-dashboard


    【解决方案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)))
    

    【讨论】:

      【解决方案2】:

      原来我必须在“:metric field”中写入我的 pingDelay 值。它现在开始工作了。

      【讨论】:

        猜你喜欢
        • 2022-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-10
        • 1970-01-01
        相关资源
        最近更新 更多