Prometheus(普罗米修斯)搭建监控在我的上一篇博客,如果有需要可以去参考参考,这篇时下篇,上篇是Prometheus(普罗米修斯)搭建监控,两篇可以连起来看
温馨提示,请将下文文档中所涉及到的邮箱,换成你们自己的。谢谢,不然你们接收不到报警信息,会发到我这
1)部署prometheus监控组件alertmanager.
[root@docker01 ~]# docker load < alertmanager.tar
[root@docker01 ~]# docker run -d --name alertmanager -p 9093:9093 prom/alertmanager
[root@docker01 ~]# vim alertmanager.yml
global:
resolve_timeout: 5m
smtp_from: '2389113325@qq.com'
smtp_smarthost: 'smtp.qq.com:465'
smtp_auth_username: '2389113325@qq.com'
smtp_auth_password: 'ikeamxidxbodeaba'
smtp_require_tls: false
smtp_hello: 'qq.com'
route:
group_by: ['alertname']
group_wait: 5s
group_interval: 5s
repeat_interval: 5m
receiver: 'email'
receivers:
- name: 'email'
email_configs:
- to: '2389113325@qq.com'
send_resolved: true
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
[root@docker01 ~]# docker rm -f alertmanager
[root@docker01 ~]# docker run -d --name alertmanager -p 9093:9093 -v /root/alertmanager.yml:/etc/alertmanager/alertmanager.yml prom/alertmanager
2)创建监控规则,使用email报警方式。监控服务运行状态,如果服务节点down机状态,则发送邮件。
[root@docker01 ~]# mkdir -p prometheus/rules
[root@docker01 ~]# cd prometheus/rules/
[root@docker01 ~]# vim prometheus.yml
12行:
12行:
15行:
- "/usr/local/prometheus/rules/*.rules"
[root@docker01 ~]# docker rm -f prometheus
[root@docker01 ~]# docker run -d -p 9090:9090 --name prometheus --net=host -v /root/prometheus.yml:/etc/prometheus/prometheus.yml -v /root/prometheus/rules/node-up.rules:/usr/local/prometheus/rules/node-up.rules prom/prometheus
Docker02:
[root@docker02 ~]# docker stop cadvisor
Cadvisor
3)创建邮件发送模板,仍使用email报警方式,模拟服务节点down机状态,查看验证email发送模板。
[root@docker01 ~]# cd prometheus/
[root@docker01 prometheus]# mkdir alertmanager-tmpl
[root@docker01 prometheus]# cd alertmanager-tmpl/
[root@docker01 alertmanager-tmpl]# vim email.tmpl
{{ define "email.from" }}2389113325@qq.com{{ end }}
{{ define "email.to" }}2389113325@qq.com{{ end }}
{{ define "email.to.html" }}
{{ range .Alerts }}
=========start==========<br>
告警程序: prometheus_alert<br>
告警级别: {{ .Labels.severity }} 级<br>
告警类型: {{ .Labels.alertname }}<br>
故障主机: {{ .Labels.instance }}<br>
告警主题: {{ .Annotations.summary }}<br>
触发时间: {{ .StartsAt.Format "2019-08-04 16:58:15" }} <br>
=========end==========<br>
{{ end }}
{{ end }}
[root@docker01 ~]# vim alertmanager.yml
8行:
templates:
- '/etc/alertmanager-tmpl/*.tmpl'
21行:
21行:
- to: '{{ template "email.to"}}'
html: '{{template "email.to.html" .}}'
[root@docker01 ~]# docker rm -f alertmanager
[root@docker01 ~]# docker run -itd --name alertmanager -p 9093:9093 -v /root/alertmanager.yml:/etc/alertmanager/alertmanager.yml -v /root/prometheus/alertmanager-tmpl:/etc/alertmanager-tmpl prom/alertmanager:latest
Docker02:
[root@docker02 ~]# docker stop cadvisor