2

是否可以动态发送 influx db 标签,以下配置似乎不起作用,因为当我尝试通过 influx db 客户端选择所有标签时,它返回 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)} }]  
                        )
                    )
                )
            )
        )
    )
))
4

2 回答 2

1

不幸的是,它并没有太大帮助,因为由于某些原因,由于版本不兼容或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) }]  
                    )
                )
            )
        )
    )
)
)) 
于 2017-11-10T08:50:36.690 回答
0

这是 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 或更高版本。

于 2017-11-09T22:31:38.517 回答