linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)
Posted 刘宏缔的架构森林
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)相关的知识,希望对你有一定的参考价值。
一,alertmanager的用途
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,下载alertmanager
https://prometheus.io/download/
[root@blog prometheus]# pwd /usr/local/source/prometheus [root@blog prometheus]# wget https://github.com/prometheus/alertmanager/releases/download/v0.20.0/alertmanager-0.20.0.linux-amd64.tar.gz
三,安装alertmanager
[root@blog prometheus]# tar -zxvf alertmanager-0.20.0.linux-amd64.tar.gz
[root@blog prometheus]# mv alertmanager-0.20.0.linux-amd64 /usr/local/soft/
[root@blog prometheus]# /usr/local/soft/alertmanager-0.20.0.linux-amd64/alertmanager --version alertmanager, version 0.20.0 (branch: HEAD, revision: f74be0400a6243d10bb53812d6fa408ad71ff32d) build user: root@00c3106655f8 build date: 20191211-14:13:14 go version: go1.13.5
四,配置alertmanager
[root@blog alertmanager-0.20.0.linux-amd64]# pwd /usr/local/soft/alertmanager-0.20.0.linux-amd64 [root@blog alertmanager-0.20.0.linux-amd64]# vi alertmanager.yml
global: resolve_timeout: 5m smtp_smarthost: \'smtp.163.com:465\' smtp_from: \'chinalinuxzend@163.com\' smtp_auth_username: \'chinalinuxzend@163.com\' smtp_auth_password: \'yourauthcode\' smtp_require_tls: false route: group_by: [\'alertname\'] group_wait: 10s group_interval: 10s repeat_interval: 1h receiver: \'mail\' receivers: - name: \'mail\' email_configs: - to: \'371125307@qq.com\'
说明:
如果是在阿里云上,需要配置465端口发送邮件,因为25端口被封禁了,参考这一篇:
https://www.cnblogs.com/architectforest/p/12924395.html
smtp_auth_password:它不是邮箱的登录密码,而是邮件服务商提供的一个授权码
[root@blog alertmanager-0.20.0.linux-amd64]# ./amtool check-config alertmanager.yml
五,使systemd支持alertmanager服务
[root@blog alertmanager-0.20.0.linux-amd64]# vi /usr/lib/systemd/system/alertmanager.service
[Unit] Description=Alertmanager After=network.target [Service] Type=simple ExecStart=/usr/local/soft/alertmanager-0.20.0.linux-amd64/alertmanager --config.file=/usr/local/soft/alertmanager-0.20.0.linux-amd64/alertmanager.yml Restart=on-failure [Install] WantedBy=multi-user.target
[root@blog alertmanager-0.20.0.linux-amd64]# systemctl daemon-reload
[root@blog alertmanager-0.20.0.linux-amd64]# systemctl start alertmanager.service
[root@blog alertmanager-0.20.0.linux-amd64]# systemctl status alertmanager.service
[root@blog alertmanager-0.20.0.linux-amd64]# ss -lntp | grep alertmanager LISTEN 0 1024 *:9093 *:* users:(("alertmanager",pid=29807,fd=6)) LISTEN 0 1024 *:9094 *:* users:(("alertmanager",pid=29807,fd=3))
http://121.122.123.47:9093/
六,配置prometheus使用alertmanager报警
[root@blog ~]# mkdir -p /data/prometheus/rules [root@blog ~]# cd /data/prometheus/rules/ [root@blog rules]# vi rule.yml
groups: - name: alert-rules.yml rules: - alert: InstanceStatus # alert 名字 expr: up{job="118node"} == 0 # 判断条件 for: 10s # 条件保持 10s 才会发出 alter labels: # 设置 alert 的标签 severity: "critical" annotations: # alert 的其他标签,但不用于标识 alert description: 服务器 已当机超过 20s summary: 服务器 运行状态
[root@blog ~]# vi /usr/local/soft/prometheus-2.18.1.linux-amd64/prometheus.yml
alerting: alertmanagers: - static_configs: - targets: - localhost:9093 rule_files: - "/data/prometheus/rules/rule.yml"
说明:指定了报警服务的地址/规则文件的地址
七,重启prometheus和alertmanager,使配置生效
[root@blog ~]# systemctl restart prometheus.service
[root@blog ~]# systemctl restart alertmanager.service
八,测试发送邮件效果:
http://121.122.123.47:9090/alerts
[root@cacheServer ~]# ps auxfww | grep node root 6440 0.3 0.0 718788 16520 ? Sl Jun05 14:13 /usr/local/soft/node_exporter-1.0.0.linux-amd64/node_exporter [root@cacheServer ~]# kill 6440 [root@cacheServer ~]# ps auxfww | grep node
九,查看prometheus的版本
[root@blog ~]# /usr/local/soft/prometheus-2.18.1.linux-amd64/prometheus --version prometheus, version 2.18.1 (branch: HEAD, revision: ecee9c8abfd118f139014cb1b174b08db3f342cf) build user: root@2117a9e64a7e build date: 20200507-16:51:47 go version: go1.14.2
十,查看linux的版本
[root@blog ~]# cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)
以上是关于linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)的主要内容,如果未能解决你的问题,请参考以下文章
linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)
linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)
linux(centos8):为prometheus安装grafana(grafana-7.0.3)
linux(centos8):为prometheus安装grafana(grafana-7.0.3)