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-rulerules:- alert: 主機狀態expr: up == 0for: 2mlabels:status: warningannotations: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/sendvim /usr/local/alertmanager/alertmanager.yml
5、啟動vmalert
./bin/vmalert -rule=alert.rules \-datasource.url=http://localhost:8428 \-notifier.url=http://localhost:9093 &