普罗米修斯计数问题

Prometheus counting issue

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

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

我收到错误提示,我必须遵循 Prometheus 聚合器表达式。

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

非常感谢您的帮助。

指出您查询中的一些错误:

  • instance==0 [1h]Range selection is possible only on instant vector, and not an expression. i.e., instance[1h] is valid, but not the one mentioned. What you need here is a subquery,看起来像 (instance==0)[1h:1m](选择您的分辨率)。

  • count_over_time(instance): count_over_time 接受一个范围向量,所以这里不能只使用 instance,它是一个即时向量。

现在进入你预期的查询,我的理解是你想知道在过去 1 小时内 instance 系列中有多少百分比结果为 0 并对此发出警报,为此我建议寻求帮助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."

在这里,如果直线 1h 的比率是 > 0.5 (50%),它会发出警报。