AlertManager下載html
https://prometheus.io/download/node
解壓服務器
添加配置文件test.yml,配置收發郵件郵箱oop
Prometheus下載配置參考個人另外一篇:測試
http://www.javashuo.com/article/p-armszusz-ev.htmlui
參考配置:lua
global: smtp_smarthost: 'smtp.163.com:25' #163服務器 smtp_from: 'XXX@163.com' #發郵件的郵箱 smtp_auth_username: 'XXX@163.com' #發郵件的郵箱用戶名,也就是你的郵箱 smtp_auth_password: 'XXX' #發郵件的郵箱密碼 route: group_by: ['alertname'] repeat_interval: 1h receiver: live-monitoring receivers: - name: 'live-monitoring' email_configs: - to: 'czh1226@qq.com' #收郵件的郵箱
更多配置參考alertmanager包中的simple.ymlspa
添加報警規則code
prometheus targets 監控報警參考配置(node_down.yml):htm
groups: - name: example rules:
- alert: InstanceDown expr: up == 0 for: 1m labels: user: caizh annotations: summary: "Instance {{ $labels.instance }} down" description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minutes."
節點內存使用率監控報警參考配置(memory_over.yml)
groups: - name: example rules: - alert: NodeMemoryUsage expr: (node_memory_MemTotal_bytes - (node_memory_MemFree_bytes+node_memory_Buffers_bytes+node_memory_Cached_bytes )) / node_memory_MemTotal_bytes * 100 > 80 for: 1m labels: user: caizh annotations: summary: "{{$labels.instance}}: High Memory usage detected" description: "{{$labels.instance}}: Memory usage is above 80% (current value is:{{ $value }})"
固然,想要監控節點內存須要提早配置好node_exporter
修改prometheus配置文件prometheus.yml,開啓報警功能,添加報警規則配置文件
# Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: ["localhost:9093"] # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: - "node_down.yml" - "memory_over.yml"
配置完成!
啓動alertmanager
./alertmanager --config.file test.yml
啓動prometheus(默認會調用prometheus.yml)
./prometheus
http://localhost:9090/alerts
看配置與報警規則是否添加成功
成功則以下圖:
個人Prometheus Targets以下:
嘗試kill一個測試是否能夠用郵件報警
例如在slave1節點上:
hadoop-daemon.sh stop datanode
InstanceDown會變成(1 active),並處在PENDING狀態
1min後變FIRING狀態
耐心等待幾分鐘,會收到報警郵件:
郵件可能會有延時,耐心等一會~
想測試內存使用率能夠多開點佔內存的服務,或者把報警規則中內存佔用超過80%報警調小一些
Over~