This is an automated email from the ASF dual-hosted git repository. gongchao pushed a commit to branch fix-third-alarm in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
commit 4f98990806064b88a32605e3f9c9247eb0fdbf91 Author: tomsun28 <tomsu...@outlook.com> AuthorDate: Sun Jan 12 18:00:26 2025 +0800 [webapp] add alert integration Signed-off-by: tomsun28 <tomsu...@outlook.com> --- .../doc/alert-integration/prometheus.en-US.md | 89 +++++++--------------- .../doc/alert-integration/prometheus.zh-TW.md | 77 ++++++------------- 2 files changed, 49 insertions(+), 117 deletions(-) diff --git a/web-app/src/assets/doc/alert-integration/prometheus.en-US.md b/web-app/src/assets/doc/alert-integration/prometheus.en-US.md index 5e6f669ac4..7f98a5dc04 100644 --- a/web-app/src/assets/doc/alert-integration/prometheus.en-US.md +++ b/web-app/src/assets/doc/alert-integration/prometheus.en-US.md @@ -1,78 +1,41 @@ -# Prometheus Alert Integration +可以在 Prometheus Server 的 Alertmanager 配置中直接配置 HertzBeat 的服务地址,使用 HertzBeat 替换 Alertmanager 直接来接收处理 Prometheus Server 的告警信息。 + +### Prometheus Service Configuration + +- Edit the Prometheus configuration file `prometheus.yml` to add HertzBeat as the alert receiver configuration +```yaml +# Alertmanager configuration +alerting: + alertmanagers: + - static_configs: + - targets: + - hertzbeat-host:1157 + authorization: + type: 'Bearer' + credentials: '{token}' -HertzBeat is fully compatible with Prometheus alert data format. You can configure Prometheus alerting rules to send alerts to HertzBeat. - -## Prometheus Alert Configuration - -> Since Prometheus Server itself doesn't support sending alerts via HTTP API, external scripts or Alertmanager are needed to implement alert sending. -> If using Alertmanager, please refer to the **Alertmanager Integration Documentation**. Here we provide the alert configuration method for Prometheus Server without deploying Alertmanager. - -### Prometheus Alert Configuration - -1. Edit Prometheus configuration file `prometheus.yml`, add alert rules configuration - ```yaml - rule_files: - - "rules/*.rules.yml" - ``` - > `rules/*.rules.yml` is the path to alert rule files, which can be modified according to actual situations -> 2. Create alert rules folder `rules` and create alert rule files `rules/*.rules.yml` -> 3. Edit alert rule files, add alert rule configurations -> 4. Reload Prometheus configuration - -### Write Scripts to Send Alerts Automatically - -> Since Prometheus Server itself doesn't support sending alerts via HTTP API, we'll use Python scripts to implement alert sending. - -1. Install Python requests library - ```bash - pip install requests - ``` -2. Write Python script `send_alerts.py` -```python -import requests - -PROMETHEUS_URL = "http://<prometheus-host>:9090/api/v1/alerts" -WEBHOOK_URL = "http://<hertzbeat-host>:1157/api/alerts/report/prometheus" - -def get_prometheus_alerts(): - response = requests.get(PROMETHEUS_URL) - alerts = response.json()["data"]["alerts"] - return alerts - -def send_to_webhook(alert): - requests.post(WEBHOOK_URL, json=alert) - -if __name__ == "__main__": - while True: - alerts = get_prometheus_alerts() - for alert in alerts: - send_to_webhook(alert) - # schedule cyclic task, every 300s once - time.sleep(300) - ``` -3. Run Python script - ```bash - python send_alerts.py - ``` - > This script will fetch alert data from Prometheus Server and push it to HertzBeat alert platform via Webhook. +> `hertzbeat-host:1157` is the address and port of the HertzBeat Server, modify according to the actual situation, and ensure network connectivity. +> `{token}` is the authorization Token for the HertzBeat Server, replace the value after applying for a new Token. + +- Reload and start the Prometheus Server ## Verify Configuration -1. Ensure Prometheus configuration is correct and reload configuration +1. Ensure the Prometheus configuration is correct and reload the configuration ```bash curl -X POST http://localhost:9090/-/reload ``` -2. Check Prometheus alert rules status +2. Check the status of Prometheus alert rules ```bash curl http://localhost:9090/api/v1/rules ``` -3. Trigger test alerts and check in HertzBeat alert center +3. Trigger a test alert and check in the HertzBeat alert center. ## Common Issues -- Ensure HertzBeat URL is accessible from Prometheus server -- Check Prometheus logs for alert sending failure error messages -- Verify the correctness of alert rule expressions +- Ensure the HertzBeat URL is accessible from the Prometheus server. +- Check the Prometheus logs for any error messages regarding alert sending failures. +- Verify the correctness of the alert rule expressions. -For more information, please refer to [Prometheus Alerting Documentation](https://prometheus.io/docs/alerting/latest/configuration/) +For more information, please refer to the [Prometheus Alert Configuration Documentation](https://prometheus.io/docs/alerting/latest/configuration/) diff --git a/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md b/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md index 7dcf5b57ae..d875e64d53 100644 --- a/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md +++ b/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md @@ -1,55 +1,24 @@ -> 由於 Prometheus Server 本身並不支持 HTTP API 的告警發送,因此需要借助外部腳本或者 Alertmanager 來實現告警發送。 -> 若使用 Alertmanager,可參考 **Alertmanager 集成文檔**。這裡提供非部署 Alertmanager 的 Prometheus Server 的告警配置方法。 +可以在 Prometheus Server 的 Alertmanager 配置中直接配置 HertzBeat 的服務地址,使用 HertzBeat 替換 Alertmanager 直接來接收處理 Prometheus Server 的告警信息。 + +### Prometheus 服務配置 + +- 編輯 Prometheus 配置文件 `prometheus.yml`,添加 HertzBeat 作為告警接收端配置 +```yaml +# Alertmanager configuration +alerting: + alertmanagers: + - static_configs: + - targets: + - hertzbeat-host:1157 + authorization: + type: 'Bearer' + credentials: '{token}' -### Prometheus 告警配置 - -1. 編輯 Prometheus 配置文件 `prometheus.yml`,添加告警規則配置 - ```yaml - rule_files: - - "rules/*.rules.yml" - ``` - > `rules/*.rules.yml` 為告警規則文件路徑,可以根據實際情況修改 -> 2. 創建告警規則文件夾 `rules`,並創建告警規則文件 `rules/*.rules.yml` -> 3. 編輯告警規則文件,添加告警規則配置 -> 4. 重新加載 Prometheus 配置 - -### 編寫腳本自動發送告警 - -> 由於 Prometheus Server 本身並不支持 HTTP API 的告警發送,這裡我們使用 Python 腳本來實現告警發送。 - -1. 安裝 Python requests 庫 - ```bash - pip install requests - ``` -2. 編寫 Python 腳本 `send_alerts.py` -```python -import requests - -PROMETHEUS_URL = "http://<prometheus-host>:9090/api/v1/alerts" -WEBHOOK_URL = "http://<hertzbeat-host>:1157/api/alerts/report/prometheus" - -def get_prometheus_alerts(): - response = requests.get(PROMETHEUS_URL) - alerts = response.json()["data"]["alerts"] - return alerts - -def send_to_webhook(alert): - requests.post(WEBHOOK_URL, json=alert) - -if __name__ == "__main__": - while True: - alerts = get_prometheus_alerts() - for alert in alerts: - send_to_webhook(alert) - # 设置定时任务,例如每 300 秒即 5 分钟执行一次 - time.sleep(300) - ``` -3. 運行 Python 腳本 - ```bash - python send_alerts.py - ``` - > 該腳本會從 Prometheus Server 獲取告警數據,並通過 Webhook 推送到 HertzBeat 告警平台。 +> `hertzbeat-host:1157` 為 HertzBeat Server 地址和端口,根據實際情況修改,需要保證網絡連通性。 +> `{token}` 為 HertzBeat Server 的授權 Token,申請新 Token 後替換值。 + +- 重新加載啟動 Prometheus Server ## 驗證配置 @@ -61,12 +30,12 @@ if __name__ == "__main__": ```bash curl http://localhost:9090/api/v1/rules ``` -3. 觸發測試告警並在 HertzBeat 告警中心查看 +3. 觸發測試告警並在 HertzBeat 告警中心查看。 ## 常見問題 -- 確保 HertzBeat URL 可以被 Prometheus 服務器訪問 -- 檢查 Prometheus 日誌中是否有告警發送失敗的錯誤信息 -- 驗證告警規則表達式的正確性 +- 確保 HertzBeat URL 可以被 Prometheus 伺服器訪問。 +- 檢查 Prometheus 日誌中是否有告警發送失敗的錯誤信息。 +- 驗證告警規則表達式的正確性。 更多信息請參考 [Prometheus 告警配置文檔](https://prometheus.io/docs/alerting/latest/configuration/) --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@hertzbeat.apache.org For additional commands, e-mail: notifications-h...@hertzbeat.apache.org