运维别卷系列 - 云原生监控平台 之 05.prometheus alertManager 实践

文章目录

    • @[toc]
    • Alertmanager 简介
    • Alertmanager 实现的核心概念
      • Grouping
      • Inhibition
      • Silences
      • Client behavior
      • High Availability
    • Alertmanager 配置文件
      • global
      • templates
      • route
      • inhibit_rules
      • receivers
    • Alertmanager 部署
      • 创建 cm
      • 创建 svc
      • 创建 sts
      • Prometheus 配置告警
        • Prometheus 配置文件增加 Alertmanager 配置
        • Prometheus 增加告警规则

Alertmanager 简介

ALERTMANAGER

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

Alertmanager 实现的核心概念

Grouping

  • Grouping categorizes alerts of similar nature into a single notification. This is especially useful during larger outages when many systems fail at once and hundreds to thousands of alerts may be firing simultaneously.
  • 分组将类似性质的警报分类到单个通知中。这在较大规模的中断期间特别有用,因为许多系统同时发生故障,并且可能同时触发数百到数千个警报。

Inhibition

  • Inhibition is a concept of suppressing notifications for certain alerts if certain other alerts are already firing.
  • 抑制是一个概念,用于在已触发某些其他警报时抑制某些警报的通知。

Silences

  • Silences are a straightforward way to simply mute alerts for a given time. A silence is configured based on matchers, just like the routing tree. Incoming alerts are checked whether they match all the equality or regular expression matchers of an active silence. If they do, no notifications will be sent out for that alert.
  • 静默是一种在给定时间内简单地将警报静默的简单方法。静默是基于匹配器配置的,就像路由树一样。检查传入警报是否与活动静默的所有相等或正则表达式匹配器匹配。如果他们这样做,则不会针对该警报发送任何通知。

Client behavior

  • The Alertmanager has special requirements for behavior of its client. Those are only relevant for advanced use cases where Prometheus is not used to send alerts.
  • Alertmanager 对其客户端的行为有特殊要求。这些仅与不使用 Prometheus 发送警报的高级用例相关。

High Availability

  • Alertmanager supports configuration to create a cluster for high availability. This can be configured using the --cluster-* flags.

  • Alertmanager 支持配置以创建集群以实现高可用性。这可以使用 --cluster-* 标志进行配置。

  • It’s important not to load balance traffic between Prometheus and its Alertmanagers, but instead, point Prometheus to a list of all Alertmanagers.

  • 重要的是不要在 Prometheus 及其 Alertmanager 之间对流量进行负载均衡,而是将 Prometheus 指向所有 Alertmanager 的列表。

Alertmanager 配置文件

CONFIGURATION

和 Prometheus 一样,Alertmanager 也支持 post 请求来 reload 配置文件,也是 /-/reload

  • github 上的配置文件示例

global

全局配置

global:# 定义邮件服务器smtp_smarthost: 'localhost:25'# 发送邮件的邮件地址smtp_from: 'alertmanager@example.org'# 发件人名字(具体以邮件服务器为准)smtp_auth_username: 'alertmanager'# 基于 SMTP 身份验证的,不是平常使用的明文密码,需要从邮箱里面申请smtp_auth_password: 'password'# SMTP 是否是 tlssmtp_require_tls: false

templates

邮件报警的内容模板

templates:- '/etc/alertmanager/template/*.tmpl'

route

与路由相关的设置允许根据时间配置警报的路由、聚合、限制和静音方式。

route:# 依据 label 做分组,例如:cluster=A 和 alertname=LatencyHigh 的多个警报将被批处理到一个组中。# 这有效地完全禁用了聚合,按原样传递所有警报。这不太可能是您想要的,除非您的警报量非常低,或者您的上游通知系统执行自己的分组。group_by: ['alertname', 'cluster', 'service']# 当传入警报创建新的警报组时,请至少等待 "group_wait" 以发送初始通知。# 这种方式可以确保您获得同一组的多个警报,这些警报在第一次通知中将另一个警报批处理在一起后不久就开始触发。group_wait: 30s# 发送第一个通知时,请等待 "group_interval" 以发送一批已开始为该组启动的新警报。group_interval: 5m# 如果警报已成功发送,请等待 "repeat_interval" 重新发送警报。repeat_interval: 3h# 默认的接收器receiver: team-X-mails# 以上所有属性都由所有子路由继承,并且可以在每条路由上进行覆盖。# 子路由routes:# 此路由对警报标签执行正则表达式匹配,以捕获与服务列表相关的警报。- matchers:- service=~"foo1|foo2|baz"receiver: team-X-mails# 该服务有一个关键警报的子路由,任何不匹配的警报,即不等于 critical 的,回退到父节点并发送到 "team-X-mails"routes:- matchers:- severity="critical"receiver: team-X-pager- matchers:- service="files"receiver: team-Y-mailsroutes:- matchers:- severity="critical"receiver: team-Y-pager# 此路由处理来自数据库服务的所有警报。如果没有团队来处理,则默认由 DB 团队处理。- matchers:- service="database"receiver: team-DB-pager# 按受影响的数据库对警报进行分组。group_by: [alertname, cluster, database]routes:- matchers:- owner="team-X"receiver: team-X-pagercontinue: true- matchers:- owner="team-Y"receiver: team-Y-pager

