完整译文请访问:http://www.coderdocument.com/docs/prometheus/v2.14/prometheus/configuration/template_examples.html。
Prometheus支持模板化告警的注解和标签以及服务控制台页面。模板能够对本地数据库运行查询、遍历数据、使用条件、格式化数据等等。Prometheus模板语言基于Go模板系统。
简单的告警字段模板
alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
summary: "Instance {
{$labels.instance}} down"
description: "{
{$labels.instance}} of job {
{$labels.job}} has been down for more than 5 minutes."
告警字段模板将在每次触发警报的规则遍历期间执行,因此要保持所有查询和模板都是轻量级的。如果你需要更复杂的警报模板,建议你链接到控制台。
简单遍历
如下显示一个实例列表,以及它们是否启动:
{
{