目录

  • 引言
  • 一、定义
    • 1. 告警功能概述
    • 2. 通知告警信息
    • 3. Prometheus 监控系统的告警逻辑
      • 3.1 告警功能
      • 3.2 静默、抑制、分组等功能
  • 二、部署告警对接邮箱
    • 1. 下载安装包
    • 2. 修改配置文件
    • 3. 配置绑定的邮箱
    • 4. 启动 alertmanager
    • 5. 启动 prometheus
    • 6. 模拟故障

引言

  • Prometheus 对指标的收集、存储同告警能力分属于 Prometheus ServerAlertManager(通用的组件) 两个独立的组件,前者仅负责基于 “告警规则” 生成告警通知,具体的告警操作则由后者完成;

  • Alertmanager 负责处理由客户端发来的告警通知客户端通常是 Prometheus server,但它也支持接收来自其它工具的告警

  • Alertmanager 对告警通知进行分组、去重后,根据路由规则将其路由到不同的 receiver,如Email、短信或PagerDuty等;

  • 目前 Alertmanager 还不支持钉钉,那用户完全可以通过 Webhook 与钉钉机器人进行集成,从而通过钉钉接收告警信息。

  • 同时 AltManager 还提供了静默告警抑制机制来对告警通知行为进行优化

PS:webhook是一个 APr 概念, webhoo 是一种 web 回调或者 http 的 push APT.Webhook 作为一个轻量的事件处理应用

一、定义

1. 告警功能概述

  • prometheus 对指标的收集、存储与告警能力分属于 Prometheus serve 和 alertmanager 两个独立的组件,pro-server 只负责通过"告警规则"生成告警通知,具体告警操作是由alertmmanager完成

  • 告警规则:
    是由 PromQL 编写的布尔值表达式使用>< =与一个常用量值,比如80%进行比较,其返回值为true或false

  • prometheus-server 对抓取到的指标序列与告警规则中做为比较的 Prometheus 匹配,则会把此样本值抓取过来作比较,若返回值为 true 则认为指标异常,不能满足 false,则为正常值以上表达式为告警规则表达式
    比如:筛选一个指标数据 cpu 使用率 <0% 系统异常

2. 通知告警信息

一旦条件表达式为 true 就会触发通知信息,送给 altermanager,由 alter 借助特定服务的 API 或者访问入口,将此信息发出去,一般称为告警媒介,也可以借助邮件进行告警 SMTP

3. Prometheus 监控系统的告警逻辑

  • route:告警路由,分组、分类分发告警消息给不同渠道

  • prometheus 通过 alter-rule 规则,生成告警通知给 altermanager,altermanager 会生成本地的告警路由表(第一路由默认称为根路由,所有的告警信息都需要一个根路由,没有一个匹配项,则需要设置一个默认路由)为实现将特定的信息发送给特定的用户

例如:
按消息级别来看: 严重、中等、普通级别,红色报警、蓝色报警,应用发送方
按分组: 业务运维、系统运维、基础设施运维、k8s运维

3.1 告警功能

除了基本的告警通知能力外,Altermanager还支持对告警进行去重、分组、抑制、

3.2 静默、抑制、分组等功能

分组 (Grouping):将相似告警合并为单个告警通知的机制,在系统因大面积故障而触发告警潮时,分组机制能避免用户被大量的告警噪声淹没,进而导致关键信息的隐没;
抑制(Inhibition):系统中某个组件或服务故障而触发告警通知后,那些依赖于该组件或服务的其它组件或服务可能也会因此而触发告警,抑制便是避免类似的级联告警的一种特性,从而让用户能将精力集中于真正的故障所在
静默(silent):是指在一个特定的时间窗口内,即便接收到告警通知,Alertmanager也不会真正向用户发送告警信息的行为;通常,在系统例行维护期间,需要激活告警系统的静默特性
路由(route):用于配置Alertmanager如何处理传入的特定类型的告警通知,其基本逻辑是根据路由匹配规则的匹配结果来确定处理当前告警通知的路径和行为

二、部署告警对接邮箱

192.168.8.20
在 prometheus-server 端定义告警规则,指定alertmanager的位置,将告警信息发送给alert处理

1. 下载安装包

tar zxvf alertmanager-0.21.0.linux-amd64.tar.gz -C /usr/local/
ln -s /usr/local/alertmanager-0.21.0.linux-amd64/ /usr/local/alertmanager
  • 配置文件解析
