
我已經設定了 Prometheus 的 Alertmanager 來管理來自 Prometheus 的警報。我收到了從 Prometheus 發送到 Alertmanager 的警報,但故事到此結束。 Alertmanager 永遠不會將警報發送到我的電子郵件端點。
為了弄清楚警報在 Alertmanager 內部到底在哪裡結束了它們的旅程,我想將日誌等級從“資訊”變為“調試”,但無法弄清楚如何操作。即使現在找到日誌似乎也是一個艱鉅的任務,它不存在/var/log
並且journalctl -u alertmanager
包含的內容太少,以至於可能在某個地方還有另一條日誌。
的手冊頁配置警報管理器沒有提到調試等級。我查看了原始程式碼中提到的 log 並發現該設定應該命名為log.level
.將以下程式碼片段新增至設定 YAML 也沒有幫助:
log:
level: debug
因為 Alertmanager 無法啟動,無法解析其設定檔。
答案1
答案是,不可能透過設定檔設定 Prometheus 的 Alertmanagers 日誌等級進行調試,只能透過命令列參數進行調試。不要問我為什麼,我相信他們有他們的理由。
透過 Puppet,我將參數新增到 Alertmanager 的 Systemd 單元檔案中,因此它最終看起來像這樣:
[Unit]
Description=Prometheus alertmanager
Wants=basic.target
After=basic.target network.target
[Service]
User=alertmanager
Group=alertmanager
EnvironmentFile=/etc/sysconfig/alertmanager
ExecStart=/usr/local/bin/alertmanager \
--config.file=/etc/alertmanager/alertmanager.yaml \
--storage.path=/var/lib/alertmanager \
--log.level=debug
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
如果您從 shell 啟動 Alertmanager,則只需將該標誌新增--log.level=debug
至您的呼叫即可。
journalctl -u alertmanager
然後可以透過 Linux 發行版上的 Systemd init 系統查看偵錯訊息。
答案2
在 Ubuntu 系統上(如果 prometheus-alertmanager 是透過 apt 和官方的儲存庫安裝)。
打開
/etc/default/prometheus-alertmanager
並添加
ARGS="--log.level=debug"
到檔案(替換 ARGS="")
然後透過systemd重啟prometheus-alertmanager:
sudo systemctl restart prometheus-alertmanager.service
透過journalctl顯示日誌:
journalctl -u prometheus-alertmanager.service --since today
答案3
在我的docker-compose.yml
下一步中我做了:command: --log.level=debug
查看具體資訊:
alertmanager:
restart: unless-stopped
image: prom/alertmanager:latest
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
- '--storage.path=/alertmanager'
- '--log.level=debug'
volumes:
- ./alertmanager.yml:/etc/alertmanager/alertmanager.yml
expose:
- 9093/tcp
networks:
monitoring-net: