简介

Alertmanager 主要用于接收 Prometheus 发送的告警信息,它很容易做到告警信息的去重,降噪,分组,策略路由,是一款前卫的告警通知系统。它支持丰富的告警通知渠道,可以将告警信息转发到邮箱、企业微信、钉钉等。这一节讲解利用AlertManager,把接受到的告警信息,转发到邮箱。

实验

准备

启动 http-simulator 度量模拟器:

docker run --name http-simulator -d -p 8080:8080 pierrevincent/prom-http-simulator:0.1

启动 Prometheus,为了方便更新配置,使用挂载配置文件的方式:

docker run --name prometheus -d -p 9090:9090 -v /Users/huanchu/Documents/prometheus-data:/prometheus-data \
prom/prometheus --web.enable-lifecycle --config.file=/prometheus-data/prometheus.yml

启动添加了参数 --web.enable-lifecycle,让Prometheus支持通过web端点动态更新配置。

访问http://127.0.0.1:9090/targets ,Prometheus 自身的 metrics 和 http-simulator 的 metrics 处于up 状态 ,那么准备工作就做好了。

实验

实验1

告警配置

在prometheus-data文件夹下,创建告警配置文件 simulator_alert_rules.yml:

groups:
- name: simulator-alert-rule
rules:
- alert: HttpSimulatorDown
expr: sum(up{job="http-simulator"}) == 0
for: 1m
labels:
severity: critical

配置文件的意思是 http-simulator 服务up状态为 0 ,并且持续1分钟时,产生告警 ,级别为 “严重的”。

修改prometheus.yml,引用simulator_alert_rules.yml文件,prometheus.yml 内容如下:

global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_timeout: 5s rule_files:
- "simulator_alert_rules.yml" scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'http-simulator'
metrics_path: /metrics
static_configs:
- targets: ['192.168.43.121:8080']

更新Prometheus配置:

curl -X POST http://localhost:9090/-/reload

访问http://127.0.0.1:9090/config,可以看到已经为更新了配置:

访问http://127.0.0.1:9090/rules,Rules 下出现了新添加的告警规则:

验证

访问http://127.0.0.1:9090/alerts ,Alerts 下 HttpSimulatorDown 为绿色,处于INACTIVE 状态,表示什么都没有发生。

关闭 http-simulator 服务:

docker stop http-simulator

访问http://127.0.0.1:9090/alerts,HttpSimulatorDown 变成黄色,处于 PENDING 状态,表示报警即将被激活。

一分钟后,HttpSimulatorDown 变成红色,处于 FIRING 状态,表示报警已经被激活了。

实验2

告警配置

在simulator_alert_rules.yml文件中增加告警配置:

- alert: ErrorRateHigh
expr: sum(rate(http_requests_total{job="http-simulator", status="500"}[5m])) / sum(rate(http_requests_total{job="http-simulator"}[5m])) > 0.02
for: 1m
labels:
severity: major
annotations:
summary: "High Error Rate detected"
description: "Error Rate is above 2% (current value is: {{ $value }}"

配置文件的意思是 http-simulator 请求的错误率对2% ,并且持续1分钟时,产生告警 ,级别为 “非常严重的”

更新Prometheus配置:

curl -X POST http://localhost:9090/-/reload

验证

访问http://127.0.0.1:9090/alerts,ErrorRateHigh 为绿色的 INACTIVE 状态。

把 http-simulator 的错误率调到 10%

curl -H 'Content-Type: application/json' -X PUT -d '{"error_rate": 10}' http://localhost:8080/error_rate

稍等一会后,访问http://127.0.0.1:9090/alerts, 可以看到错误率已经大2%,ErrorRateHigh 为红色的 FIRING 状态,报警已经被激活了。

安装和配置AlertManager

通过docker 挂载文件的方式安装AlertManager,在本地创建文件夹 alertmanager-data 文件夹,在其中创建 alertmanager.yml,内容如下:

global:
smtp_smarthost: 'smtp.163.com:25'
smtp_from: 'xxxxx@163.com'
smtp_auth_username: 'xxxxx@163.com'
smtp_auth_password: 'xxxxx' route:
group_interval: 1m #当第一个报警发送后,等待'group_interval'时间来发送新的一组报警信息
repeat_interval: 1m # 如果一个报警信息已经发送成功了,等待'repeat_interval'时间来重新发送他们
receiver: 'mail-receiver'
receivers:
- name: 'mail-receiver'
email_configs:
- to: 'xxxxxx@163.com'

启动 AlertManager:

docker run --name alertmanager -d -p 9093:9093 -v /Users/huanchu/Documents/alertmanager-data:/alertmanager-data \
prom/alertmanager --config.file=/alertmanager-data/alertmanager.yml

在Prometheus目录下,修改prometheus.yml配置Alertmanager地址:

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- 192.168.43.121:9093

更新Prometheus配置:

curl -X POST http://localhost:9090/-/reload

