作者 | AddoZhang       责编 | 欧阳姝黎

在配置系统监控的时候,是不是即使绞尽脑汁监控的也还是不够全面,或者不知如何获取想要的指标。

Awesome Prometheus alerts[1] 维护了一套开箱即用的 Prometheus 告警规则集合,有 300 多个告警规则。同时,还是说明如何获取对应的指标。这些规则,对每个 Prometheus 都是通用的。

涉及如主机、硬件、容器等基础资源,到数据库、消息代理、运行时、反向代理、负责均衡器,运行时、服务编排,甚至是网络层面和 Prometheus 自身和集群。

alert_rules

Prometheus 的安装和配置不做赘述,配置可以看这里[2]。下面简单看下几个常用规则

主机和硬件资源

主机和硬件资源的告警依赖 node-exporter[3] 输出的指标。例如:

内存不足

可用内存低于阈值 10% 就会触发告警。

- alert:HostOutOfMemoryexpr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes *100<10
for:2mlabels:severity: warningannotations:summary:Hostout of memory (instance {{ $labels.instance }})description:"Node memory is filling up (< 10% left)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

主机异常的网络吞吐

最近两分钟入站的流量超过 100m。

rate 语法见这里[4]

- alert:HostUnusualNetworkThroughputInexpr: sum by(instance)(rate(node_network_receive_bytes_total[2m]))/1024/1024>100
for:5mlabels:severity: warningannotations:summary:Host unusual network throughput in(instance {{ $labels.instance }})description:"Host network interfaces are probably receiving too much data (> 100 MB/s)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

Mysql

Mysql 的告警依赖 prometheus/mysqld_exporter[5] 输出的指标。

连接数过多

Mysql 实例的连接数最近一分钟的连接数超过最大值的 80% 触发告警

- alert:MysqlTooManyConnections(>80%)expr: avg by(instance)(rate(mysql_global_status_threads_connected[1m]))/ avg by(instance)(mysql_global_variables_max_connections)*100>80
for:2mlabels:severity: warningannotations:summary:MySQL too many connections (>80%)(instance {{ $labels.instance }})description:"More than 80% of MySQL connections are in use on {{ $labels.instance }}\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

慢查询

最近一分钟慢查询数量大于 0 时触发。

- alert:MysqlSlowQueriesexpr: increase(mysql_global_status_slow_queries[1m])>0
for:2mlabels:severity: warningannotations:summary:MySQL slow queries (instance {{ $labels.instance }})description:"MySQL server mysql has some new slow query.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

运行时 JVM

JVM 的运行时告警,居然只有可怜巴巴的一个。堆空间占用超过 80% 触发告警。

依赖 java-client[6] 输出的指标。

- alert:JvmMemoryFillingUpexpr:(sum by(instance)(jvm_memory_used_bytes{area="heap"})/ sum by(instance)(jvm_memory_max_bytes{area="heap"}))*100>80
for:2mlabels:severity: warningannotations:summary: JVM memory filling up (instance {{ $labels.instance }})description:"JVM memory is filling up (> 80%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

Kubernetes

Kubernetes 相关的告警规则有 33 个,比较丰富。

摘个比较常见的:容器OOM告警。

- alert:KubernetesContainerOomKillerexpr:(kube_pod_container_status_restarts_total - kube_pod_container_status_restarts_total offset 10m>=1)and ignoring (reason) min_over_time(kube_pod_container_status_last_terminated_reason{reason="OOMKilled"}[10m])==1
for:0mlabels:severity: warningannotations:summary:Kubernetes container oom killer (instance {{ $labels.instance }})description:"Container {{ $labels.container }} in pod {{ $labels.namespace }}/{{ $labels.pod }} has been OOMKilled {{ $value }} times in the last 10 minutes.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

SSL 证书过期

通过 [7] 输出的指标,可以监控证书过期:未来 7 天 有证书过期便会触发告警。

- alert:SslCertificateExpiry(<7Days)expr: ssl_verified_cert_not_after{chain_no="0"}- time()<86400*7
for:0mlabels:severity: warningannotations:summary: SSL certificate expiry (<7 days)(instance {{ $labels.instance }})description:"{{ $labels.instance }} Certificate is expiring in 7 days\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

今天列出来的也仅仅是冰山一角,而且用户也可以贡献[8]出更多的规则。

引用链接

[1] Awesome Prometheus alerts: https://awesome-prometheus-alerts.grep.to/
[2] 这里: https://awesome-prometheus-alerts.grep.to/alertmanager
[3] node-exporter: https://github.com/prometheus/node_exporter
[4] 这里: https://prometheus.io/docs/prometheus/latest/querying/functions/#rate
[5] prometheus/mysqld_exporter: https://github.com/prometheus/mysqld_exporter
[6] java-client: https://github.com/prometheus/client_java
[7] : https://github.com/ribbybibby/ssl_exporter
[8] 贡献: https://github.com/samber/awesome-prometheus-alerts#-contributing