cat /usr/local/alertmanager/alertmanager.yml
global:                                                 #全局参数resolve_timeout: 5mroute:                                                  #路由信息group_by: ['alertname']                              #分组group_wait: 30s                                      #分组缓冲/等待时间group_interval: 5m                                    #重新分组时间repeat_interval: 1h                                  #重新告警间隔receiver: 'web.hook'                                   #接收方/媒介
receivers:
- name: 'web.hook'webhook_configs:- url: 'http://127.0.0.1:5001/'                       #标注5001端口
inhibit_rules:                                          #抑制规则的策略- source_match:                                     #匹配项severity: 'critical'                              #严重的级别target_match:severity: 'warning'                                #target匹配warning级别equal: ['alertname', 'dev', 'instance']             #符合alertname、dev、instance

2. 修改配置文件

cd /usr/local/alertmanager
cp alertmanager.yml alertmanager.yml.bak
vim alertmanager.ymlglobal:         resolve_timeout: 5m   smtp_from: 772147186@qq.comsmtp_auth_username: 772147186@qq.comsmtp_auth_password: ztcopqiixarfbdbgsmtp_require_tls: falsesmtp_smarthost: 'smtp.qq.com:465'route:group_by: ['alertname']group_wait: 10sgroup_interval: 10srepeat_interval: 1hreceiver: 'email-test'
receivers:
- name: 'email-test'email_configs:- to: 772147186@qq.comsend_resolved: true

3. 配置绑定的邮箱

登入邮箱——>设置——>账户——>pop3/IMAO/SMTP/Exchange/CardDVA/——>开启

4. 启动 alertmanager

cd /usr/local/alertmanager/
./alertmanager
  • 配置文件
#需要注意 prometheus 安装的位置
cd /usr/local/prometheus-2.27.1.linux-amd64/
mkdir alert-config
cd alert-config/
mkdir alert_rules targets
cd alert_rules/vim instance_down.yaml                           #邮件会接收到的信息groups:
- name: AllInstancesrules:- alert: InstanceDown                         #节点服务挂掉 # Condition for alertingexpr: up == 0                             #up状态为0时for: 1m# Annotation - additional informational labels to store more informationannotations:title: 'Instance down'description: Instance has been down for more than 1 minute.'# Labels - additional labels to be attached to the alertlabels:severity: 'critical'                       #告警级别
cd ..
cd targets/
vim alertmanagers.yaml- targets:- 192.168.8.20:9093labels:app: alertmanager
----------------------------------------------------------------------------------------------
vim nodes-linux.yaml- targets:- 192.168.8.17:9100- 192.168.8.18:9100- 192.168.8.19:9100labels:app: node-exporterjob: node
--------------------------------------------------------------------------------------------
vim prometheus-servers.yaml - targets:- 192.168.8.20:9090labels:app: prometheusjob: prometheus----------------------------------------------------------------------------------------------
[root@prometheus /usr/local/prometheus-2.27.1.linux-amd64/alert-config]#tree
.
├── alert_rules
│   └── instance_down.yaml
└── targets├── alertmanagers.yaml├── nodes-linux.yaml└── prometheus-servers.yaml
  • prometheus 启动文件
vim /usr/local/prometheus-2.27.1.linux-amd64/prometheus.yml # my global config
# Author: MageEdu <mage@magedu.com>
# Repo: http://gitlab.magedu.com/MageEdu/prometheus-configs/
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:- file_sd_configs:- files:- "/usr/local/prometheus-2.27.1.linux-amd64/alert-config/targets/alertmanagers*.yaml"# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:- "rules/*.yaml"- "/usr/local/prometheus-2.27.1.linux-amd64/alert-config/alert_rules/*.yaml"# 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'.file_sd_configs:- files:- /usr/local/prometheus-2.27.1.linux-amd64/alert-config/targets/prometheus-*.yamlrefresh_interval: 2m# All nodes- job_name: 'nodes'file_sd_configs:- files:- /usr/local/prometheus-2.27.1.linux-amd64/alert-config/targets/nodes-*.yamlrefresh_interval: 2m- job_name: 'alertmanagers'file_sd_configs:- files:- /usr/local/prometheus-2.27.1.linux-amd64/alert-config/targets/alertmanagers*.yamlrefresh_interval: 2m

5. 启动 prometheus

指定修改的配置文件启动

cd /usr/local/prometheus-2.27.1.linux-amd64/
./prometheus --config.file=./prometheus.yml

6. 模拟故障

  • 停止 node_exporter

  • 查看 prometheus-UI

  • 查看QQ邮箱

