计算给定时间内的黎曼事件 window

Count riemann events in given time window

在针对特定服务的 riemann 配置中,我试图为其所有事件分配 metric=1,在 5 秒内对它们求和并将结果发送到 influxdb。

我尝试了以下方法:

(streams
  (where (service "offers")
    (fixed-time-window 5
      (smap folds/sum (with :metric 1 index))))
  influx)

确实不行,存储在influx中的事件不符合这个规则。

内置 folds/count 函数执行此操作:

(fixed-time-window 5
  (smap folds/count influx))            

另外,对 influx 的调用需要是进行计数的流的子级,因此它是被索引的计数。

如果您想使用 folds/sum 修复您的示例,您可以将调用移至 (with :metric 1) 调用之外或上游,以便将指标设置为 1,然后将新的指标在对 folds/sum 的调用中求和。然后将对 index 和/或 influx 的调用作为 smap 的子流,以便对求和项进行索引和转发。

添加到 Arthur 的答案中,您可能想使用 rate (with scale) instead of fixed-time-window (with smap and folds/count). rate is generally better than fixed-time-window because rate fires as soon as the time window has finished, while fixed-time-window has to wait until a new event arrives after the time window has finished, which can never happen or happen too far in the future. There's an issue in riemann 关于这个。

还有一个 comment from aphyr 解释了为什么 rate 比窗口函数更有效。

您只需要将它与 scale 一起使用,因为 rate 将以秒为单位测量速率,而您想要以 5 秒为单位(在 5 秒间隔内测量)获得速率。