☞苹果或推出粉色款iPhone 13;用户超 8 亿,拼多多再超阿里;贝索斯将于7月5日卸任亚马逊CEO|极客头条☞特斯拉已在中国建立数据中心☞21 句话入门机器学习

开箱即用的 Prometheus 告警规则集相关推荐

  1. 5.prometheus告警插件-alertmanager、自定义webhook案例编写

    5.prometheus告警插件-alertmanager 参考文章: https://www.bookstack.cn/read/prometheus-book/alert-install-aler ...

  2. linux查看文件句柄阀值,prometheus 告警指标

    记录了prometheus 告警指标 主机和硬件监控 可用内存指标 主机中可用内存容量不足 10% - alert: HostOutOfMemory expr: node_memory_MemAvai ...

  3. prometheus告警功能

    prometheus告警功能 Prometheus对指标的收集.存储同告警能力分属于Prometheus Server和AlertManager(通用的组件,可由企业自行开发)两个独立的组件,前者仅负 ...

  4. Prometheus 告警收敛

    Prometheus 告警收敛 告警面临最大问题,是警报太多,相当于狼来了的形式.收件人很容易麻木,不再继续理会.关键的告警常常被淹没.在一问题中,alertmanger在一定程度上得到很好解决. P ...

  5. 玩转prometheus告警 alertmanger(一)之prometheus告警规则

    目录 1. 告警系统原理概述 2.  配置prometheus规则 2.1 配置告警规则目录 2.2 告警规则 3. 查看效果 1. 告警系统原理概述 在开始之前,需要了解下prometheus和al ...

  6. Prometheus 告警规则

    Prometheus 告警规则 Prometheus官方内置的第三方报警通知包括:邮件. 即时通讯软件(如Slack.Hipchat).移动应用消息推送(如Pushover)和自动化运维工具(例如:P ...

  7. 最易懂的Prometheus告警原理详解

    通俗易懂的一篇文章,主要介绍了 Prometheus 什么时候告警,什么时候不会告警.同时介绍了 Prometheus 告警原理. 警报是监控系统中必不可少的一块, 当然了, 也是最难搞的一块. 我们 ...

  8. alertmanager监控 Prometheus 告警,alertmanage配置邮件告警

    1.搭建Prometheus,node及mysql参考该链接: 配置grafana展示prometheus监控数据 2.下载安装 alert manager: https://prometheus.i ...

  9. Prometheus告警实践

    完整译文请访问:告警. 点击这里获取云原生干货https://www.coderdocument.com/resource_credential.html?code=云原生干货 对什么告警 目标是尽可 ...

最新文章

  1. 只有14秒,假老黄才是假的!黄仁勋没有骗了全世界,英伟达「元宇宙」验明正身...
  2. RabbitMQ在windows系统安装部署文档
  3. Java 写时拷贝容器CopyOnWriteArrayList的测试
  4. python sort 多级排序_为什么在python中使用排序功能进行多级排序...
  5. b-2014四川电子机械职业技术学院计算机科学与技术毕业设计选题,2014届计算机科学与技术专业本科毕业设计(论文)选题指南...
  6. flash时间轴控制命令
  7. DESeq2差异基因分析和批次效应移除
  8. C# list集合 重复元素 索引_源码分析专题10-纯手写JDK不同版本下的List接口
  9. 我在自学python_我要自学python 自动化-request库
  10. ReentrantLock实现原理
  11. “音”你而来,“视”而可见 腾讯云+社区音视频技术开发实战沙龙圆满结束...
  12. linux mint 19 中国镜像,Beta版Linux Mint 19.3 Tricia的ISO镜像已开放下载
  13. pandas.to_numeric
  14. 电驴(easyMule)自动关机工具
  15. cv个人计算机SCI英文简历模板,个人英文简历模板
  16. python中的value是什么意思_Python self[name]=value是什么意思?
  17. 富爸爸穷爸爸读书感言
  18. ROM 和 RAM 区别
  19. LeCo-200. 岛屿数量
  20. [转]PHP大型Web应用入门(一)

热门文章

  1. ESP32驱动LCD液晶屏选型、262K什么意思?SPI写LCD的GRAM时序、MCU液晶屏驱动IC的寄存器功能
  2. Tina-TI 电路仿真 多参数交流传输特性分析 频率与相位增益的关系 选择控制对象
  3. 【分享】如何长时间高效学习
  4. 【英语】舞动奇迹--荡漾我心
  5. Oracle无法登陆EM问题解决方案
  6. 数据结构——树状数组
  7. spring boot 使用 websocket tomcat刚启动就关闭到问题
  8. 【loj6029】「雅礼集训 2017 Day1」市场 线段树+均摊分析
  9. 史上最全的MSSQL复习笔记
  10. 为什么要使用面向对象编程