此处默认已安装Prometheus服务,服务地址:192.168.56.200 

一、设置企业微信

1.1、企业微信注册(已有企业微信账号请跳过)

企业微信注册地址:https://work.weixin.qq.com/

按照要求填写相应信息,注册企业微信

1.2 、创建自建应用

企业微信注册完成后,登录进去,点击上方导航条中的【应用管理】按钮,切换到应用管理页面。

然后选择【创建应用】,创建用于接收Alertmanager告警信息的自建应用

填写应用名称等信息,创建应用。创建应用后,记录应用的 AgentId 和 Secret 以备后用

然后点击上方导航条中的【我的企业】按钮,在页面最下方查看企业ID 并记录,以备后用。

二、安装Alertmanager

此处采用源码编译的方式安装。首先下载alertmanager的软件包,下载地址:https://github.com/prometheus/alertmanager/releases/download/v0.19.0/alertmanager-0.19.0.linux-amd64.tar.gz

下载完成后,将下载中软件包上传至Prometheus服务所在的机器(192.168.56.200)的 /usr/local 目录下

解压alertmanager软件包:

#   tar -zvxf alertmanager-0.19.0.linux-amd64.tar.gz
# mv alertmanager-0.19.0.linux-amd64/ alertmanager

进入解压后的alertmanager文件夹,修改alertmanager.yml文件,配置报警信息,alertmanager.yml 内容如下:

global:
resolve_timeout: 5m templates: #告警模板
- './template/test.tmpl' route: # 设置报警分发策略
group_by: ['alertname'] # 分组标签
group_wait: 10s # 告警等待时间。告警产生后等待10s,如果有同组告警一起发出
group_interval: 10s # 两组告警的间隔时间
repeat_interval: 1m # 重复告警的间隔时间,减少相同右键的发送频率 此处为测试设置为1分钟
receiver: 'wechat' # 默认接收者 receivers:
- name: 'wechat'
wechat_configs:
- send_resolved: true
agent_id: '' # 自建应用的agentId
to_user: '*****' # 接收告警消息的人员Id
api_secret: '******' # 自建应用的secret
corp_id: '******' # 企业ID #inhibit_rules:
# - source_match:
# severity: 'critical'
# target_match:
# severity: 'warning'
# equal: ['alertname', 'dev', 'instance']

创建告警模板

进入Alertmanager安装文件夹,创建告警模板文件

#   cd /usr/local/alertmanager
# mkdir template
# cd template/
# vim test.tmpl

将以下内容写入文件当中

{{ define "wechat.default.message" }}
{{ range .Alerts }}
========监控报警==========
告警状态:{{ .Status }}
告警级别:{{ .Labels.severity }}
告警类型:{{ .Labels.alertname }}
告警应用:{{ .Annotations.summary }}
告警主机:{{ .Labels.instance }}
告警详情:{{ .Annotations.description }}
触发阀值:{{ .Annotations.value }}
告警时间:{{ .StartsAt.Format "2006-01-02 15:04:05" }}
========end=============
{{ end }} {{ end }}

检查alertmanager.yml 配置是否正确

#   cd /usr/local/alertmanager
# ./amtool check-config alertmanager.yml

配置正确,模板文件也已经识别

启动alertmanager

#  ./alertmanager

可以看到alertmanager服务已经起来,服务所在的端口为9093

浏览器访问: http://192.168.56.200:9093  (IP:9093)

alertmanager成功启动。

三、配置Prometheus

Ctrl+C 结束掉alertmanager服务进程,进入Prometheus的安装目录下修改Prometheus配置。

#  cd /usr/local/prometheus
# vim prometheus.yml

修改Prometheus.yml文件中的 alerting 配置项及rule_files配置项

alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']

rule_files:  #配置告警规则
   - "rule.yml"

修改完成后保存退出

以下是Prometheus.yml 文件全部内容:

# 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: ['localhost:9093']
# - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "rule.yml"
# - "first_rules.yml"
# - "second_rules.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'] - job_name: 'Linux'
static_configs:
- targets: ['192.168.56.201:9100']
labels:
instance: Linux - job_name: 'Windows'
static_configs:
- targets: ['192.168.56.1:9182']
labels:
instance: Windows - job_name: 'snmp'
scrape_interval: 10s
static_configs:
- targets:
- 172.20.2.83 # 交换机IP地址
metrics_path: /snmp
# params:
# module: [if_mib]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.56.100:9116 # snmp_exporter 服务IP地址

创建并编写告警规则文件rule.yml

#  vim rule.yml

将以下内容写入文件当中,(此处用于测试,设置为当内存占用高于10%时,就会告警)