访问http://127.0.0.1:9093,访问Alertmanager UI界面,可以看到接收到ErrorRateHigh告警:

邮箱会收到告警信息:

欢迎扫码或微信搜索公众号《程序员果果》关注我,关注有惊喜~

Prometheus 整合 AlertManager的更多相关文章

  1. Prometheus 与 Alertmanager 通信

    Prometheus 与 Alertmanager 通信 1.编辑Prometheus配置文件配置连接地址:vim prometheus.yml # Alertmanager configuratio ...

  2. Prometheus 安装Alertmanager集成

    Prometheus 安装Alertmanager集成 # 下载地址 地址1:https://prometheus.io/download/ 地址2:https://github.com/promet ...

  3. prometheus学习系列十一: Prometheus和AlertManager的高可用

    前面的系列中, prometheus和alertmanager都是单机部署的,会有单机宕机导致系统不可用情况发生.本文主要介绍下prometheus和alertmanager的高可用方案. 服务的高可 ...

  4. Prometheus 和 Alertmanager实战配置

    Prometheus时序数据库 一.Prometheus 1.Prometheus安装 1)源码安装 prometheus安装包最新版本下载地址:https://prometheus.io/downl ...

  5. linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)

    一,alertmanager的用途 1,Alertmanager的作用: Alertmanager是一个独立的报警模块, 它接收Prometheus等客户端发来的警报,并通过分组.删除重复等处理, 通 ...

  6. Prometheus+Grafana+Alertmanager实现告警推送教程 ----- 图文详解

    前言 本文主要介绍的是Prometheus采集数据,通过Grafana加上PromQL语句实现数据可视化以及通过Alertmanage实现告警推送功能.温馨提示,本篇文章特长,2w多的文字加上几十张图 ...

  7. prometheus,alertmanager 报警配置详解

    vim prometheus.yml global: scrape_interval: 15s external_labels: monitor: 'codelab-monitor' scrape_c ...

  8. 基于Prometheus+Grafana+AlertManager的监控系统

    一.Prometheus 1.1 简介 Prometheus是一套开源的监控&报警&时间序列数据库的组合,基于应用的metrics来进行监控的开源工具 . 1.2 下载&安装 ...

  9. prometheus+grafana+Alertmanager邮箱告警

    环境 系统:CentOS 7 软件:alertmanager-0.18.0.linux-amd64.tar.gz 安装 下载二进制包 地址:https://prometheus.io/download ...

随机推荐

  1. Spring Boot 集成配置 HTTPS

    这是泥瓦匠的第108篇原创 文章工程: * JDK 1.8 * Maven 3.5.2 * Spring Boot 1.5.9.RELEASE ## 一.HTTPS 是什么 问:什么是HTTP? 答: ...

  2. Python自学day-1

    一.Python介绍 1.python擅长领域:     WEB开发:Django. pyramid. Tornado. Bottle. Flask. WebPy     网络编程:Twisted(牛 ...

  3. Hadoop初步学习

    我们老板理解的大数据是,从数据到知识的转化.大数据目前的应用如 支付宝金融大数据.腾讯出行大数据等. 大数据的工作就是从海量数据源中筛选,梳理对自己有用的数据,整合成合适的数据结构,存储并进行可视化. ...

  4. idea提交代码到自己git账号的master branch

    1.注册GitHub账号 2.创建本地密钥与远程仓库连接(使用idea的话,这第二步可能不是必须的,但是密钥我之前配置过.所以写下来) ①安装git 客户端sudo apt-get install g ...

  5. Oracle 聚集函数

    (1)avg(x):返回x的平均值 select avg(grade) from sc; (2)count(x):返回统计的行数 select count(name) from sc; (3)max( ...

  6. 分析了16年的福利彩票记录,原来可以用Python这么买彩票

    目录 0 引言 1 环境 2 需求分析 3 代码实现 4 后记 0 引言 上周被一则新闻震惊到了,<2454万元大奖无人认领!福彩史上第二大弃奖在广东中山产生 >,在2019年5月2日开奖 ...

  7. JAVA 实现 GET、POST、PUT、DELETE HTTP请求

    1.get 2.put 3.post 4.delete

  8. UVALive 6255:Kingdoms(状压DFS)

    题目链接 题意 给出n个王国和n*n的矩阵,mp[i][j] 代表第 i 个王国欠第 j 个王国 mp[i][j] 块钱.如果当前的王国处于负债状态,那么这个王国就会被消除,和它相连的王国的债务都会被 ...

  9. java中session和application的用法

    Session的用法 首先创建2个jsp文件t1.jsp  t2.jsp 在t1.jsp <% //设置session的键与值 session.setAttribute("abc&qu ...

  10. svn unable to connect to a repository url 计算机积极拒绝

    网上应该说启动server服务,首先找不到这个服务,后来下载个软件有了,启动还是不行.clear了所有saved data之后也是不行. 解决方法:Network中 Enable proxy Serv ...