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

2022-04-13 14:48:38 +08:00
 Aliencn

目前在 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)是分离的,我想通过一个地方设置报警值,在其他地方都能读到,在图表中直接展现出来。

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

658 次点击
所在节点    问与答
3 条回复
dier
2022-04-13 16:03:05 +08:00
你有定义“node_disk_usage_waring” 这个规则吗?如果没有定义,它是空的肯定不会生效呀!
先定义 rules



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

Aliencn
2022-04-13 17:29:52 +08:00
@dier
现在的情况就是在 alert 的 expr 中,
prometheus 中的变量与常量做比较,可以触发报警。
record 的值和常量做比较也,可以触发报警(就是你的第二张图里的)
prometheus 中的变量与 prometheus 中的变量做比较,可以触发报警。
record 的值与 record 的值做比较,可以触发报警
但是
prometheus 中的变量与 record 的值做比较,就不能出发报警(就是我主题里写的那个配置)
Aliencn
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
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/846739

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX