Riemann - 从地图动态构建流

时间:2015-01-05 12:48:20

标签: clojure riemann

我有以下功能,它获取具有服务名称和阈值的地图。它检查服务是否超过定义的阈值,然后在事件上调用多个下游子节点。

(defn tc
  [s & children]
   (where
     (and (service (:service_name s)) (not (expired? event)))
       (by [:host :service]
         (where (> metric (:threshold s)
           (with :state "critical" 
             (apply sdo children)))))))

我想使用地图矢量动态构建流:

(def services [{:service "cpu/usage" :threshold 90}
               {:service "memory/usage" :threshold 90}])

尝试在流中运行时,我收到以下警告:

(streams
  (doseq [s services] (tc s prn)))

WARN [2015-01-05 14:27:07,187] Thread-15 - riemann.core - instrumentation service caught
java.lang.NullPointerException
  at riemann.core$stream_BANG_$fn__11140.invoke(core.clj:19)
  at riemann.core$stream_BANG_.invoke(core.clj:18)
  at riemann.core$instrumentation_service$measure__11149.invoke(core.clj:57)
  at riemann.service.ThreadService$thread_service_runner__8782$fn__8783.invoke(service.clj:66)
  at riemann.service.ThreadService$thread_service_runner__8782.invoke(service.clj:65)
  at clojure.lang.AFn.run(AFn.java:22)
  at java.lang.Thread.run(Thread.java:701)

如果我在doseq中运行streams函数,它可以工作。 这个工作并提供以下输出:

(doseq [s services]
  (streams (tc s prn)))

#riemann.codec.Event{:host "testhost", :service "memory/usage", :state "critical", :description nil, :metric 91.0, :tags nil, :time 1420460856, :ttl 60.0}

1 个答案:

答案 0 :(得分:0)

如果您的活动没有所有必填字段,似乎会爆炸,这里是来自类似项目的样本,我从一系列事件中构建事件(减少)它是虽然我以同样的方式生成事件,但并不完全是你在做什么:

{:service (:service (first events))
 :metric (->> events count)
 :host "All-counts"
 :state "OK"
 :time (:time (last events))
 :ttl default-interval}

当时间不见时,我特意得到了NPE。如果你不能从某个地方继承它,只需补充(例如使用now),这里没有合理的值,事件过期将不起作用,你将用完RAM