Alertmanager
Prometheus Alertmanager 是 Prometheus 监控体系中的告警管理组件,由 Prometheus 社区以 Go 语言开发, 用于接收 Prometheus Server 发送的告警信息; 其首个稳定版本随 Prometheus 项目在 2016 年进入 CNCF 孵化后逐步成熟,并由开源社区持续维护与迭代,支持告警去重、分组、抑制及多渠道通知。
使用 Alertmanager 设置告警
Alertmanager v0.29.0 支持 Windows 10 or newer,或 Windows 7 + VxKex .
容器安装启动 docker run --name alertmanager -d -p 127.0.0.1:9093:9093 quay.io/prometheus/alertmanager
二进制下载启动 alertmanager --config.file=path/to/alertmanager.yml
配置步骤
- 修改 Prometheus 主配置, 设置 Alertmanager 地址
- 修改 Alertmanager 主配置,设置告警收敛分组、告警发送渠道和接收人
- 先后启动 Alertmanager 和重启 Prometheus
Alertmanager 参考配置 alertmanager.yml
global:
resolve_timeout: 1m
smtp_smarthost: "smtp.bar.com:25"
smtp_from: "BOT <bot@bar.com>"
smtp_auth_username: "bot@bar.com"
smtp_auth_password: "x"
smtp_require_tls: false
route:
receiver: "dev"
receivers:
- name: "dev"
email_configs:
- to: "someone@bar.com"Prometheus 参考配置 prometheus.yml
alerting:
AlertManagers:
- static_configs:
- targets:
- 127.0.0.1:9093
rule_files:
- "host_rules.yml"Prometheus 参考配置 host_rules.yml ,新建或修改该配置文件,和 prometheus.yml 在同一个根目录
# rules.yml
groups:
- name: host_down
rules:
- alert: HostDown
expr: up == 0
for: 3m
labels:
severity: critical
annotations:
summary: "{{ $labels.instance }} node/service is down"
description: "Target {{ $labels.instance }} node/service has been unreachable for more than minute(s)."相关工具
- 可视化修改 config.yml Alertmanager Routing Tree Editor
ref: https://prometheus.io/docs/alerting/latest/overview/
使用 Alertmanager 和 Grafana 设置告警
参考前一步配置 prometheus 和 alertmanager 后,并重启服务后。 通过修改 prometheus 的 rule_files 配置文件易错、效率低,可使用 Grafana 自带的网页可视化规则编辑器代替配置。
修改 Grafana 配置 grafana.ini 的 SMTP 章节,参考:
[smtp]
enabled = true
host = smtp.foo.com:25
user = bot@foo.com
password = """secret"""
skip_verify = false
from_address = bot@foo.com
from_name = BOT
ehlo_identity = foo.com
startTLS_policy = OpportunisticStartTLS
...重启 Grafana 服务。
打开 Grafana 左侧面板
- Alerting - Contact points 新增高级接收邮件
- Alerting - Alert rules 配置高级规则
