当前位置: 首页 > news >正文

Prometheus-v2.45.0 + 钉钉告警

目录

1. 创建一个钉钉内部群

2. 添加自定义机器人 

3. 配置钉钉发送告警服务

4. 配置alertmanager,接入dingding

5. 配置告警消息发送模板

6. 修改配置规则文件 


续接上篇:https://blog.csdn.net/Lzcsfg/article/details/140851688

相关软件包链接:https://pan.baidu.com/s/1b3AzJBNtIt1PfjNi1eE7fg?pwd=jcj8 
提取码:jcj8 
 

1. 创建一个钉钉内部群

2. 添加自定义机器人 

3. 配置钉钉发送告警服务

传入软件包prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

[root@localhost ~]# cd /opt

解压软件包

[root@localhost opt]# tar xf prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

 将目录名字改成短点的

[root@localhost opt]# mv prometheus-webhook-dingtalk-2.1.0.linux-amd64 webhook-dingtalk
[root@localhost opt]# cd webhook-dingtalk/

 拷贝配置文件并重命名 

[root@localhost webhook-dingtalk]# cp config.example.yml config.yml

编辑配置文件

[root@localhost webhook-dingtalk]# vim config.yml
# 配置块,用于定义钉钉机器人的Webhook
targets:# 第一个Webhook配置,用于发送消息,但没有启用@提醒功能webhook1:url: https://oapi.dingtalk.com/robot/send?access_token=2a6adaa1f19ef7ac61e57410c9f2f6c9b00c417842a766d99765f644f80d48d0secret: SEC85d2833b679817a49b1197aa0f5699e6c0e000eb5cb90e74da756c32b48eee75# 第二个Webhook配置,用于发送消息,并启用所有用户的@提醒功能another_webhook_mention_all:url: https://oapi.dingtalk.com/robot/send?access_token=2a6adaa1f19ef7ac61e57410c9f2f6c9b00c417842a766d99765f644f80d48d0mention:all: true  # 启用所有用户的@提醒# 第三个Webhook配置,用于发送消息,并指定需要@提醒的手机号码webhook_mention_users:url: https://oapi.dingtalk.com/robot/send?access_token=2a6adaa1f19ef7ac61e57410c9f2f6c9b00c417842a766d99765f644f80d48d0mention:mobiles: ['130xxxxx151']  # 指定需要@提醒的手机号码

启动

[root@localhost webhook-dingtalk]# ll
total 18744
-rw-r--r-- 1 3434 3434    11358 Apr 21  2022 LICENSE
-rw-r--r-- 1 3434 3434     1299 Apr 21  2022 config.example.yml
-rw-r--r-- 1 root root      265 Aug  2 02:32 config.yml
drwxr-xr-x 4 3434 3434       34 Apr 21  2022 contrib
-rwxr-xr-x 1 3434 3434 19172733 Apr 21  2022 prometheus-webhook-dingtalk[root@localhost webhook-dingtalk]# ./prometheus-webhook-dingtalk --config.file="config.yml"
# 后台启动命令使用 nohup ./prometheus-webhook-dingtalk --config.file="config.yml" &# 会监听8060端口
[root@localhost webhook-dingtalk]# ss -tnlp
State         Recv-Q         Send-Q                 Local Address:Port                 Peer Address:Port        Process                                         
LISTEN        0              128                          0.0.0.0:22                        0.0.0.0:*            users:(("sshd",pid=819,fd=3))                  
LISTEN        0              128                             [::]:22                           [::]:*            users:(("sshd",pid=819,fd=4))                  
LISTEN        0              4096                               *:3000                            *:*            users:(("grafana",pid=6705,fd=10))             
LISTEN        0              4096                               *:9100                            *:*            users:(("node_exporter",pid=6303,fd=3))        
LISTEN        0              4096                               *:9093                            *:*            users:(("alertmanager",pid=6835,fd=8))         
LISTEN        0              4096                               *:9094                            *:*            users:(("alertmanager",pid=6835,fd=3))         
LISTEN        0              4096                               *:9090                            *:*            users:(("prometheus",pid=6873,fd=7))           
LISTEN        0              4096                               *:8060                            *:*            users:(("prometheus-webh",pid=6996,fd=3)) 

4. 配置alertmanager,接入dingding

[root@localhost webhook-dingtalk]# vim /opt/alertmanager/alertmanager.yml
receivers:- name: 'dingding'  # 接收器的名字,定义为 'dingding'webhook_configs:- url: 'http://192.168.226.29:8060/dingtalk/webhook1/send'send_resolved: true  # 当报警被解决时,也会发送通知route:receiver: 'dingding'  # 默认的接收器是 'dingding'group_by: ['alertname']  # 报警分组的依据字段,这里按 'alertname' 分组group_wait: 30s  # 第一个报警的等待时间,在此期间新的报警会被加入到同一组group_interval: 1m  # 每组之间的最小等待时间repeat_interval: 5m  # 重复报警发送的时间间隔templates:- /opt/alertmanager/tmpl/*.tmpl  # 指定模板文件的路径,用于格式化报警通知的内容inhibit_rules:- source_match:severity: 'critical'  # 源报警的匹配条件:严重性为 'critical'target_match:severity: 'warning'  # 目标报警的匹配条件:严重性为 'warning'equal: ['alertname', 'dev', 'instance']  # 抑制规则生效的条件,只有当 'alertname'、'dev' 和 'instance' 三个字段相同时,规则才会生效

