系列文章目录
第一章 生产环境部署prometheus+grafana+kafka+redis+nginx+node+postgres
prometheus+alertmanager告警管理
前言
alert官方配置说明文档:https://prometheus.io/docs/alerting/latest/configuration/
Prometheus官方下载地址(很丰富):https://prometheus.io/download/
rules基本配置:https://awesome-prometheus-alerts.grep.to/rules
qq邮箱获取授权码帮助:https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
企业微信:https://work.weixin.qq.com/
一、根据qq邮箱帮助文档获取授权码
1、qq邮箱获取授权码
2、企业微信获取授权码
1、登录web端企业微信–应用管理–创建应用
2.应用名称、头像、介绍、成员根据实际要求选。
3、创建完成后收集corpid(企业id)、 AgentId、Secret、账号
二、部署alertmanager
1.下载、安装alertmanager
mv alertmanager-0.24.0.linux-amd64.tar.gz /u01/
mkdir alertmanager
tar -zxvf alertmanager-0.24.0.linux-amd64.tar.gz -C alertmanager
cd alertmanager/alertmanager-0.24.0.linux-amd64/
配置qq邮箱alert
global: ##全局配置
resolve_timeout: 5m ##当告警的状态由firing变为resolve时,需等待5min,如果报警未更新,则声明该告警已解决。可略微调高阈值避免
smtp_smarthost: 'smtp.qq.com:465'
smtp_from: '134****626@qq.com'
smtp_auth_username: '134****626@qq.com'
smtp_auth_password: 'zzsijsyobcddbaah' # 这个密码需要生成,非QQ密码
smtp_require_tls: false
route:
group_by: ['service','alertname','cluster'] ##根据label进行分组。--cluster可创建集群
group_wait: 30s ##触发告警后,等待30s发送
group_interval: 10s ##两组告警发送的时间间隔
repeat_interval: 1h ##重复告警发送的时间间隔
receiver: 'email' #默认接收者
receivers: ###告警的处理方式email
- name: 'email'
#webhook_configs: ##告警转发到下列url
# - url: 'http://127.0.0.1:5001/'
email_configs: ##告警转发到对应邮箱地址
- to: '134****626@qq.com'
inhibit_rules: ###添加抑制规则
- source_match: ####根据label匹配源告警
severity: 'critical'
target_match: ####根据label匹配目的告警
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
微信配置:
需要修改route的receiver:
receivers:
- name: 'wechat'
# webhook_configs:
# - url: 'http://127.0.0.1:5001/'
wechat_configs:
- send_resolved: true
corp_id: "ww4489c7c1e62"
#to_party: 部门id
to_user: "WangChao"
agent_id: 1000002
api_secret: "mYYWhtWWF4hZ-eRm_BRlKwNReuCq6m8"
message: '{
{ template "wechat.default.message" . }}'
飞书配置
最大的坑就是飞书传参必须有头部信息,像跳过这个坑就得借助工具了,我用的PrometheusAlert
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"request example"}}' https://open.feishu.cn/open-apis/bot/v2/hook/f7b50f15-0c78-4378-a74c-185d445f3e92
就是他!!!!!!!!!!!
headers:
Content-Type: 'application/json'
下载linux.zip
wget https://github.com/feiyu563/PrometheusAlert/releases/download/v4.7/linux.zip && unzip linux.zip &&cd linux/
</