1. 告警概述

prometheus的告警管理分为两部分。通过在prometheus服务端设置告警规则, Prometheus服务器端产生告警向Alertmanager发送告警。 然后,Alertmanager管理这些告警,包括静默,抑制,聚合以及通过电子邮件,PagerDuty和HipChat等方法发送通知。

设置警报和通知的主要步骤如下:

  • 设置并配置Alertmanager;
  • 配置Prometheus对Alertmanager访问;
  • 在普罗米修斯创建警报规则;

2. 告警管理模块 ALERTMANAGER

Alertmanager处理客户端应用程序(如Prometheus服务器)发送的告警。 它负责对它们进行重复数据删除,分组和路由,以及正确的接收器集成,例如电子邮件,PagerDuty或OpsGenie。 它还负责警报的静默和抑制。

以下描述了Alertmanager实现的核心概念。 请参阅配置文档以了解如何更详细地使用它们。

分组(Grouping)

分组将类似性质的告警分类为单个通知。 这在大型中断期间尤其有用,因为许多系统一次失败,并且可能同时发射数百到数千个警报。

示例:

发生网络分区时,群集中正在运行数十或数百个服务实例。 一半的服务实例无法再访问数据库。 Prometheus中的告警规则配置为在每个服务实例无法与数据库通信时发送告警。 结果,数百个告警被发送到Alertmanager。

作为用户,只能想要获得单个页面,同时仍能够确切地看到哪些服务实例受到影响。 因此,可以将Alertmanager配置为按群集和alertname对警报进行分组,以便发送单个紧凑通知。

这些通知的接收器通过配置文件中的路由树配置告警的分组,定时的进行分组通知。

抑制(Inhibition)

如果某些特定的告警已经触发,则某些告警需要被抑制。

示例:

如果某个告警触发,通知无法访问整个集群。 Alertmanager可以配置为在该特定告警触发时将与该集群有关的所有其他告警静音。 这可以防止通知数百或数千个与实际问题无关的告警触发。

静默(SILENCES)

静默是在给定时间内简单地静音告警的方法。 基于匹配器配置静默,就像路由树一样。 检查告警是否匹配或者正则表达式匹配静默。 如果匹配,则不会发送该告警的通知。

在Alertmanager的Web界面中可以配置静默。

客户端行为(Client behavior)

Alertmanager对其客户的行为有特殊要求。 这些仅适用于不使用Prometheus发送警报的高级用例。

3. 配置

Alertmanager通过命令行标志和配置文件进行配置。 命令行标志配置不可变系统参数,而配置文件定义禁止规则,通知路由和通知接收器。
要查看所有可用的命令行标志,请运行alertmanager -h
Alertmanager可以在运行时重新加载其配置。 如果新配置格式不正确,则不会应用更改并记录错误。 通过向进程发送SIGHUP或向/ - / reload端点发送HTTP POST请求来触发配置重新加载。发送HTTP POST的方式比较常用,我们更改过配置文件之后,reload一下即可重启Alertmanager模块使新配置的规则生效。

配置文件

要指定要加载的配置文件,请使用--config.file

./alertmanager --config.file=simple.yml

该文件以YAML格式编写,由下面描述的方案定义。 括号表示参数是可选的。 对于非列表参数,该值设置为指定的默认值。
下面是一个配置文件的示例:

