成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Alertmanager 告警配置文件和告警規則詳解

運維
Alertmanager 是 Prometheus 生態中的一個重要組件,用于處理 Prometheus 發送的告警(Alerts),它提供了告警分組、抑制、去重、路由以及告警通知等功能。

一、什么是 Alertmanager?

Alertmanager 是 Prometheus 生態中的一個重要組件,用于處理 Prometheus 發送的告警(Alerts)。它提供了告警分組、抑制、去重、路由以及告警通知等功能。它可以在發現問題時立即通知相關負責人,使運維人員能快速響應并采取措施。

下面是告警是流程圖:

Alertmanager 的主要功能:

  • 告警分組(Grouping):將相似的告警合并,減少告警數量。
  • 去重(Deduplication):如果同一告警在短時間內重復觸發,Alertmanager 只會發送一次。
  • 抑制(Inhibition):當某個高優先級告警觸發時,屏蔽低優先級的相關告警。
  • 路由(Routing):將不同類型的告警發送到不同的接收者(如郵件、Slack、Webhook)。
  • 通知(Notification):支持多種通知方式,如郵件、Slack、PagerDuty、Webhook 等。

二、Alertmanager 配置文件詳解

完整的配置文件,這個只是實例,生產環境需要根據實際配置:

global:
  resolve_timeout: 5m  
  smtp_smarthost: 'smtp.example.com:587'
  smtp_from: 'alert@example.com'
  smtp_auth_username: 'user@example.com'
  smtp_auth_password: 'yourpassword'
  smtp_hello: "qq.com"
  smtp_require_tls: false

route:
  receiver: 'default'
  group_by: ['alertname', 'cluster', 'service']  # 分組依據
  group_wait: 30s  # 第一次分組告警發送前的等待時間
  group_interval: 5m  # 組內新告警的發送間隔
  repeat_interval: 3h  # 相同告警重復發送的間隔
  routes:
    - match:
        severity: critical
      receiver: 'email'
      continue: true# 繼續匹配后續規則
    - match:
        severity: warning
      receiver: 'slack'
    - match:
        alertname: InstanceDown
      receiver: 'webhook'

receivers:
  - name: 'default'
    webhook_configs:
      - url: 'http://webhook.example.com/alert'# Webhook 地址

  - name: 'email'
    email_configs:
      - to: 'admin@example.com'
        from: 'alert@example.com'
        smarthost: 'smtp.example.com:587'
        auth_username: 'user@example.com'
        auth_password: 'yourpassword'
        send_resolved: true# 發送告警恢復通知

  - name: 'slack'
    slack_configs:
      - channel: '#alerts'
        send_resolved: true
        api_url: 'https://hooks.slack.com/services/XXX/YYY/ZZZ'
        title: '{{ .CommonAnnotations.summary }}'
        text: '{{ .CommonAnnotations.description }}'

  - name: 'webhook'
    webhook_configs:
      - url: 'http://alert-handler.local/notify'

inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['instance']

Alertmanager 的配置文件 alertmanager.yml 主要包括以下幾個部分,每個部分的作用及參數如下。

1. global 配置

全局配置,Global塊配置下的配置選項在本配置文件內的所有配置項下可見,但是文件內其他位置的子配置可以覆蓋Global配置。

global:
  resolve_timeout: 5m  # 告警恢復后等待 5 分鐘再標記為已解決
  smtp_smarthost: 'smtp.example.com:587'  # 郵件服務器地址
  smtp_from: 'xxx@example.com'  # 發送郵件的地址
  smtp_auth_username: 'xxx@example.com'  # 郵件服務器認證用戶名
  smtp_auth_password: 'yourpassword'  # 郵件服務器認證密碼
  • resolve_timeout:在告警恢復后,等待多長時間才將其標記為“已解決”。
  • smtp_smarthost:用于發送郵件告警的郵件服務器地址。
  • smtp_from:用于發送告警郵件的發件人地址。
  • smtp_auth_username 和 smtp_auth_password:用于認證 SMTP 服務器的用戶名和授權碼。
  • smtp_require_tls:是否開啟tls認證

2. route 配置

告警路由配置,用于告警信息的分組路由,可以將不同分組的告警發送給不同的收件人。

route:
  receiver: 'default' 
  group_by: ['alertname', 'cluster', 'service']  
  group_wait: 30s  
  group_interval: 5m 
  repeat_interval: 3h
  • receiver:默認的接收器(如果沒有匹配到具體的路由規則,則使用此接收器)。
  • group_by:定義告警分組的方式,確保相同服務的告警不會重復發送。
  • group_wait:在發送第一個告警前等待的時間,避免瞬時波動導致告警風暴。
  • group_interval:在同一分組內,新增告警的發送間隔。
  • repeat_interval:相同告警重復發送的時間間隔,防止過度通知。

3. routes 配置

路由子配置,優先級高于route,配置和route一樣的:

