alertmanager安裝配置

kunchengs發表於2024-09-05

https://prometheus.io/download/#alertmanager
https://github.com/prometheus/alertmanager

介紹說明
https://blog.csdn.net/weixin_42171272/article/details/139112335
https://zhuanlan.zhihu.com/p/703090367

https://blog.csdn.net/namelijink/article/details/135487104
wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz

tar -zxf alertmanager-0.27.0.linux-amd64.tar.gz
cd alertmanager-0.27.0.linux-amd64/

vim alertmanager.yml

進行配置檔案修改

點選檢視程式碼

global:
  resolve_timeout: 5m #處理超時時間,預設為5分鐘
  external_url: 'http://xxxxx:8893'
  
  smtp_from: 'xxx@qq.com'       # smtp_from:指定通知報警的郵箱
  smtp_smarthost: 'smtp.qq.com:25'        # smtp_smarthost: 使用email開啟服務配置
  smtp_auth_username: xxx@qq.com'    # smtp_auth_username:郵箱使用者名稱
  smtp_auth_password: xxxxxxxxxxxxj'    # 此處為郵箱授權碼

route:
  group_by: ['alertname', 'item']  # 傳入報警分組在一起的標籤,如item=測試和alertname=Disk的多個報警將批處理為單個組
  group_wait: 30s  # 這個引數設定了在傳送第一批警報之後,Alertmanager 等待新警報加入現有組的時間。此處 group_wait 被設定為 30 秒。如果在 30 秒內沒有新的警報加入組,那麼這個組的警報將被髮送出去。
  group_interval: 300s  # 傳送組警報的時間間隔
  repeat_interval: 4h  # 對同一個警報組的重複通知之間的時間間隔 對於email配置中,此項不可以設定過低,否則將會由於郵件傳送太多頻繁,被smtp伺服器拒絕
  receiver: 'email'   # 傳送警報的接收者的名稱,以下receivers name的名稱
  
       
# 定義模板
#templates:
#  - '/usr/local/alertmanager/template/*.tmpl'

receivers:

# 接收郵件的郵箱
- name: 'email'
  email_configs:
  - to: 'xxxxxxxx'

inhibit_rules: # 抑制規則
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance', 'prod']

啟動
cd /usr/local/prometheusAlert/

./alertmanager --web.external-url="http://xxxx:8893" --web.listen-address="0.0.0.0:8893" --cluster.listen-address="0.0.0.0:8894" --config.file=alertmanager.yml

關閉程序
ps -ef |grep alertmanager |awk '{print $2}'|xargs kill -9

靜默啟動
nohup ./alertmanager --web.external-url="http://xxxxx:8893" --web.listen-address="0.0.0.0:8893" --cluster.listen-address="0.0.0.0:8894" --config.file=alertmanager.yml > server_alertmanager.log 2>&1 &

瀏覽器訪問
http://xxxxxxx:8893/#/alerts

config官網
https://prometheus.io/docs/alerting/latest/configuration/#route

訪問:
http://localhost:8893

告警json

點選檢視程式碼

{
  "receiver": "web\\.hook",
  "status": "resolved",
  "alerts": [
    {
      "status": "resolved",
      "labels": {
        "alertname": "ckExceptionAlert",
        "app": "gateway",
        "appName": "getindex",
        "severity": "warning"
      },
      "annotations": {
        "description": "告警當前值:3.0508474576271185",
        "summary": "系統監控最近5分鐘服務異常"
      },
      "startsAt": "2024-08-07T10:51:10.04Z",
      "endsAt": "2024-08-07T10:52:40.04Z",
      "generatorURL": "http://http://8.219.198.22:9090/graph?g0.expr=sum+by+%28appName%29+%28increase%28app_invoke_error_count_total%5B5m%5D%29%29+%3E+1\u0026g0.tab=1",
      "fingerprint": "a01e6c598cd57929"
    }
  ],
  "groupLabels": {
    "alertname": "ckExceptionAlert"
  },
  "commonLabels": {
    "alertname": "ckExceptionAlert",
    "app": "gateway",
    "appName": "getindex",
    "severity": "warning"
  },
  "commonAnnotations": {
    "description": "告警當前值:3.0508474576271185",
    "summary": "系統監控最近5分鐘服務異常"
  },
  "externalURL": "http://http://8.219.198.22:8893",
  "version": "4",
  "groupKey": "{}:{alertname=\"ckExceptionAlert\"}",
  "truncatedAlerts": 0
}


相關文章