groups:
- name: mem-rule
rules:
- alert: "内存报警"
expr: (node_memory_MemTotal_bytes - (node_memory_MemFree_bytes+node_memory_Buffers_bytes+node_memory_Cached_bytes )) / node_memory_MemTotal_bytes * 100 > 10
for: 30s
labels:
severity: warning
annotations:
summary: "服务名:{{$labels.alertname}} 内存报警"
description: "{{ $labels.alertname }} 内存资源利用率大于 10%"
value: "{{ $value }}"

保存退出

四、告警检测

重启Prometheus服务,使配置的告警规则生效

#  systemctl restart prometheus

进入alertmanager的安装文件夹,启动alertmanager

#  cd /usr/local/alertmanager
# ./alertmanager

稍等片刻,登录企业微信,可以看到已经接收到告警信息

浏览器访问 http://192.168.56.200:9093/#/alerts  ,也能看到告警信息

五、配置alertmanager服务开机自启

Ctrl+C 结束掉 alertmanager 服务进程,创建 alertmanager服务,让 alertmanager 以服务的方式,开机自启。

添加系统服务

#  vim /etc/systemd/system/alertmanager.service

将以下内容写入文件中

[Unit]
Description=alertmanager
After=network.target

[Service]
WorkingDirectory=/usr/local/alertmanager
ExecStart=/usr/local/alertmanager/alertmanager --config.file=alertmanager.yml --log.level=debug --log.format=json
Restart=on-failure

[Install]
WantedBy=multi-user.target

保存退出

启动服务,设置开机自启

#  systemctl daemon-reload
# systemctl enable alertmanager
# systemctl start alertmanager

至此Prometheus+alertmanage配置企业微信报警完成。

Prometheus(五):Prometheus+Alertmanager 配置企业微信报警的更多相关文章

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

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

  2. zabbix配置企业微信报警

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

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

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

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

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

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

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

  6. Nagios通过企业微信报警

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

  7. Prometheus 企业微信报警/inhibit抑制 /静默(二)

    创建企业微信应用 注册企业微信:访问https://work.weixin.qq.com/,注册企业,随便填,不需要认证 创建应用 创建告警配置 vim /usr/local/prometheus-2 ...

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

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

  9. zabbix企业微信报警实现

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

随机推荐

  1. Linux学习之编译运行.c(C语言)文件

    在Linux命令行界面下,创建文件hello.c,进入vim编辑器,编辑一个简单的C语言文件 分解C语言文件执行过程,要经过预编译.编译.汇编.连接四个步骤后才能执行, 预编译:gcc -E hell ...

  2. jenkins更新为国内源

    系统管理->插件管理->高级->升级站点->URL https://jenkins-zh.gitee.io/update-center-mirror/tsinghua/upda ...

  3. Docker方式安装SonarQube

    获取镜像 docker pull postgres: docker pull sonarqube:-community 启动镜像 docker run -d -p : -e POSTGRES_PASS ...

  4. Qt应用程序主窗口之二:拖放操作与打印文档

    一.拖放操作 对于一个实用的应用程序,不仅希望能从文件菜单中打开一个文件,更希望可以通过拖动直接将桌面上的文件拖入程序界面上来打开,就像可以将.pro文件拖入Creator中来打开整个项目一样.Qt中 ...

  5. Python【每日一问】28

    问: [基础题]:求 1+2!+3!+...+20! 的和 [提高题]:两个乒乓球队进行比赛,各出三人.甲队为 a,b,c 三人,乙队为 x,y,z 三人.已抽签决定比赛名单. 有人向队员打听比赛的名 ...

  6. docker 学习操作记录 4

    记录3 [BEGIN] // :: Connecting to ... Connection established. To escape to local shell, press Ctrl+Alt ...

  7. ES6高级技巧(二)

    Array.from const cities = [ { name: 'Milan', visited: 'no' }, { name: 'Palermo', visited: 'yes' }, { ...

  8. Scala Operators, File & RegExp

    Operators Thread.`yield`() 反引号除了用于命名标识符,还可以在调用方法时避免冲突(yield 为 Scala 关键字,但也是 Thread 的方法) 中缀运算符(infix ...

  9. 【题解】Luogu P5471 [NOI2019]弹跳

    原题传送门 先考虑部分分做法: subtask1: 暴力\(O(nm)\)枚举,跑最短路 subtask2: 吧一行的点压到vector中并排序,二分查找每一个弹跳装置珂以到达的城市,跑最短路 sub ...

  10. mosquitto: error while loading shared libraries: libwebsockets.so.12: cannot open shared object file

    错误描述: # mosquitto -c /etc/mosquitto/mosquitto.conf -dmosquitto: error while loading shared libraries ...