global:# The smarthost and SMTP sender used for mail notifications.smtp_smarthost: 'localhost:25'smtp_from: 'alertmanager@example.org'smtp_auth_username: 'alertmanager'smtp_auth_password: 'password'# The auth token for Hipchat.hipchat_auth_token: '1234556789'# Alternative host for Hipchat.hipchat_api_url: 'https://hipchat.foobar.org/'# The directory from which notification templates are read.
templates:
- '/etc/alertmanager/template/*.tmpl'# The root route on which each incoming alert enters.
route:# The labels by which incoming alerts are grouped together. For example,# multiple alerts coming in for cluster=A and alertname=LatencyHigh would# be batched into a single group.group_by: ['alertname', 'cluster', 'service']# When a new group of alerts is created by an incoming alert, wait at# least 'group_wait' to send the initial notification.# This way ensures that you get multiple alerts for the same group that start# firing shortly after another are batched together on the first # notification.group_wait: 30s# When the first notification was sent, wait 'group_interval' to send a batch# of new alerts that started firing for that group.group_interval: 5m# If an alert has successfully been sent, wait 'repeat_interval' to# resend them.repeat_interval: 3h # A default receiverreceiver: team-X-mails# All the above attributes are inherited by all child routes and can # overwritten on each.# The child route trees.routes:# This routes performs a regular expression match on alert labels to# catch alerts that are related to a list of services.- match_re:service: ^(foo1|foo2|baz)$receiver: team-X-mails# The service has a sub-route for critical alerts, any alerts# that do not match, i.e. severity != critical, fall-back to the# parent node and are sent to 'team-X-mails'routes:- match:severity: criticalreceiver: team-X-pager- match:service: filesreceiver: team-Y-mailsroutes:- match:severity: criticalreceiver: team-Y-pager# This route handles all alerts coming from a database service. If there's# no team to handle it, it defaults to the DB team.- match:service: databasereceiver: team-DB-pager# Also group alerts by affected database.group_by: [alertname, cluster, database]routes:- match:owner: team-Xreceiver: team-X-pagercontinue: true- match:owner: team-Yreceiver: team-Y-pager# Inhibition rules allow to mute a set of alerts given that another alert is
# firing.
# We use this to mute any warning-level notifications if the same alert is
# already critical.
inhibit_rules:
- source_match:severity: 'critical'target_match:severity: 'warning'# Apply inhibition if the alertname is the same.equal: ['alertname', 'cluster', 'service']receivers:
- name: 'team-X-mails'email_configs:- to: 'team-X+alerts@example.org'- name: 'team-X-pager'email_configs:- to: 'team-X+alerts-critical@example.org'pagerduty_configs:- service_key: <team-X-key>- name: 'team-Y-mails'email_configs:- to: 'team-Y+alerts@example.org'- name: 'team-Y-pager'pagerduty_configs:- service_key: <team-Y-key>- name: 'team-DB-pager'pagerduty_configs:- service_key: <team-DB-key>- name: 'team-X-hipchat'hipchat_configs:- auth_token: <auth_token>room_id: 85message_format: htmlnotify: true

全局配置

(global)指定在所有其他配置上下文中有效的参数。 它们还可用作其他配置节的默认值。

路由

路由块定义路由树中的节点及其子节点。 如果未设置,其可选配置参数将从其父节点继承。

每个告警配置的顶级路由中进入路由树,该路由必须匹配所有告警(即没有任何已配置的匹配器)。 然后它遍历子节点。 如果将continue设置为false,则在第一个匹配的子项后停止。 如果匹配节点上的continue为true,则告警将继续与后续兄弟节点匹配。 如果告警与节点的任何子节点都不匹配(没有匹配的子节点,或者不存在),则根据当前节点的配置参数处理告警。

抑制规则(inhibit_rule)

当存在与另一组匹配器匹配的告警(源)时,禁止规则将匹配一组匹配器的告警(目标)静音。
告警可以抑制自己。 避免在告警与源和目标都匹配的情况下编写抑制规则。

后面会详细介绍下Altermanager的抑制规则使用。

receiver

Receiver是一个或多个通知集成的命名配置。包括邮件等通知的集成,这里不再详细介绍,可以根据自己的需要参考官网进行配置。
https://prometheus.io/docs/alerting/configuration/

4. 发送告警

Prometheus会自动负责发送由其配置的告警规则生成的告警。 强烈建议根据时间序列数据在Prometheus中配置告警规则,而不是实现直接客户端。

Alertmanager在/ api / v1 / alerts上侦听API端点上的告警。 只要客户仍处于活动状态(通常为30秒至3分钟),客户就会不断重新发送告警。 客户端可以通过以下格式的POST请求将警报列表推送到该端点:

[{"labels": {"<labelname>": "<labelvalue>",...},"annotations": {"<labelname>": "<labelvalue>",},"startsAt": "<rfc3339>","endsAt": "<rfc3339>","generatorURL": "<generator_url>"},...
]

标签用于标识告警相同的实例并执行重复数据删除。 注释始终设置为最近收到的注释,并且不识别告警。

两个时间戳都是可选的。 如果省略startsAt,则当前时间由Alertmanager分配。 endsAt仅在已知警报结束时间时设置。 否则,它将设置为自上次收到告警以来的可配置超时时间。

generatorURL字段是唯一的反向链接,用于标识客户端中此告警的生成实体。

Alertmanager还支持/ api / alerts上的旧版端点,该端点与Prometheus版本0.16.2及更低版本兼容。

