AlertManager进行告警

安装AlertManager

github上给了AlertManager的几种安装方法:(https://github.com/prometheus/alertmanager)。

这里,我们使用二进制进行安装。首先下载二进制文件,这里我们下载最新版本0.20.0https://prometheus.io/download/#alertmanager)

$ wget https://github.com/prometheus/alertmanager/releases/download/v0.20.0/alertmanager-0.20.0.linux-amd64.tar.gz

同样,我们使用systemd来管理这个服务。我们把解压后的整个alertmanager-0.20.0.linux-amd64文件夹移动到/usr/local/目录下,并重命名为alertmanager

$ mv ./alertmanager-0.20.0.linux-amd64 /usr/local/alertmanager

然后创建文件/usr/lib/systemd/system/alertmanager.service,内容如下

[Unit]
Description=alertmanager
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/alertmanager/alertmanager --config.file /usr/local/alertmanager/alertmanager.yml --storage.path=/var/lib/alertmanager
Restart=on-failure

[Install]
WantedBy=multi-user.target

编辑/usr/local/alertmanager/alertmanager.yml,内容如下(参考【1】【2】:

启动alertmanager

为Prometheus配置AlertManager与告警规则

编辑/usr/local/prometheus/prometheus.yml文件,在alerting区域与rule_files区域添加如下的内容,最终prometheus.yml文件内容如下:

然后创建文件/usr/local/prometheus/rule_files/memory_alert.yml,内容如下:

不久后,便可以接收到告警邮件,如下

Reference

【1】https://www.cnblogs.com/longcnblogs/p/9620733.html 【2】https://github.com/prometheus/alertmanager/blob/master/doc/examples/simple.yml

Last updated

Was this helpful?