创建企业微信应用

注册企业微信:访问https://work.weixin.qq.com/,注册企业,随便填,不需要认证

创建应用







创建告警配置

vim /usr/local/prometheus-2.1/rule2.yml
groups:
- name: cluster
rules:
- alert: HIGHCPU
expr: (1-irate(node_cpu_seconds_total{mode="idle",job="export_test2"}[1m]))*100 > 10
for: 5s
labels:
for: 'highcpu'
annotations:
description: CPU MORE THAN 10%
summary: 'cpu more than 10%'

在Prometheus的配置中添加以上规则

vim /usr/local/prometheus-2.1/prometheus.yml
rule_files:
- "/usr/local/prometheus-2.1/rule.yml"
- "/usr/local/prometheus-2.1/rule2.yml" #添加此规则

创建报警策略

 vim /usr/local/alertmanager-0.15.2/alertmanager.yml
global:
wechat_api_corp_id: 'ww0cxxxxf5b5'
wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
wechat_api_secret: 'K4jHxxxxxxxL4_4Xj-lvQ' route:
group_by: ['alertname']
group_wait: 10s
group_interval: 5s
repeat_interval: 10s
receiver: 'weixin'
routes:
- receiver: 'weixin'
match:
severity: 'critical'
- receiver: 'weixin'
match:
for: 'highcpu'
receivers:
- name: 'weixin'
wechat_configs:
- send_resolved: true #告警恢复发送通知
to_party: '1'
agent_id: '1000003'
corp_id: 'ww0cxxxxf5b5'
api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
api_secret: 'K4jHxxxxxxxL4_4Xj-lvQ'

corp_id :在企业微信中我的企业 --> 企业信息 --> 企业ID

agent_id 与 api_secret :点击创建的应用Prometheus,可以看到AgentId 与 Secret

to_party:是指发送信息的部门ID

api_url : 企业微信地址

重启prometheus 与 alertmanager 服务

测试

在被监控机上拉高cpu

cat /dev/urandom | md5sum

企业微信收到告警信息

[FIRING:1] HIGHCPU (0 highcpu node2 export_test2 idle)
CPU MORE THAN 10% cpu more than 10%
Alerts Firing:
Labels:
- alertname = HIGHCPU
- cpu = 0
- for = highcpu
- instance = node2
- job = export_test2
- mode = idle
Annotations:
- description = CPU MORE THAN 10%
- summary = cpu more than 10%
Source: http://centos1.com:9090/graph?g0.expr=%281+-+irate%28node_cpu_seconds_total%7Bjob%3D%22export_test2%22%2Cmode%3D%22idle%22%7D%5B1m%5D%29%29+%2A+100+%3E+10&g0.tab=1 AlertmanagerUrl:
http://centos1.com:9093/#/alerts?receiver=weixin

cpu恢复,收到通知信息

[RESOLVED] HIGHCPU (0 highcpu node2 export_test2 idle)
CPU MORE THAN 10% cpu more than 10% Alerts Resolved:
Labels:
- alertname = HIGHCPU
- cpu = 0
- for = highcpu
- instance = node2
- job = export_test2
- mode = idle
Annotations:
- description = CPU MORE THAN 10%
- summary = cpu more than 10%
Source: http://centos1.com:9090/graph?g0.expr=%281+-+irate%28node_cpu_seconds_total%7Bjob%3D%22export_test2%22%2Cmode%3D%22idle%22%7D%5B1m%5D%29%29+%2A+100+%3E+10&g0.tab=1 AlertmanagerUrl:
http://centos1.com:9093/#/alerts?receiver=weixin

注:如果你的企业微信收不到告警信息,并坚信配置没有问题,那么可以重新注册一个企业微信试试。

抑制规则试用

注:本文中配置抑制的两个监控项没有直接逻辑联系,纯属测试抑制功能

添加新的告警配置

vim /usr/local/prometheus-2.1/rule2.yml  在尾部添加以下配置
- name: test
rules:
- alert: go_goroutines
expr: go_goroutines{instance="node2",job="export_test2"} > 5
for: 10s
labels:
severity: 'warning'
annotations:
description: go_goroutines > 5

添加以上规则的通知方式与抑制配置

vim /usr/local/alertmanager-0.15.2/alertmanager.yml
global:
wechat_api_corp_id: 'ww0xxxxxxx5b5'
wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
wechat_api_secret: 'K4jH8xxxxxxxxxxxXj-lvQ' #templates:
# - '/alertmanager/template/wechat.tmpl' route:
group_by: ['alertname']
group_wait: 10s
group_interval: 5s
repeat_interval: 10s
receiver: 'weixin'
routes:
- receiver: 'weixin'
match:
severity: 'critical'
- receiver: 'weixin'
match:
for: 'highcpu'
- receiver: 'weixin' #新添加通知方式(三行)
match:
severity: 'warning'
receivers:
- name: 'weixin'
wechat_configs:
- send_resolved: true
to_party: '1'
agent_id: '1000003'
corp_id: 'ww0xxxxxxxxx5b5'
api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
api_secret: 'K4jH8xxxxxxxxxxxxxxxxxxxXj-lvQ' inhibit_rules: #新添加抑制规则
- source_match:
for: 'highcpu'
target_match:
severity: 'warning'
equal: ['instance','job']

实现效果为:当cpu与go_goroutines都满足告警条件,cpu发出告警,go_goroutines被抑制

当已经发送的告警通知匹配到target_match和target_match_re规则,当有新的告警规则如果满足source_match或者定义的匹配规则,并且以发送的告警与新产生的告警中equal定义的标签完全相同,则启动抑制机制,新的告警不会发送。

静默规则试用

