【问题标题】:Prometheus counting issue普罗米修斯计数问题
【发布时间】:2019-02-08 20:34:48
【问题描述】:

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

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

我得到错误显示我必须遵循 Prometheus 聚合器表达式。

不知道背后的原因是什么。

非常感谢您的帮助。

【问题讨论】:

    标签: prometheus prometheus-alertmanager


    【解决方案1】:

    指出查询中的一些错误:

    • instance==0 [1h]: Range selection 仅适用于即时向量,而不适用于表达式。即,instance[1h] 是有效的,但不是提到的那个。您需要的是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."
    

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

    【讨论】:

    • 嘿 Codesome,非常感谢您的帮助。现在可以使用了
    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2020-05-28
    • 2021-09-12
    • 2017-09-03
    • 1970-01-01
    • 2022-10-17
    • 2022-12-02
    • 2022-12-17
    相关资源
    最近更新 更多