routes:
    - match:
        severity: critical
      receiver: 'email'
      continue: true
    - match:
        severity: warning
      receiver: 'slack'
    - match:
        alertname: InstanceDown
      receiver: 'webhook'
  • match:定義匹配規則,例如 severity: critical 表示匹配所有嚴重告警。
  • receiver:匹配該規則的告警將發送到指定接收器。
  • continue:如果為 true,則匹配該規則后仍會繼續匹配其他規則,默認是找到符合的規則后就不在往下繼續匹配。

4. receivers 配置

告警接收人配置,每個receiver都有一個名字,經過route分組并且路由后需要指定一個receiver,可以配置不同類型的接收者:

receivers:
  - name: 'default'
    webhook_configs:
      - url: 'http://webhook.example.com/alert'
  • name:定義接收器的名稱。
  • webhook_configs:使用 Webhook 發送告警。
- name: 'email'
    email_configs:
      - to: 'admin@example.com'
        send_resolved: true
  • to:郵件接收者。
  • send_resolved:是否發送恢復通知。
- name: 'slack'
    slack_configs:
      - channel: '#alerts'
        api_url: 'https://hooks.slack.com/services/XXX/YYY/ZZZ'
  • channel:告警發送的 Slack 頻道。
  • api_url:Slack Webhook URL。

5. inhibit_rules 配置

告警抑制,主要用于減少告警的次數,防止“告警轟炸:

inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['instance']
  • source_match:定義高優先級的告警。
  • target_match:當 source_match 觸發時,抑制 target_match。
  • equal:只有在相同 instance 觸發時才應用抑制規則。

當一個 severity 為 critical 的告警觸發時,所有 severity 為 warning 且 alertname 和 instance 標簽與 critical 告警相同的告警將被抑制,不會發送通知。

完整的配置文件應該還有個Templates配置:用于放置自定義模板的位置,這里不展開講

三、Prometheus 告警規則詳解

1. 告警規則文件

告警配置文件可以自定義名稱,在prometheus配置文件同步就行。

alert-rules.yml:

groups:
  - name: 主機狀態監控
    rules:
      - alert: 主機宕機
        expr: up == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "實例 {{ $labels.instance }} 宕機"
          description: "實例 {{ $labels.instance }} 已經宕機超過 1 分鐘。請檢查服務狀態。"
  • expr:告警觸發條件。
  • for:持續多長時間才觸發告警。
  • labels:告警標簽,可用于匹配規則。
  • annotations:告警的詳細描述。
責任編輯:趙寧寧 來源: 運維李哥不背鍋
相關推薦

2021-02-18 15:36:13

PrometheusAlertmanageGrafana

2021-08-27 07:06:10

應用

2023-03-26 08:41:37

2014-06-16 11:17:12

入侵檢測OSSEC日志分析

2025-01-21 11:18:46

2023-01-13 08:35:29

告警降噪系統

2019-01-17 08:38:03

Redis監控內存

2024-07-31 08:02:26

Prometheus服務器代碼

2022-08-30 13:03:39

prometheusAlert

2011-03-02 13:12:37

vsftpd配置

2009-07-09 15:55:18

WebWork配置文件

2021-08-26 11:30:54

AlertManage阿里云

2025-01-06 10:38:04

2021-03-31 08:02:34

Prometheus 監控運維

2023-11-21 08:57:16

2017-01-20 09:43:12

日志告警挖掘

2010-06-17 16:23:32

Grub2 配置

2009-08-13 09:58:55

C#讀取配置文件

2009-06-05 10:35:02

struts.prop配置文件

2010-11-12 09:44:59

Cassandra配置
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲欧洲综合av | 中文字幕视频在线 | 亚洲国产精品va在线看黑人 | 亚洲在线一区 | 久久综合成人精品亚洲另类欧美 | www.99热.com| 国产精品日女人 | 91啪亚洲精品 | 华人黄网站大全 | 久久久精彩视频 | 欧美精品欧美精品系列 | 美女视频. | 亚洲一区二区三区免费观看 | 国产精品欧美精品日韩精品 | 国产欧美视频一区 | 日本一区二区三区在线观看 | 国产高清视频在线观看播放 | av国产精品毛片一区二区小说 | 成人午夜在线 | 日韩视频在线免费观看 | 久久99精品久久久久子伦 | 一区二区在线免费观看 | 亚洲精品女优 | 免费久久网站 | 日韩av在线免费 | 亚洲网站在线观看 | 国产中的精品av涩差av | 91在线导航 | 中文区中文字幕免费看 | 亚洲福利片 | 中文字幕在线观看日韩 | 成人av鲁丝片一区二区小说 | 99riav3国产精品视频 | 久久这里只有精品首页 | 精品一区二区在线看 | 日韩一二三区视频 | 一区二区三区在线看 | 久久久久久亚洲精品 | 国产精品福利在线观看 | 热久久国产 | 国产女人第一次做爰毛片 |