Prometheus实现钉钉报警

news/2025/3/15 4:53:17/

1、Prometheus实现钉钉报警

1.1 Prometheus环境

# my global config
global:scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Alertmanager configuration
alerting:alertmanagers:- static_configs:- targets:- 192.168.204.195:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:# - "first_rules.yml"# - "second_rules.yml"- "rule/*.yml" # A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: "prometheus"# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:- targets: ["localhost:9090"]# 采集JVM监控数据- job_name: pushgatewaystatic_configs:- targets: ['192.168.204.195:9091']labels: instance: pushgateway
groups:
- name: node_rulerules:- alert: node memory usagesexpr: node_memory_usages > 20for: 10slabels:severity: highannotations:summary: "【监控告警】{{ $labels.exported_instance }}: 空间使用率异常"description: "【监控告警】{{ $labels.exported_instance }}: 空间使用率异常,请及时处理。"

启动情况:

在这里插入图片描述

1.2 pushgateway环境

启动情况:

在这里插入图片描述

1.3 自定义机器人并获取自定义机器人Webhook地址

1、首先创建一个群聊。

进入到钉钉软件的主页面后,点击右上角的加号按钮。

弹出加号里面的选项后,点击上面的发起群聊按钮。

进入到发起群聊界面后选择内部项目群,选择属于个人,点击上面的选择联系人选项。

进入到联系人界面后,选择要加入群聊的好友,最后点击右下角确定即可。

2、选择需要添加机器人的群聊,然后依次单击群设置 > 智能群助手 > 添加机器人。

3、点击添加机器人。

在这里插入图片描述

4、选择自定义。

在这里插入图片描述

5、点击添加。

在这里插入图片描述

6、输入相关信息,点击完成。

在这里插入图片描述

在这里插入图片描述

加签生成的随机码需要保存,后面会使用到。

7、点击完成。

在这里插入图片描述

这样我们就成功添加了自定义钉钉机器人并获取了 Webhook 地址。

获取到的Webhook的地址如下:

https://oapi.dingtalk.com/robot/send?access_token=57af98ce4cea66cb829df72c531efe093c6a254134ecf555f1

1.4 钉钉报警插件

访问github下载最新的插件(prometheus-webhook-dingtalk):

https://github.com/timonwong/prometheus-webhook-dingtalk/

这里下载 prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v2.1.0/prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

上传到服务器进步解压:

$ tar -xvf prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

修改配置文件:

$ vim config.example.yml
# 将内容修改为
# Targets, previously was known as "profiles"
targets:webhook1:url: https://oapi.dingtalk.com/robot/send?access_token=57af98ce4cea66cb829df72c531efe093c6a254134ecf555f1# secret for signaturesecret: SEC5d2ad4bd4cea26830145472cdd7c8dda5b8bea57a029f4f7db7524webhook_mention_users:url: https://oapi.dingtalk.com/robot/send?access_token=57af98ce4cea66cb829df72c531efe093c6a254134ecf555f1mention:mobiles: ['18210820213']

启动:

$ nohup ./prometheus-webhook-dingtalk --config.file="config.example.yml" >> nohup.out 2>&1 &

1.5 alertmanager环境

global:resolve_timeout: 5m
route:group_by: ['alertname']group_wait: 15sgroup_interval: 30srepeat_interval: 2mreceiver: 'web.hook'
receivers:- name: 'web.hook'webhook_configs:# prometheus-webhook-dingtalk的地址- url: 'http://192.168.204.195:8060/dingtalk/webhook1/send' send_resolved: true
inhibit_rules:- source_match:severity: 'critical'target_match:severity: 'warning'equal: ['alertname', 'dev', 'instance']

启动情况:

在这里插入图片描述

1.6 触发报警

触发告警前:

在这里插入图片描述

# 执行该脚本触发告警
cat <<EOF | curl --data-binary @- http://192.168.204.195:9091/metrics/job/test_job/instance/test_instance
node_memory_usages 36
node_memory_total 36000
EOF

触发告警后:

在这里插入图片描述

在这里插入图片描述

钉钉接收到的消息:

在这里插入图片描述

如果恢复告警也会收到信息:

在这里插入图片描述

至此钉钉告警完成。


http://www.ppmy.cn/news/911439.html

相关文章

如何使用Java开发高性能的分布式系统

写在前面&#xff1a; 随着现代应用需求的不断演进&#xff0c;传统的单体应用已经无法满足对高容量、高并发和高可用性的需求。为了应对这些挑战&#xff0c;分布式系统应运而生。简而言之&#xff0c;分布式系统是由多个计算机节点组成的系统&#xff0c;这些节点通过网络进…

博德之门2增强版存档_博德之门2:增强版 存档位置及修改方法

虽然博德之门系列游戏是比较老的游戏&#xff0c;但游戏性还是非常不错的&#xff0c;可能对画面党来说游戏有些难接受&#xff0c;不过真正融入游戏还是会发现这款作品的乐趣所在&#xff0c;最近不少玩家问到游戏存档位置&#xff0c;下面是详细解析。 存档位置及修改方法 第…

文件操作存档2

将0-127之间的ASCII字符写入demo.bin二进制文件中&#xff0c;并读取内容显示 #include <stdio.h> #include <stdlib.h>int main() {FILE *fp;char ch;int i;if( (fp fopen("demo.bin","wb")) NULL)//以二进制写方式打开文件{printf("…

[Unity存档系统]简单介绍Unity常见存档系统二JSON以及使用方法

学习目标&#xff1a; 如果你和我同样苦恼于游戏相关的数据怎么存储与读取&#xff0c;那么不妨看看这个up主有关Unity存档系统的教程。[Unity] 存档系统 Part 1 | PlayerPrefs | Unity初学者系列教程 | 数据存取 | 存档读档 | Save&Load_哔哩哔哩_bilibili在本视频中你将学…

matlab: 03(2) cell、存档和读档

学习素材&#xff1a;MATLAB教程_台大郭彦甫&#xff08;14课&#xff09;原视频补档 MATLAB教學 - 04变数&#xff08;变量&#xff09;与档案存取_哔哩哔哩_bilibili &#xff08;部分素材使用视频截图&#xff09; 目录 一、cell 1.两种构造方法 2.matrix into a cell …

Unity存档

Unity3D输出Android透明背景的实现&#xff1a; 1.Player Settings -> Resolution and Presentation -> Render Over Native UI //可不用设置此选项 2.相机的camera flag设为Solid color 3.相机的background RGBA values to (0,0,0,0) 4.Unity对应的activity标签…

闪客工具:ghostcat

一套不错的工具类库&#xff0c;里面包含了很多不错新鲜概念。 AS3的通用工具类库(AS3 library of generic tools) http://wiki.9ria.com/index.php/GhostCat#.E4.BB.8B.E7.BB.8D

计算机领域闪客是指,第一单元闪客之门.doc

第一单元闪客之门 第1单元 闪客之门(第1-3课) 一、单元概述 本单元通过学生对Flash 8的逐步了解&#xff0c;初步感受制作动画的乐趣&#xff0c;体验踏入闪客之门的喜悦。 在本单元中&#xff0c;通过任务驱动、竞赛等方式&#xff0c;充分调动学生的参与热情与创新意识&#…