prometheus告警相关推荐

  1. 5.prometheus告警插件-alertmanager、自定义webhook案例编写

    5.prometheus告警插件-alertmanager 参考文章: https://www.bookstack.cn/read/prometheus-book/alert-install-aler ...

  2. linux查看文件句柄阀值,prometheus 告警指标

    记录了prometheus 告警指标 主机和硬件监控 可用内存指标 主机中可用内存容量不足 10% - alert: HostOutOfMemory expr: node_memory_MemAvai ...

  3. 开箱即用的 Prometheus 告警规则集

    作者 | AddoZhang       责编 | 欧阳姝黎 在配置系统监控的时候,是不是即使绞尽脑汁监控的也还是不够全面,或者不知如何获取想要的指标. Awesome Prometheus aler ...

  4. prometheus告警功能

    prometheus告警功能 Prometheus对指标的收集.存储同告警能力分属于Prometheus Server和AlertManager(通用的组件,可由企业自行开发)两个独立的组件,前者仅负 ...

  5. Prometheus 告警收敛

    Prometheus 告警收敛 告警面临最大问题,是警报太多,相当于狼来了的形式.收件人很容易麻木,不再继续理会.关键的告警常常被淹没.在一问题中,alertmanger在一定程度上得到很好解决. P ...

  6. 玩转prometheus告警 alertmanger(一)之prometheus告警规则

    目录 1. 告警系统原理概述 2.  配置prometheus规则 2.1 配置告警规则目录 2.2 告警规则 3. 查看效果 1. 告警系统原理概述 在开始之前,需要了解下prometheus和al ...

  7. Prometheus 告警规则

    Prometheus 告警规则 Prometheus官方内置的第三方报警通知包括:邮件. 即时通讯软件(如Slack.Hipchat).移动应用消息推送(如Pushover)和自动化运维工具(例如:P ...

  8. 最易懂的Prometheus告警原理详解

    通俗易懂的一篇文章,主要介绍了 Prometheus 什么时候告警,什么时候不会告警.同时介绍了 Prometheus 告警原理. 警报是监控系统中必不可少的一块, 当然了, 也是最难搞的一块. 我们 ...

  9. alertmanager监控 Prometheus 告警,alertmanage配置邮件告警

    1.搭建Prometheus,node及mysql参考该链接: 配置grafana展示prometheus监控数据 2.下载安装 alert manager: https://prometheus.i ...

  10. Prometheus告警实践

    完整译文请访问:告警. 点击这里获取云原生干货https://www.coderdocument.com/resource_credential.html?code=云原生干货 对什么告警 目标是尽可 ...

最新文章

  1. 初次体验hiphop-php
  2. python中如何打开csv文件_在Python中从CSV文件读取数据
  3. ACM中java的使用 (转)
  4. android 关于多任务下载问题
  5. MongoDB基础知识总结
  6. 悬挑脚手架卸载钢丝绳要求_安全不可忽视!脚手架搭设彩色图集,动画展示施工全过程,抠细节...
  7. 一步一步学Silverlight 2系列(4):鼠标事件处理
  8. linux中mysql数据库启用日志记录_MYSQL启用日志,和查看日志
  9. java序列化错在哪里_Spark序列化错误:java.io.NotSerializableException
  10. AMI corpus download
  11. mysql date timestamp_【Mysql】Datetime和Timestamp区别,及mysql中各种时间的使用
  12. 【安全】导入本地linux用户到LDAP中
  13. 为什么有人说瑞士银行是全世界最安全的银行?
  14. 下血本买的!2021Java高级面试题
  15. P3371 单源最短路径【模板】 洛谷
  16. 7-7 找出总分最高的学生 (15 分)
  17. Python学习笔记(五)--Python数据类型-数字及字符串
  18. Atitit 人员招募之道 attilax著
  19. 跟小海一起看下雪——用HTML、CSS和JS实现简单的下雪特效
  20. matlab 2013a破解文件

热门文章

  1. 用C语言/C++实现一个基础的电话簿
  2. JVM底层原理之标配参数、X和XX参数
  3. 【python爬虫】用python编写LOL战绩查询
  4. 什么是MES生产管理和生产制造执行系统?有哪些系统模块组成?
  5. 奔图Pantum M6608 一体机驱动
  6. c# excel导入后处理不固定列数据
  7. 硬件知识:电源开关上的“1“和“0“分别是什么意思
  8. spark 实现K-means算法
  9. 微信小程序第五篇:页面弹出效果及共享元素动画
  10. Linux字体相关文件存放的目录位置