程序员

prometheus告警问题分析

作者:admin 2021-04-09 我要评论

今天来说一下我在使用prometheus过程中遇到的告警问题。 问题分析 最近运维prometheus的过程中发现,有的时候它应该发送告警,可实际却没有;有的时候,不该发送...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

今天来说一下我在使用prometheus过程中遇到的告警问题。

问题分析

最近运维prometheus的过程中发现,有的时候它应该发送告警,可实际却没有;有的时候,不该发送告警却发送了;还有的时候,告警出现明显的延迟。为了找出其中的具体原因,特地去查阅了一些资料,同时也参考了官网的相关资料。希望对大家在今后使用prometheus有所帮助。

先来看一下官网提供的prometheus和alertmanager的一些默认的重要配置。如下所示:

  1. # promtheus 
  2. global
  3.   # How frequently to scrape targets by default. 从目标抓取监控数据的间隔 
  4.   [ scrape_interval: <duration> | default = 1m ] 
  5.   # How long until a scrape request times out. 从目标住区数据的超时时间 
  6.   [ scrape_timeout: <duration> | default = 10s ] 
  7.   # How frequently to evaluate rules. 告警规则评估的时间间隔 
  8.   [ evaluation_interval: <duration> | default = 1m ] 
  9. # alertmanager 
  10. # How long to initially wait to send a notification for a group 
  11. of alerts. Allows to wait for an inhibiting alert to arrive or collect 
  12. # more initial alerts for the same group. (Usually ~0s to few minutes.) 
  13. [ group_wait: <duration> | default = 30s ] # 初次发送告警的等待时间 
  14.  
  15. # How long to wait before sending a notification about new alerts that 
  16. # are added to a group of alerts for which an initial notification has 
  17. # already been sent. (Usually ~5m or more.) 
  18. [ group_interval: <duration> | default = 5m ] 同一个组其他新发生的告警发送时间间隔 
  19.  
  20. # How long to wait before sending a notification again if it has already 
  21. # been sent successfully for an alert. (Usually ~3h or more). 
  22. [ repeat_interval: <duration> | default = 4h ] 重复发送同一个告警的时间间隔 

通过上面的配置,我们来看一下整个告警的流程。通过流程去发现问题。


根据上图以及配置来看,prometheus抓取数据后,根据告警规则计算,表达式为真时,进入pending状态,当持续时间超过for配置的时间后进入active状态;数据同时会推送至alertmanager,在经过group_wait后发送通知。

告警延迟或频发

根据整个告警流程来看,在数据到达alertmanager后,如果group_wait设置越大,则收到告警的时间也就越长,也就会造成告警延迟;同理,如果group_wait设置过小,则频繁收到告警。因此,需要按照具体场景进行设置。

不该告警的时候告警了

prometheus每经过scrape_interval时间向target拉取数据,再进行计算。与此同时,target的数据可能已经恢复正常了,也就是说,在for计算过程中,原数据已经恢复了正常,但是被告警跳过了,达到了持续时间,就触发了告警,也就发送了告警通知。但从grafana中看,认为数据正常,不应发送告警。这是因为grafana以prometheus为数据源时,是range query,而不是像告警数据那样稀疏的。


本文转载自网络,原文链接:https://mp.weixin.qq.com/s/ZjiXyzXkvMqCtEy-1R_yBQ

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 四两拨千斤——你不知道的VScode编码Ty

    四两拨千斤——你不知道的VScode编码Ty

  • 我是如何在 Vue 项目中做代码分割的

    我是如何在 Vue 项目中做代码分割的

  • position:sticky 粘性定位的几种巧妙应

    position:sticky 粘性定位的几种巧妙应

  • 从零到一搭建React组件库

    从零到一搭建React组件库

腾讯云代理商
海外云服务器