inhibit_rules

当存在与另一组匹配器匹配的警报(源)时,禁止规则会将匹配一组匹配器的警报(目标)静音。目标警报和源警报必须具有 equal 列表中标签名称的相同标签值。

# 抑制规则允许在另一个警报正在触发的情况下使一组警报静音。
# 如果同一警报已经是关键警报,我们将使用此功能来静音任何警告级别的通知。
inhibit_rules:- source_matchers: [severity="critical"]target_matchers: [severity="warning"]# 如果源警报和目标警报中都缺少 "equal" 中列出的所有标签名称,则将应用禁止规则!equal: [alertname, cluster, service]

receivers

一个或多个通知集成的命名配置。

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>

Alertmanager 部署

同样,这里是采用 k8s 的方式来部署的,部署的版本是 v0.27.0

创建 cm

smtp 相关的,大家修改成自己的配置就可以了

---
apiVersion: v1
data:alertmanager.yml: |global:resolve_timeout: 5msmtp_smarthost: 'localhost:25'smtp_from: 'alertmanager@example.org'smtp_auth_username: 'alertmanager'smtp_auth_password: 'alertmanager'smtp_require_tls: falsetemplates:- '/app/config/email.tmpl'receivers:- name: default-receiveremail_configs:- to: "imcxsen@163.com"html: '{{ template "email.to.html" . }}'headers: { Subject: " {{ .CommonAnnotations.summary }}" }send_resolved: trueroute:group_interval: 15mgroup_wait: 30sreceiver: default-receiverrepeat_interval: 15mroutes:- match:severity: warningreceiver: default-receivercontinue: true- match:severity: errorreceiver: default-receivercontinue: trueemail.tmpl: |-{{ define "email.to.html" }}{{ range .Alerts }}========= {{ .StartsAt.Format "2006-01-02T15:04:05" }} ==========<br>告警程序: prometheus_alert <br>告警类型: {{ .Labels.alertname }} <br>故障主机: {{ .Labels.instance }} <br>告警主题: {{ .Annotations.summary }} <br>告警详情: {{ .Annotations.description }} <br>{{ end }}{{ end }}
kind: ConfigMap
metadata:labels:name: alertmanager-cmnamespace: monitor

创建 svc

---
apiVersion: v1
kind: Service
metadata:annotations:labels:app: alertmanagername: alertmanager-svcnamespace: monitor
spec:ports:- name: httpprotocol: TCPport: 9093selector:app: alertmanagertype: ClusterIP

创建 sts

---
apiVersion: apps/v1
kind: StatefulSet
metadata:labels:app: alertmanagername: alertmanagernamespace: monitor
spec:replicas: 1selector:matchLabels:app: alertmanagerserviceName: alertmanager-svctemplate:metadata:annotations:labels:app: alertmanagerspec:containers:- args:- "--config.file=/app/config/alertmanager.yml"- "--storage.path=/alertmanager/data"image: prom/alertmanager:v0.27.0livenessProbe:failureThreshold: 60initialDelaySeconds: 5periodSeconds: 10successThreshold: 1tcpSocket:port: servicetimeoutSeconds: 1name: alertmanagerports:- containerPort: 9093name: serviceprotocol: TCP- containerPort: 8002name: clusterprotocol: TCPresources:limits:cpu: 1000mmemory: 1024Mirequests:cpu: 1000mmemory: 1024MivolumeMounts:- mountPath: /app/configname: config-volumevolumes:- configMap:name: alertmanager-cmname: config-volume

Prometheus 配置告警

Prometheus 配置文件增加 Alertmanager 配置

主要增加以下的内容,定义 Prometheus 的告警规则路径和 Alertmanager 的地址,配置完成后 curl -X POST http://ip:port/-/reload 来更新 Prometheus 的配置文件

