使用指标名称而不是指标标签进行匹配
Match using metric name instead of metric labels
我的一个出口商打印了一个没有标签的指标:
$ curl -s http://localhost:9999/metrics | grep service_up | grep -v "#"
service_up 1
在创建 AlertManager 接收器时,我通常使用 match
的度量标签之一(例如,job: 'nodeexporter-textcollector'
)。
例如,在这种情况下,AlertManager 配置如下所示:
route:
receiver: 'default'
routes:
- receiver: 'custom'
match:
severity: 'critical'
job: 'nodeexporter-textcollector'
但是,对于上述指标 (service_up
) 是否可以与指标名称匹配?
谢谢。
您需要创建一个自定义的命名警报并在其上放置正确的标签。例如 severity
就像这个例子。
# alerts/example-redis.yml
groups:
- name: ExampleRedisGroup
rules:
- alert: ExampleRedisDown
expr: redis_up{} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Redis instance down"
description: "Whatever"
此外,请注意 expr
字段,alermanager 将如何理解它需要触发一个 alert.Just 检查您的 alertmanager 分发中的 alerts
文件夹,有很多示例。
关于创建警报的官方文档:https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/
自定义提醒的更多示例:https://awesome-prometheus-alerts.grep.to/alertmanager
您已经为此指标定义了警报规则,对吗?类似于以下示例:
- alert: ServiceIsDown
expr: service_up == 0
现在,要路由此警报,您只需使用警报名称:
route:
receiver: 'default'
routes:
- receiver: 'custom'
match:
alertname: 'ServiceIsDown'
我的一个出口商打印了一个没有标签的指标:
$ curl -s http://localhost:9999/metrics | grep service_up | grep -v "#"
service_up 1
在创建 AlertManager 接收器时,我通常使用 match
的度量标签之一(例如,job: 'nodeexporter-textcollector'
)。
例如,在这种情况下,AlertManager 配置如下所示:
route:
receiver: 'default'
routes:
- receiver: 'custom'
match:
severity: 'critical'
job: 'nodeexporter-textcollector'
但是,对于上述指标 (service_up
) 是否可以与指标名称匹配?
谢谢。
您需要创建一个自定义的命名警报并在其上放置正确的标签。例如 severity
就像这个例子。
# alerts/example-redis.yml
groups:
- name: ExampleRedisGroup
rules:
- alert: ExampleRedisDown
expr: redis_up{} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Redis instance down"
description: "Whatever"
此外,请注意 expr
字段,alermanager 将如何理解它需要触发一个 alert.Just 检查您的 alertmanager 分发中的 alerts
文件夹,有很多示例。
关于创建警报的官方文档:https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/
自定义提醒的更多示例:https://awesome-prometheus-alerts.grep.to/alertmanager
您已经为此指标定义了警报规则,对吗?类似于以下示例:
- alert: ServiceIsDown
expr: service_up == 0
现在,要路由此警报,您只需使用警报名称:
route:
receiver: 'default'
routes:
- receiver: 'custom'
match:
alertname: 'ServiceIsDown'