Prometheus 部署告警对接 QQ 邮箱相关推荐

  1. Prometheus -Grafana部署及部署告警

    目录 一.prometheus 概述 1.简介 2. 指标类型 3. 作业 job 和实列 targets/instance 4. PrometheusQL(数据查询语言也是时序数据库使用语言) 二. ...

  2. Prometheus(三)Grafana部署及部署告警

    文章目录 一.Grafana部署及模板展示 1.Grafan部署步骤 二.打标签 1.重新打标定义(在job上定义) 2.relabel config(重新打标配置) 三.prometheus告警功能 ...

  3. 通过Alertmanager实现Prometheus的告警告警配置(邮箱加钉钉)

    通过Alertmanager实现Prometheus的告警 告警配置 Prometheus本身不支持的告警功能,主要通过插件Alertmanager来实现告警.Alertmanager用于接收Prom ...

  4. linux的QQ邮件告警,QQ邮箱告警注意点

    背景 使用QQ邮箱告警一直失败,查了很多资料,发现ssl规则,和设置端口设置下即可 脚本内容(163邮箱,可直接使用) [root@hf-01 ~]# vim /usr/lib/zabbix/aler ...

  5. Zabbix创建用户及告警媒介配置,配置qq邮箱告警配置/163(下)

    Zabbix创建用户及告警媒介配置,配置qq邮箱告警配置/163(下) 上篇文章我们在虚拟机里安装了mailx服务, 修改了mail.rc的配置文件 在zabbix-server的邮件配置路径下创建了 ...

  6. 虚拟机部署Gitlab + 配置QQ,网易邮箱

    查找Gitlab镜像 docker search gitlab 拉取Gitlab镜像 docker pull registry.gitlab.cn/omnibus/gitlab-jh:latest 创 ...

  7. prometheus监控告警功能

    prometheus监控K8S 监控告警功能 alertmanager邮箱告警配置 首先开通SMTP服务,QQ邮箱:设置–帐号–开通POP3/SMTP服务,记住生成的密码(其它邮箱同理) 编辑prom ...

  8. prometheus监控+告警

    1 开始安装前的准备 1.1 修改主机名 1.2 关闭防火墙 1.3 关闭seliunx 1.4 关闭防火墙 1.5 下载阿里云的yum源 2 下载所用到的包 2.1 安装 node_porter 2 ...

  9. Java实现邮件发送 超详细!!!(以QQ邮箱个人版和企业版为例)

    Java实现发送邮件 超详细!!!(以QQ邮箱个人版和企业版为例) 文章目录 Java实现发送邮件 超详细!!!(以QQ邮箱个人版和企业版为例) 个人邮箱示例 配置依赖 简单了解涉及的两个传输协议 Q ...

最新文章

  1. Ruby DSL介绍及其在测试数据构造中的使用(1)
  2. 容量和速度是选购闪存盘的关键
  3. linux io模拟时序,spi四种模式io模拟时序
  4. python免费教学视频教程-Python免费教程_Python免费视频教程大全_易玩网
  5. css 识别变量中的换行符_Python编程 第二章——变量和简单数据类型
  6. codeforces 的一些数学题
  7. Linux文件操作命令
  8. 生效linux内核,Linux内核
  9. Qt中修改应用程序和标题栏的图标
  10. c语言 %15s,c语言求助
  11. 4027-计数排序(C++,附解析)
  12. angular 常用指令的使用
  13. 微信小程序nginx+uwsgi+django配置的域名问题
  14. 计算机为动态分区无法安装系统,采用gpt分区无法安装系统怎么办
  15. ubuntu 下文件/文件夹 比较工具 DiffMerge
  16. Transaction-based classification and detection approach for Ethereum smart contract
  17. Android FrameWork(AMS,WMS,PMS等)的概念及解析,获取系统服务
  18. Java对象内存布局(JOL)
  19. layui实现文件压缩上传_基于SSM框架、Layui的多文件上传、包括图片,压缩包,音频等文件(与数据库挂钩) - 爱秧博客...
  20. springboot自动创建Oracle,一键生成项目 SpringBoot项目代码生成器 支持Oracle 支持MySql...

热门文章

  1. html是网页病毒吗,无弹窗浏览器 目前最具效果性的防网页病毒软件
  2. Android 源码编译环境搭建
  3. 个人博客作业Week3
  4. 大数据分析师与数据分析师_非分析师的数据分析
  5. 新版阿里云官网Maven中央仓库地址
  6. 使用Quasar进行木马植入
  7. office2007各组件全面介绍
  8. Life is short(人生如此短暂)
  9. 数组练习题-java
  10. 利用selenium实现淘宝双十一抢购商品