vmalert通过在alert.rules中配置告警规则实现告警,告警规则语法与Prometheus兼容,依赖Alertmanager与prometheus-webhook-dingtalk实现钉钉告警,以下步骤:
1、构建vmalert
从源代码构建vmalert:
git clone https://github.com/VictoriaMetrics/VictoriaMetrics
cd VictoriaMetrics
make vmalert
构建二进制文件将放置在VictoriaMetrics/bin文件夹中。
2、添加alert.rules
告警规则语法兼容Prometheus:
vim alert.rules
#rule示例
groups:
- name: test-rule
rules:
- alert: 主机状态
expr: up == 0
for: 2m
labels:
status: warning
annotations:
summary: "{{$labels.instance}}:服务器关闭"
description: "{{$labels.instance}}:服务器关闭"
3、修改钉钉prometheus-webhook-dingtalk配置文件
vim /usr/local/prometheus-webhook-dingtalk/config.example.yml
4、修改alertmanager配置文件
#查看prometheus-webhook-dingtalk的url地址,altermanager会将通知像这个地址发送
journalctl -u prometheus-webhook-dingtalk -f
#可以看到url urls=http://localhost:8060/dingtalk/webhook1/send
vim /usr/local/alertmanager/alertmanager.yml
5、启动vmalert
./bin/vmalert -rule=alert.rules \
-datasource.url=http://localhost:8428 \
-notifier.url=http://localhost:9093 &