需求:

  有时候,我们总有一些奇奇怪怪的需求,要定时定点的去判断或者去操作;

  比如我现在就有一个奇奇怪怪的需求,因为prometheus 没有做高可用,我要看它是否挂了,如果太频繁我又嫌烦,如果太久又不能起到效果;

  所以我现在需要,每天早上6点发个告警,以便我确保 prometheus 是存活的;

解决:

  比如现在是 2021-08-02 16:01:01 ,那么我获取的

获取小时数 16:floor(node_time_seconds{instance='10.20.50.5:9100'}%(3600*24)/3600+8)      ,这里+8 是因为是 UTC 时间,+8 到我们中国本地时间

获取分钟数 5:floor(node_time_seconds{instance='10.20.50.5:9100'}%(3600*24)/60%60)         ,这里不+8 是因为,反正分钟都一样

  prometheus定时定点发送告警

 最后,在rules 里面配置

  

- alert: Prometheus存活测试
expr: floor(node_time_seconds{instance='10.20.50.5:9100'}%(3600*24)/3600+8)==6 and floor(node_time_seconds{instance='10.20.50.5:9100'}%(3600*24)/60%60)<10
for: 5m
labels:
severity: critical
annotations:
summary: "Prometheus 存活测试"
description: "Prometheus alive test"

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2021-09-14
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2021-10-23
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2023-02-23
  • 2022-01-16
  • 2021-12-20
  • 2022-12-23
  • 2021-11-17
  • 2021-12-28
相关资源
相似解决方案