
前言
前面提到了,Prometheus 数据指标采集 + Grafana 数据 Web 展示 + 钉钉告警消息通知,但是仅仅是做了一个实验,并没有深究其触发告警问题,那 Prometheus 到底是如何触发告警的?我们接着往下看。
一、Prometheus 架构
在搞清楚 Prometheus 是如何触发告警前,首先我们要清楚 Prometheus 的一个整体架构,其他部分我们先不看,我们就来看 Alertmanager 部分,从架构图中可看到它作为一个整体独立存在,Prometheus 以 Push 消息的方式与其通信,Alertmanager 最后再将 Prometheus 推送过来的告警信息经过其模板渲染后路由给指定用户&&接收端(邮件/钉钉/企业微信等),从而实现告警通知。

沿用前两篇博客案例来逐步解释。
二、Prometheus 告警触发
2.1 Prometheus 规则文件与字段解释
首先,来看 Prometheus 的告警规则:
cat /home/data/prometheus/rules/ssl_cert_alerts.yml
groups: # 父分组
- name: "SSL证书过期提醒" # 子分组。该字段下可配置多个子分组(子分组名用name字段定义),也就是说Prometheus以组的形式进行告警配置。本案例中定义了名为“SSL证书过期提醒”的一个子分组。
rules: # 定义子分组的告警规则。
- alert: "证书过期时间<30天" # 定义告警名。
expr: probe_ssl_earliest_cert_expiry{
job="SSL证书时间"} - time() < 86400 * 30 # 告警条件(只有满足这个表达式条件时才会触发告警)
for: 0s # 持续的时间(满足告警条件持续时间多久后,才会发送告警到Alertmanager)
labels: # 标签(K/V的形式,如定义告警的级别 - - > 提示、告警、严重。)
severity: "提示"
annotations: # 注释(summary -- 摘要、description -- 详情)
summary: "SSL 证书即将过期!"
description: "{
{ $labels.instance }} SSL 证书将在30天后过期,请注意及时续费!"
- alert: "证书过期时间<7天"
expr: probe_ssl_earliest_cert_expiry{
job="SSL证书时间"} - time() < 86400 * 7
for: 0s
labels:
severity: "告警"
annotations:
summary: "SSL 证书即将过期!"
description: "{
{ $labels.instance }} SSL 证书将在7天后过期,请注意及时续费!"
- alert: "证书过期时间<1天"
expr: probe_ssl_earliest_cert_expiry{
job="SSL证书时间"} - time() < 86400 * 1
for: 0s
labels:
severity: "灾难"
annotations:
summary: "SSL 证书即将过期!"
description:
2782




被折叠的 条评论
为什么被折叠?