重启alertmanager

[root@localhost webhook-dingtalk]# cd /opt/alertmanager/
[root@localhost alertmanager]# nohup ./alertmanager &

5. 配置告警消息发送模板

[root@localhost alertmanager]# vim /opt/alertmanager/tmpl/email.tmpl
{{ define "__subject" }}[告警] {{ .Status | toUpper }}: {{ .CommonLabels.alertname }}{{ end }}{{ define "__description" }}
告警名称: {{ .CommonLabels.alertname }}
主机: {{ .CommonLabels.instance }}
告警级别: {{ .CommonLabels.severity }}
开始时间: {{ .StartsAt }}
结束时间: {{ .EndsAt }}
描述: {{ .CommonAnnotations.description }}
{{ end }}{{ define "__message" }}
{"msgtype": "markdown","markdown": {"title": "{{ template "__subject" . }}","text": "## {{ template "__subject" . }}\n\n{{ template "__description" . }}"}
}
{{ end }}{{ define "dingtalk.default.message" }}{{ template "__message" . }}{{ end }}

6. 修改配置规则文件 

 在prometheus中的prometheus.yml指定了规则文件位置

[root@localhost alertmanager]# cd /opt/prometheus
[root@localhost prometheus]# vim ./rules/disk.yml
groups:- name: 'disk-usage-alerts'# 这是告警组的名称rules:- alert: DiskSpaceUsageHigh# 这是告警规则的名称expr: 100 - (node_filesystem_avail_bytes / node_filesystem_size_bytes * 100) > 10# 告警表达式检查磁盘使用率是否超过10%for: 30s# 如果条件持续30秒,则触发告警labels:severity: 'critical'# 为告警添加标签,指定严重性为“关键”annotations:summary: '磁盘使用率过高: {{ $labels.instance }}'# 摘要注释,描述告警的内容,包括实例名称description: '磁盘使用率超过阈值: {{ $value }}%'# 描述注释,给出具体的磁盘使用率

重启prometheus 

[root@localhost alertmanager]# prometheus restart

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Python初学者必须掌握的基础知识点
  • 汽车电控诊断DTC-Status状态位
  • Spring Boot 应用中的事务管理与 Feign 调用问题分析及解决
  • C#使用NPOI进行Excel和Word文件处理(一)
  • PVE虚拟机被锁定:VM is locked解决方法
  • QtQuick Text-文本格式
  • Windows 读取wav文件字节流并播放
  • 多旋翼+四光吊舱:5Kg负载无人机技术详解
  • MySQL:行级锁
  • 车载音频开发(一):从看懂wav开始
  • DUILib 创建自定义文本编辑控件
  • 【Python】模块
  • 《Windows API每日一练》24.1 WinSock简介
  • Java中的notify()与notifyAll()区别
  • 探展2024世界人工智能大会之合合信息扫描黑科技~
  • JS 中的深拷贝与浅拷贝
  • [译]CSS 居中(Center)方法大合集
  • 【407天】跃迁之路——程序员高效学习方法论探索系列(实验阶段164-2018.03.19)...
  • 【个人向】《HTTP图解》阅后小结
  • Map集合、散列表、红黑树介绍
  • Nacos系列:Nacos的Java SDK使用
  • Vue--数据传输
  • 我的zsh配置, 2019最新方案
  • 项目管理碎碎念系列之一:干系人管理
  • 最简单的无缝轮播
  • 资深实践篇 | 基于Kubernetes 1.61的Kubernetes Scheduler 调度详解 ...
  • ​如何在iOS手机上查看应用日志
  • # dbt source dbt source freshness命令详解
  • #设计模式#4.6 Flyweight(享元) 对象结构型模式
  • ()、[]、{}、(())、[[]]等各种括号的使用
  • (1)Android开发优化---------UI优化
  • (19)夹钳(用于送货)
  • (Charles)如何抓取手机http的报文
  • (ctrl.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“
  • (Git) gitignore基础使用
  • (pytorch进阶之路)CLIP模型 实现图像多模态检索任务
  • (第二周)效能测试
  • (转)Windows2003安全设置/维护
  • (最全解法)输入一个整数,输出该数二进制表示中1的个数。
  • .dwp和.webpart的区别
  • .helper勒索病毒的最新威胁:如何恢复您的数据?
  • .mp4格式的视频为何不能通过video标签在chrome浏览器中播放?
  • .Net 8.0 新的变化
  • .NET Core WebAPI中封装Swagger配置
  • .NET Core跨平台微服务学习资源
  • .net 连接达梦数据库开发环境部署
  • .NET 漏洞分析 | 某ERP系统存在SQL注入
  • .NET命令行(CLI)常用命令
  • .NET未来路在何方?
  • .NET中GET与SET的用法
  • @select 怎么写存储过程_你知道select语句和update语句分别是怎么执行的吗?
  • @Transient注解
  • @基于大模型的旅游路线推荐方案
  • [ web基础篇 ] Burp Suite 爆破 Basic 认证密码
  • [20150707]外部表与rowid.txt