天天看點

alertmanager配置詳解

原文;https://www.cnblogs.com/gered/p/13496950.html

目錄

【1】Alertmanager工作機制

【2】AlertManager的三個概念

分組(Grouping)

抑制(Inhibition)

靜默(Silences )

【3】安裝Alertmanager

【3.1】二進制安裝

【3.2】Alertmanager 參數

參數 描述

–config.file=“alertmanager.yml” 指定Alertmanager配置檔案路徑

–storage.path=“data/” Alertmanager的資料存放目錄

–data.retention=120h 曆史資料保留時間,預設為120h

–alerts.gc-interval=30m 警報gc之間的間隔

–web.external-url=WEB.EXTERNAL-URL 外部可通路的Alertmanager的URL(例如Alertmanager是通過nginx反向代理)

–web.route-prefix=WEB.ROUTE-PREFIX wen通路内部路由路徑,預設是 --web.external-url

–web.listen-address=":9093" 監聽端口,可以随意修改

–web.get-concurrency=0 并發處理的最大GET請求數,預設為0

–web.timeout=0 web請求逾時時間

–cluster.listen-address=“0.0.0.0:9094” 叢集的監聽端口位址。設定為空字元串禁用HA模式

–cluster.advertise-address=CLUSTER.ADVERTISE-ADDRESS 配置叢集通知位址

–cluster.gossip-interval=200ms 發送條消息之間的間隔,可以以增加帶寬為代價更快地跨叢集傳播。

–cluster.peer-timeout=15s 在同級之間等待發送通知的時間

… …

–log.level=info 自定義消息格式 [debug, info, warn, error]

–log.format=logfmt 日志消息的輸出格式: [logfmt, json]

–version 顯示版本号

【4】Alertmanager配置詳解

## Alertmanager 配置檔案
global:
  resolve_timeout: 5m
  # smtp配置
  smtp_from: "[email protected]"
  smtp_smarthost: 'smtp.qq.com:465'
  smtp_auth_username: "[email protected]"
  smtp_auth_password: "auth_pass"
  smtp_require_tls: true
# email、企業微信的模闆配置存放位置,釘釘的模闆會單獨講如果配置。
templates:
  - '/data/alertmanager/templates/*.tmpl'
# 路由分組
route:
  receiver: ops
  group_wait: 30s # 在組内等待所配置的時間,如果同組内,30秒内出現相同報警,在一個組内出現。
  group_interval: 5m # 如果組内内容不變化,合并為一條警報資訊,5m後發送。
  repeat_interval: 24h # 發送報警間隔,如果指定時間内沒有修複,則重新發送報警。
  group_by: [alertname]  # 報警分組
  routes:
      - match:
          team: operations
        group_by: [env,dc]
        receiver: 'ops'
      - match_re:
          service: nginx|apache
        receiver: 'web'
      - match_re:
          service: hbase|spark
        receiver: 'hadoop'
      - match_re:
          service: mysql|mongodb
        receiver: 'db'
# 接收器
# 抑制測試配置
      - receiver: ops
        group_wait: 10s
        match:
          status: 'High'
# ops
      - receiver: ops # 路由和标簽,根據match來指定發送目标,如果 rule的lable 包含 alertname, 使用 ops 來發送
        group_wait: 10s
        match:
          team: operations
# web
      - receiver: db # 路由和标簽,根據match來指定發送目标,如果 rule的lable 包含 alertname, 使用 db 來發送
        group_wait: 10s
        match:
          team: db
# 接收器指定發送人以及發送管道
receivers:
# ops分組的定義
- name: ops
  email_configs:
  - to: '[email protected],[email protected]'
    send_resolved: true
    headers:
      subject: "[operations] 報警郵件"
      from: "警報中心"
      to: "小煜狼皇"
  # 釘釘配置
  webhook_configs:
  - url: http://localhost:8070/dingtalk/ops/send
    # 企業微信配置
  wechat_configs:
  - corp_id: 'ww5421dksajhdasjkhj'
    api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
    send_resolved: true
    to_party: '2'
    agent_id: '1000002'
    api_secret: 'Tm1kkEE3RGqVhv5hO-khdakjsdkjsahjkdksahjkdsahkj'

# web
- name: web
  email_configs:
  - to: '[email protected]'
    send_resolved: true
    headers: { Subject: "[web] 報警郵件"} # 接收郵件的标題
  webhook_configs:
  - url: http://localhost:8070/dingtalk/web/send
  - url: http://localhost:8070/dingtalk/ops/send
# db
- name: db
  email_configs:
  - to: '[email protected]'
    send_resolved: true
    headers: { Subject: "[db] 報警郵件"} # 接收郵件的标題
  webhook_configs:
  - url: http://localhost:8070/dingtalk/db/send
  - url: http://localhost:8070/dingtalk/ops/send
# hadoop
- name: hadoop
  email_configs:
  - to: '[email protected]'
    send_resolved: true
    headers: { Subject: "[hadoop] 報警郵件"} # 接收郵件的标題
  webhook_configs:
  - url: http://localhost:8070/dingtalk/hadoop/send
  - url: http://localhost:8070/dingtalk/ops/send

# 抑制器配置
inhibit_rules: # 抑制規則
  - source_match: # 源标簽警報觸發時抑制含有目标标簽的警報,在目前警報比對 status: 'High'
      status: 'High'  # 此處的抑制比對一定在最上面的route中配置不然,會提示找不key。
    target_match:
      status: 'Warning' # 目标标簽值正則比對,可以是正規表達式如: ".*MySQL.*"
    equal: ['alertname','operations', 'instance'] # 確定這個配置下的标簽内容相同才會抑制,也就是說警報中必須有這三個标簽值才會被抑制。
           

【4.1】案例示範

【4.2】route 路由比對規則

【4.3】receiver 接收器

【4.4】inhibit_rules 抑制器

【5】警報通知接收器

【參考文檔】

繼續閱讀