如何动态地向Riemann客户端发送InfluxDB标签

时间:2017-11-09 08:58:22

标签: clojure influxdb riemann

是否有可能动态发送流入数据库标记,以下配置似乎无法正常工作,因为当我尝试通过流入数据库客户端选择所有标记时,它会返回0结果,请提供建议。应该改变。提前致谢。

(def send-influx
(influxdb/influxdb {
    :host "localhost"
    :db "riemann"
    :username "riemann"
    :password "riemann"}
 ))

(streams
(where (and (not (expired? event)) (service "service"))
    #(info %)
    (by [:host :service :id]
        (changed :metric {:pairs? true}
            (fn [[startEvent endEvent]]
                (when-not (empty? startEvent)
                    (let [diff (- (:metric endEvent) (:metric startEvent))]
                        (send-influx [{
                            :host (:host startEvent),
                            :service (:service startEvent),
                            :id (:id startEvent),
                            :metric diff,
                            :time (:time startEvent) },
                            :tag-fields {:id (:id startEvent)} }]  
                        )
                    )
                )
            )
        )
    )
))

2 个答案:

答案 0 :(得分:1)

以下是Riemann文档中的一个示例:

(def influx (influxdb {:host "localhost"
                       :db "riemann"
                       :version :new-stream}))

(streams
  (smap
    (fn [event]
      (assoc event :measurement     (:service event)
                   :influxdb-tags   {:state (:state event)}
                   ;; :value = 0 by default
                   :influxdb-fields {:value (or (:metric event) 0)}))
    influx))

如您所见,您应该在事件中使用:measurements,:Influxdb-tags和:Influxdb-fields键。

此配置适用于Riemann 0.2.13或更高版本。

答案 1 :(得分:0)

不幸的是,它没有多大帮助,因为由于某些原因,由于版本不兼容或smth,有一些解析异常,但是我最终能够通过将配置更改为以下来使其工作

    (def send-influx
    (influxdb/influxdb {
        :host "localhost"
        :db "riemann"
        :username "riemann"
        :password "riemann"
        :tag-fields #(:id)})

(streams
(where (and (not (expired? event)) (service "service"))
    #(info %)
    (by [:host :service :id]
    (changed :metric {:pairs? true}
        (fn [[startEvent endEvent]]
            (when-not (empty? startEvent)
                (let [diff (- (:metric endEvent) (:metric startEvent))]
                    (send-influx [{
                        :host (:host startEvent),
                        :service (:service startEvent),
                        :id (:id startEvent),
                        :metric diff,
                        :time (:time startEvent) },
                        :id (:id startEvent) }]  
                    )
                )
            )
        )
    )
)
))