在alertmanager的web界面创建临时静默规则,将label为 for:highcpu 的告警静默,web界面 silences --> New Silence

注:以下start与end使用的是UTC时间,比北京时间晚8h



添加静默规则后在指定时间段内不再收到label为 for:highcpu 的告警信息。

Prometheus 企业微信报警/inhibit抑制 /静默(二)的更多相关文章

  1. Prometheus(五):Prometheus+Alertmanager 配置企业微信报警

    此处默认已安装Prometheus服务,服务地址:192.168.56.200  一.设置企业微信 1.1.企业微信注册(已有企业微信账号请跳过) 企业微信注册地址:https://work.weix ...

  2. Nagios通过企业微信报警

    主要分两部分进行: 注册企业微信,自建应用,获取与发送消息相关的信息: 编写调用微信API脚本(bash),配置Nagios微信报警: 一.企业微信 1.注册企业微信:https://work.wei ...

  3. zabbix企业微信报警实现

    企业微信配置 # 注册 企业微信注册地址:https://work.weixin.qq.com 笔者注册的企业微信名称为 5iik # 配置 # 在主干5iik(企业名称)下添加子部门(监控组),并将 ...

  4. Zabbix4.2.0使用Python连接企业微信报警

    目录 1. 配置企业微信 2. 脚本配置 2.1 安装python依赖的库 2.2 编写脚本 2. 搭建FTP 3. 配置Zabbix监控FTP 3.1 添加FTP模板 3.2 添加报警媒介 3.3 ...

  5. 配置zabbix通过微信报警企业微信报警

    如今势态: 报警的方式可谓是八仙过海各显神通,如电话报警,短信报警,邮件报警,QQ报警,微信报警等等. 电话报警:一般都是使用别的平台的工具,平台给你提供一个接口供你使用,大多数为限量收费款 短信报警 ...

  6. Zabbix 3.0 配置企业微信报警(注册---测试)

    一.申请企业微信 1.登录企业微信官网,点击企业注册 二.配置企业微信 1.邀请管理员使用企业微信,如果有多个人直接添加新成员 2.管理员收到邀请,下载手机版企业微信,使用微信号登陆即可 3.创建应用 ...

  7. zabbix配置企业微信报警

    +++++++++++++++++++++++++++++++++++++++++ 1. 工作中最长使用的就是微信,普及,开源,而且免费!!! 2. 在企业微信中要记录的值: · 部门id · 企业i ...

  8. Zabbix4.0报警配置-企业微信报警

    一:前期准备 1.1:企业号注册 https://qy.weixin.qq.com/  微信调用接口说明 http://qydev.weixin.qq.com/wiki/index.php?title ...

  9. Zabbix 3.0 配置企业微信报警(配置zabbix-web)

    一.添加报警媒体类型 Name:自定义 Type:选择script Scripts name:填写脚本名称 Script parameters:脚本参数 --corpid=XXX --corpsecr ...

随机推荐

  1. [Linux]标准IO全缓冲和行缓冲

    概述 标准IO中,标准错误是不带缓冲的.若是指向终端设备的流才是行缓冲的,否则是全缓冲的. 行缓冲也可以分配缓冲区,当遇到超大行(超过缓冲区的行),缓冲区内容也会优先刷出. 示例 #include & ...

  2. The Apache Tomcat installation at this directory is version 8.5.40. A Tomcat 8.0 installation is expected.

    问题描述 Eclipse 配置 Apache Tomcat 8.5.40(8.0.x 以上版本),会报如下错误信息: 解决方法 1)在 Apache Tomcat 的安装目录中找到 lib 目录下的 ...

  3. 【算法】Attention is all you need

    Transformer 最近看了Attention Is All You Need这篇经典论文.论文里有很多地方描述都很模糊,后来是看了参考文献里其他人的源码分析文章才算是打通整个流程.记录一下. T ...

  4. Integer.valueOf()与Integer.parseInt()区别

    Integer.parseInt()和Integer.valueOf()有本质区别,具体如下列: Integer.parseInt()把String   型转换为Int型,  Integer.valu ...

  5. MIUI11系统怎么样启用root权限的教程

    MIUI11系统如何启用了ROOT超级权限?做开发的人都知道,安卓机器有ROOT超级权限,一旦手机启用了root相关权限,可以实现更多的功能,举个例子做开发的人公司的营销部门的妹纸,使用较多营销工具都 ...

  6. Django发HTML邮件

    1.settings配置 EMAIL_HOST = 'XXXX' DEFAULT_FROM_EMAIL = '张宁 <zhang.ning@XXX.com>' RECEIVER =['zh ...

  7. kityminder-editor + MongoDB 思维导图数据自动实时保存方案

    最近开始做自己的第一个开源项目:一个基于思维导图的测试用例管理系统MinderCase,在做了一周的技术调研后,决定采用kityminder-editor作为思维导图编辑器,为了支持实时存储,当思维导 ...

  8. CF1082

    D 乱搞题..发现只有a[i]=1是特殊的 瞎搞一下 E 发现一段的贡献是出现次数最多的-为c个数 然后考虑分别对每种颜色做一下 然后每次只有这种颜色和他们之间是有用的 然后做个最大区间和就好了 F ...

  9. Linux 安装qt5-designer并集成到Pycharm

    在前面,有过介绍 Pycharm集成pyrcc4 =====>链接:  Pyqt 打包资源文件  这个是在Windows下集成,且pyqt在Windows下一个双击exe搞定. 在pyqt5之前 ...

  10. 将最小的OWIN身份验证添加到现有的ASP.NET MVC应用程序

    https://weblog.west-wind.com/posts/2015/Apr/29/Adding-minimal-OWIN-Identity-Authentication-to-an-Exi ...