在 Prometheus 的警告规则中,可以使用 summary
函数来计算一个时间窗口内的概要统计信息。但是,对于 summary 类型的指标,在警告规则的 expr
表达式中无法直接访问标签(labels)。
如果你需要根据某个标签值进行条件判断或者过滤,可以使用 quantile_over_time
函数结合正则表达式来实现类似的功能。以下是一个示例:
ALERT example_alert
IF quantile_over_time(0.95, my_summary_metric{label=~"my_label_regex"}) > threshold
FOR 5m
LABELS {severity="critical"}
ANNOTATIONS {
summary = "Summary of the alert",
description = "Detailed description of the alert"
}
上述示例中,我们通过使用 quantile_over_time
函数和正则表达式来获取匹配特定标签模式的指标数据,并进行条件判断。
请根据自己的需求修改相应的指标名称、标签名称和正则表达式等参数。
内容由零声教学AI助手提供,问题来源于学员提问