普罗米修斯计数问题

时间:2019-02-08 20:34:49

标签: prometheus prometheus-alertmanager

我正在尝试计算过去一小时内普罗米修斯有多少值== 0,并尝试创建警报规则。

我想出了规则count_over_time(instance == 0 [1h])/ count_over_time(instance)

我得到一个错误,表明我必须遵循Prometheus聚合器表达式。

不确定背后的原因是什么。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

指出查询中的一些错误:

  • instance==0 [1h]Range selection仅在即时向量上可用,而不能用于表达式。即instance[1h]是有效的,但未提及。这里需要的是subquery,看起来像(instance==0)[1h:1m](选择分辨率)。

  • count_over_time(instance)count_over_time具有范围向量,因此此处不能仅使用instance,它是一个即时向量。

现在进入您期望的查询,据我了解,您想知道instance系列在过去1个小时中占0的百分比并发出警告,为此,我建议您使用{ {1}}标签来定义警报,例如:

for

如果连续groups: - name: example rules: - alert: ExampleAlert expr: count(instance == 0)/count(instance) > 0.5 for: 1h annotations: description: "Count of (instances==0) is >50% of instances for more than 1h." 的比率为> 0.5 (50%),它将发出警报。