【prometheus+alertmanager+qq邮箱、企业微信、飞书告警管理】

本文详细介绍了如何利用Prometheus+Alertmanager配置告警管理,包括通过qq邮箱、企业微信和飞书进行告警通知。首先,讲述了如何获取qq邮箱和企业微信的授权码,接着部署Alertmanager并配置qq邮箱、微信和飞书告警。然后,讨论了自定义告警规则的方法,并提供了在Grafana中设置PostgreSQL死锁监控的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系列文章目录

第一章 生产环境部署prometheus+grafana+kafka+redis+nginx+node+postgres



前言

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/
</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@王先生1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值