【问题标题】:在 prometheus 警报配置中添加端点作为接收器
【发布时间】:2022-01-16 16:07:54
【问题描述】:
我正在尝试使用警报激活我的 Spring Boot 应用程序端点,因为在 prometheus 的警报规则中定义的所需事件已损坏,因此我想将我的应用程序端点添加为接收器以接收来自普罗米修斯警报管理器。谁能建议如何将端点配置为此receiver 标签的接收器,而不是任何其他推送通知器?
- receiver: 'frontend-pager'
group_by: [product, environment]
matchers:
- team="frontend"
【问题讨论】:
标签:
spring-boot
prometheus
endpoint
prometheus-alertmanager
prometheus-java
【解决方案1】:
我认为“webhook 接收器”可以帮助您。更多信息可以参考dochttps://prometheus.io/docs/alerting/latest/configuration/#webhook_config
这是一个基于 blackbox_exporter 的指标抓取创建的 webhook 警报示例。
- prometheus 规则设置
您需要创建规则来触发警报,这里定义了一个名为“http_health_alert”的规则作为示例。
groups:
- name: http
rules:
- alert: http_health_alert
expr: probe_success == 0
for: 3m
labels:
type: http_health
annotations:
description: Health check for {{$labels.instance}} is down
- Alertmanager 设置
'match'设置为http_health_alert,警报会通过HTTP/POST方式发送到'http://example.com/alert/receiver'(我想你会提前准备好)。
警报会将 JSON 格式发布到配置的端点“http://example.com/alert/receiver”。并且还可以针对不同的标签内容,在端点/程序中自定义不同的接收方式或接收信息。
global:
route:
group_by: [alertname, env]
group_wait: 30s
group_interval: 3m
repeat_interval: 1h
routes:
- match:
alertname: http_health_alert
group_by: [alertname, env]
group_wait: 30s
group_interval: 3m
repeat_interval: 1h
receiver: webhook_receiver
receivers:
- name: webhook_receiver
webhook_configs:
- send_resolved: true
url: http://example.com/alert/receiver
- name: other_receiver
email_configs:
- send_resolved: true
to: xx
from: xxx