V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Aliencn
V2EX  ›  问与答

普罗米修斯 prometheus 如何让 record 的值在 alert 中调用

  •  
  •   Aliencn · 2022-04-13 14:48:38 +08:00 · 654 次点击
    这是一个创建于 741 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前在 alert 中 expr 那一行,是不生效的。 有没有办法让 alert 中调用 record 中的值。

    groups:
    - name: node.rule
      rules:
      - record: node_disk_usage_waring
        expr: 70
      - alert: 主机磁盘使用率过高
        expr: node_disk_usage > node_disk_usage_waring
        for: 10s
        annotations:
          description: warning
          severity: warning
    

    想这么做的原因是,在 prometheus 的生态中,触发报警(prometheus)和图表展示(grafana)是分离的,我想通过一个地方设置报警值,在其他地方都能读到,在图表中直接展现出来。

    各位大佬们有没有办法实现

    3 条回复    2022-04-13 19:01:02 +08:00
    dier
        1
    dier  
       2022-04-13 16:03:05 +08:00
    你有定义“node_disk_usage_waring” 这个规则吗?如果没有定义,它是空的肯定不会生效呀!
    先定义 rules



    然后再去调用是可以直接用定义的规则名的

    Aliencn
        2
    Aliencn  
    OP
       2022-04-13 17:29:52 +08:00
    @dier
    现在的情况就是在 alert 的 expr 中,
    prometheus 中的变量与常量做比较,可以触发报警。
    record 的值和常量做比较也,可以触发报警(就是你的第二张图里的)
    prometheus 中的变量与 prometheus 中的变量做比较,可以触发报警。
    record 的值与 record 的值做比较,可以触发报警
    但是
    prometheus 中的变量与 record 的值做比较,就不能出发报警(就是我主题里写的那个配置)
    Aliencn
        3
    Aliencn  
    OP
       2022-04-13 19:01:02 +08:00
    找到原因了,是因为 label 不匹配导致的。
    用了个骚方法,保留了 label 值
    ```
    groups:
    - name: node.rule
    rules:
    - record: node_disk_usage_waring
    expr: node_disk_usage - node_disk_usage + 10
    - alert: 主机磁盘使用率过高
    expr: node_disk_usage > node_disk_usage_waring
    for: 10s
    annotations:
    description: warning
    severity: warning
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1587 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:56 · PVG 00:56 · LAX 09:56 · JFK 12:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.