侧边栏壁纸
博主头像
一揽芳华 博主等级

行动起来,活在当下

  • 累计撰写 265 篇文章
  • 累计创建 24 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

5.7.PrometheusAlert(新增)

芳华是个男孩!
2024-10-14 / 0 评论 / 0 点赞 / 10 阅读 / 0 字
广告 广告

title: 5.7.PrometheusAlert(新增)
order: 33

icon: lightbulb

注:这节课学习更多的告警通知方式。钉钉、邮件、微信和之前学过的方式(二选一)

一、环境介绍

主机名

IP地址

系统

说明

localhost

192.168.11.60

Ubuntu 20.04

docker方式安装的prometheus

1、环境准备

安装docker

安装docker-compose

二、PrometheusAlert

1、PrometheusAlert介绍

github地址

PrometheusAlert是开源的运维告警中心消息转发系统,支持主流的监控系统Prometheus、Zabbix,日志系统Graylog2,Graylog3、数据可视化系统Grafana、SonarQube。阿里云-云监控,以及所有支持WebHook接口的系统发出的预警消息,支持将收到的这些消息发送到钉钉,微信,email,飞书,腾讯短信,腾讯电话,阿里云短信,阿里云电话,华为短信,百度云短信,容联云电话,七陌短信,七陌语音,TeleGram,百度Hi(如流)等。

2、二进制安装(和docker安装二选一)

获取最新的安装包地址

#安装二进制安装包
wget https://github.com/feiyu563/PrometheusAlert/releases/download/v4.8.2/linux.zip

#安装解压工具
apt install unzip

#解压
unzip linux.zip

ls -l

#移动并改名
mv linux/ /opt/prometheus/PrometheusAlert

#授权执行权限
chmod +x /opt/prometheus/PrometheusAlert/PrometheusAlert

修改配置文件

vim /opt/prometheus/PrometheusAlert/conf/app.conf 

修改内容如下:具体根据实际修改

#登录用户名
login_user=admin
#登录密码
login_password=password

#是否开启钉钉告警通道,可同时开始多个通道0为关闭,1为开启
open-dingding=1
#默认钉钉机器人地址
ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxx
#是否开启 @所有人(0为关闭,1为开启)
dd_isatall=1

#是否开启微信告警通道,可同时开始多个通道0为关闭,1为开启
open-weixin=1
#默认企业微信机器人地址
wxurl=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx

#是否开启飞书告警通道,可同时开始多个通道0为关闭,1为开启
open-feishu=1
#默认飞书机器人地址
fsurl=https://open.feishu.cn/open-apis/bot/hook/xxxxxxxxx

创建一个prometheus用户:

useradd -M -s /usr/sbin/nologin prometheus

更改prometheusalert文件夹权限:

chown prometheus:prometheus -R /opt/prometheus

创建 systemd 服务

cat > /etc/systemd/system/PrometheusAlert.service << "EOF"
[Unit]
Description=prometheus-alert
Documentation=https://github.com/feiyu563/PrometheusAlert

[Service]
User=prometheus
Group=prometheus
Restart=on-failure
WorkingDirectory=/opt/prometheus/PrometheusAlert
ExecStart=/opt/prometheus/PrometheusAlert/PrometheusAlert

[Install]
WantedBy=multi-user.target
EOF

启动 PrometheusAlert

systemctl daemon-reload
systemctl start PrometheusAlert.service

加入到开机自启动

systemctl enable PrometheusAlert.service

检查

systemctl status PrometheusAlert.service

查看 prometheusalert的日志以进行故障排除:

journalctl -u PrometheusAlert.service -f

3、docker安装(和二进制安装二选一,推荐)

安装

cd /data

git clone https://gitee.com/linge365/docker-compose.git

cd docker-compose/prometheus-alert

docker-compose up -d

数据持久化目录

ls -l /var/lib/docker/volumes/prometheus-alert_prometheus_alert_data/_data/

drwxr-xr-x 7 root root     4096 Jul 17 11:23 ./
drwx-----x 3 root root     4096 Jul 17 11:23 ../
drwxr-xr-x 2 root root     4096 Jul 18 17:03 conf/
drwxr-xr-x 2 root root     4096 Jul 17 11:23 db/
-rw-r--r-- 1 root root      980 Jun 24  2022 docker-entrypoint.sh
drwxr-xr-x 2 root root     4096 Jul 18 00:00 logs/
-rwxr-xr-x 1 root root 28720464 Jun 24  2022 PrometheusAlert*
drwxr-xr-x 4 root root     4096 Jul 17 11:23 static/
drwxr-xr-x 2 root root     4096 Jul 17 11:23 views/

修改配置文件

增加腾讯云、华为云、阿里云的短信,电话接收告警信息是修改配置文件

vim /var/lib/docker/volumes/prometheus-alert_prometheus_alert_data/_data/conf/app.conf

重启PrometheusAlert

docker restart prometheus-alert

4、PrometheusAlert web管理

登录web

登录地址:http://192.168.11.60:8080/login

登录帐号密码在配置文件app.conf中

#登录用户名
login_user=admin
#登录密码
login_password=password

告警测试

  • 注意:点击告警测试后飞书、钉钉、微信都能正常接收到信息,表示之前的配置没有问题

5、Alertmanager配置

修改alertmanager/config.yml增加如下配置:

  # 全局报警组,这个参数是必选的
  receiver: prometheusalert-fs或prometheusalert-wx或prometheusalert-dd


receivers:
- name: 'prometheusalert-wx'
  webhook_configs:
  - url: 'http://10.0.0.60:8080/prometheusalert?type=wx&tpl=prometheus-wx'
    send_resolved: true

- name: 'prometheusalert-dd'
  webhook_configs:
  - url: 'http://10.0.0.60:8080/prometheusalert?type=dd&tpl=prometheus-dd'
    send_resolved: true

- name: 'prometheusalert-fs'
  webhook_configs:
  - url: 'http://10.0.0.60:8080/prometheusalert?type=fs&tpl=prometheus-fs'
    send_resolved: true

url参数中 ddurl、wxurl、fsurl、phone、email、wxuser、wxparty、wxtag、groupid 等可不写,如不写这些参数,则会默认去读取配置文件中app.conf的对应参数发送消息。

重新加载配置

curl -X POST http://localhost:9093/-/reload

这样当Prometheus的告警规则触发时,会把告警信息发送给Alertmanager,Alertmanager根据配置把这个告警信息发送到指定的微信、钉钉、飞书、手机、短信上。

6、测试接收告警信息

手动发送告警消息给alertmanager

#!/usr/bin/env bash
alerts1='[
  {
    "labels": {
       "alertname": "DiskRunningFull",
       "dev": "sda1",
       "instance": "example1",
       "severity": "critical"  
     },
     "annotations": {
        "description": "The disk sda1 is running full",
        "summary": "please check the instance example1"
      }
  }
]'
curl -XPOST -d"$alerts1" http://localhost:9093/api/v1/alerts

钉钉,微信,飞书能接收到表示正常。

0
广告 广告

评论区