rule_files:
- /etc/prometheus/rules/*.yml
alerting:alertmanagers:- static_configs:- targets: ["alertmanager-svc.monitor.svc.cluster.local:9093"]
Prometheus 增加告警规则

这里为了方便验证,所以把内存使用率超过 15% 的来触发报警,因为我当前环境,有机器的内存使用率是超过 15%的,这个只需要把 expr 里面的 PromQL 放到 Prometheus 里面执行一下,找到一个均值就可以了,和上面一样,增加了规则文件,也需要 reload 一下 Prometheus 的配置文件

  • 下面定义了一个名字叫 NodeMemoryUsage 的报警
    • for 语句会使 Prometheus 服务等待指定的时间,然后执行查询表达式。
    • labels 语句允许指定额外的标签列表,把它们附加在告警上。我这里暂时没加
    • annotations 语句指定了另一组标签,它们不被当做告警实例的身份标识,它们经常用于存储一些额外的信息,用于报警信息的展示之类的。
  • 一个报警信息在生命周期内有下面 3 种状态:
    • inactive: 表示当前报警信息既不是 firing 状态也不是 pending 状态
    • pending: 表示在设置的阈值时间范围内被激活了
    • firing: 表示超过设置的阈值时间被激活了
groups:
- name: test-rulerules:- alert: NodeMemoryUsageexpr: (node_memory_MemTotal_bytes - (node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes)) / node_memory_MemTotal_bytes * 100 > 15for: 2mannotations:summary: "{{$labels.instance}}: High Memory usage detected"description: "{{$labels.instance}}: Memory usage is above 15% (current value is: {{ $value }}"

查看 Prometheus 的告警状态

在这里插入图片描述

处于 firing 状态,说明报警已经触发,可以查看邮件

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/12514.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

运维别卷系列 - 云原生监控平台 之 03.prometheus label 实践

文章目录 [toc]label 简介自定义标签relabel_configsregexrelabel_action metric_relabel_configs两者的区别 实践 label 简介 label 对于 Prometheus 来说&#xff0c;属于数据处理的方式&#xff0c;Prometheus 是通过指定的 label 来查询数据 Prometheus 的 target 中实例&…

css 步骤条虚线渐变色效果实现

效果如图所示&#xff1a; 思路&#xff1a; 使用元素覆盖的方式实现视觉上虚线的效果 实现代码&#xff1a; html布局 <ul class"details-cont"><li class"details-li" v-for"item in 3" :key"item"><div class&qu…

(教程)gpt-4o如何使用,怎么体验?gpt-4o和gpt-4-turbo的区别

今天OpenAI发布了gpt-4o&#xff0c;我体验之后&#xff0c;gpt-4o简直逆天了。中文能力也挺别强。速度比现在的gpt4还要快。 早在 5 月 11 日&#xff0c;Sam 就在推文中表示&#xff1a;OpenAI 并没有推出 GPT-5&#xff0c;或搜索引擎&#xff0c;但团队一直在努力研发一些…

Nodejs 第七十章(OSS)

OSS OSS&#xff08;Object Storage Service&#xff09;是一种云存储服务&#xff0c;提供了一种高度可扩展的、安全可靠的对象存储解决方案 OSS 对象存储以对象为基本存储单元&#xff0c;每个对象都有唯一的标识符&#xff08;称为对象键&#xff09;和数据。这些对象可以…

【保姆级介绍下运维】

&#x1f308;个人主页: 程序员不想敲代码啊 &#x1f3c6;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f44d;点赞⭐评论⭐收藏 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共…

2024年小学生古诗文大会备考:吃透历年真题和知识点(持续)

根据往年的安排&#xff0c;2024年小学生古诗文大会预计这个月就将启动。该如何备考2024年小学生古诗文大会呢&#xff1f;根据往期的经验&#xff0c;只要吃透这些真题和背后的知识点&#xff0c;通过上海小学生古诗文大会的初选&#xff08;初赛&#xff09;一点问题都没有。…

数据库SQL语言实战(八)

目录 练习题 题目一 题目二 题目三 题目四 题目五 题目六 题目七 题目八 题目九 题目十 练习题 题目一 找出年龄小于20岁且是“物理学院”的学生的学号、姓名、院系名称,按学号排序 create or replace view test6_01 as select S.sid,S.name,S.dname fr…

浅析Free RTOS中Queue的应用

目录 概述 1 认识Queue 1.1 Queue定义 1.2 FreeRTOS中的Queue 1.3 Queue状态 1.4 Queue内容 1.5 发送和接收Message 1.5.1 发送message 1.5.2 接收Message 2 Queue的特性 2.1 数据存储 2.2 可被多任务存取 2.3 读Queue时阻塞 2.4 写Queue时阻塞 3 使用Queue 3.1…

YOLOv9改进策略 | 低照度图像篇 | 2024最新改进CPA-Enhancer链式思考网络(适用低照度、图像去雾、雨天、雪天)

一、本文介绍 本文给大家带来的2024.3月份最新改进机制&#xff0c;由CPA-Enhancer: Chain-of-Thought Prompted Adaptive Enhancer for Object Detection under Unknown Degradations论文提出的CPA-Enhancer链式思考网络&#xff0c;CPA-Enhancer通过引入链式思考提示机制&am…

【提示学习论文】TCP:Textual-based Class-aware Prompt tuning for Visual-Language Model

TCP:Textual-based Class-aware Prompt tuning for Visual-Language Model&#xff08;CVPR2024&#xff09; 基于文本的类感知提示调优的VLMKgCoOp为baseline&#xff0c;进行改进&#xff0c;把 w c l i p w_{clip} wclip​进行投影&#xff0c;然后与Learnable prompts进行…

树莓派|角速度和加速度传感器

角速度传感器和加速度传感器是常见的惯性传感器&#xff0c;常用于测量物体的旋转和线性运动。 角速度传感器&#xff08;Gyroscope&#xff09;用于测量物体绕三个轴&#xff08;X、Y、Z&#xff09;的旋转速度或角速度。它可以提供关于物体在空间中的旋转方向和角度变化的信…

PXI/PXIe规格1553B总线测试模块

面向GJB5186测试专门开发的1553B总线适配卡&#xff0c;支持4Mbps和1Mbps总线速率。该产品提供2个双冗余1553B通道、1个测试专用通道、2个线缆测试通道。新一代的TM53x板卡除了支持耦合方式可编程、总线信号幅值可编程、共模电压注入、总线信号波形采集等功能外&#xff0c;又新…

Python专题:十三、日期和时间(2)

datetime 模块 today()函数 date类型 year month day

二分法的时间复杂度是logN

对数函数&#xff1a; &#xff08;a>0, a≠1&#xff0c; x>0&#xff09; 当αe时&#xff0c;记为yln x 当α10时&#xff0c;记为ylg x 当α2时&#xff0c;记为ylog x 其中x是自变量&#xff0c;函数的定义域是&#xff08;0&#xff0c;∞&#xff09;&#xff0c;…

【Flask框架】

6.Flask轻量型框架 6.1Flask简介 python提供的框架中已经写好了一个内置的服务器&#xff0c;服务器中的回应response行和头已经写好&#xff0c;我们只需要自己写显示在客户端&#xff0c;的主体body部分。 ---------------------------------------------------------- Fla…

Android Studio无法使用Google翻译问题记录

背景 其实关于Google翻译不能用的问题已经出现很久了&#xff0c;之前Google关掉了很多国内的一些Google服务&#xff0c;但是Google翻译还是能用的&#xff0c;直到不知什么时候起&#xff0c;Google翻译也不能用呢。 每次换电脑安装完AS后第一件事就是下载插件 Settings-Pl…

探索智慧生活:百度Comate引领人工智能助手新潮流

文章目录 百度Comate介绍1. 什么是百度Comate&#xff1f;主要特点 2. Comate的核心功能智能问答功能语音识别功能语音助手功能个性化服务 3. Comate 支持哪些语言&#xff1f; 使用教程(以vscode为例)1. 下载和安装Comate3. 常用操作快捷键(windows) 使用体验自然语言生成代码…

Gitlab、Redis、Nacos、Apache Shiro、Gitlab、weblogic相关漏洞

文章目录 一、Gitlab远程代码执行&#xff08;CVE-2021-22205&#xff09;二、Redis主从复制远程命令执行三、Nacos认证绕过漏洞&#xff08;CVE-2021-29441&#xff09;四、Apache Shiro认证绕过漏洞&#xff08;CVE-2020-1957&#xff09;五、Gitlab任意文件读取漏洞&#xf…

3.TCP的三次握手和四次挥手

一、前置知识 TCP是一种面向连接的、可靠的、基于字节流的传输层通信协议。在传输数据前通信双方必须建立连接&#xff08;所谓连接&#xff0c;是指客户端和服务端各自保存一份关于对方的信息&#xff0c;比如ip地址&#xff0c;端口号等&#xff09;。TCP通过三次握手建立一个…

从零开始:C++ String类的模拟实现

文章目录 引言1.类的基本结构2.构造函数和析构函数3.基本成员函数总结 引言 在C编程中&#xff0c;字符串操作是非常常见且重要的任务。标准库中的std::string类提供了丰富且强大的功能&#xff0c;使得字符串处理变得相对简单。然而&#xff0c;对于学习C的开发者来说&#x…