我想在prometheus警报中使用单引号,但除了使用双引号之外,我不能在描述中换行。由于我在描述中使用{{ $value | printf "%.2f" }}
,我无法使用双引号,因此如何在此处使用单引号?有什么想法吗?
- alert: MemoryHigh
expr: (x_process_resident_memory_bytes / y_resident_memory_limit_bytes) * 100 > 90
for: 2m
labels:
x: y
annotations:
summary: Memory high (instance {{ $labels.instance }})
description: '{{ $labels.pod }} in {{ $labels.environment}} is using more than 90% of allocated RAMn Memory = {{ $value | printf "%.2f" }}n Environment = {{ $labels.environment}}'
我也尝试过下面的描述,放置新行而不是使用n
本身,但它不起作用。
description: '{{ $labels.pod }} in {{ $labels.environment}} is using more than 90% of allocated RAM
Memory = {{ $value | printf "%.2f" }}
Environment = {{ $labels.environment}}'
Prometheus警报模板的实现基于Golang text/template和html/template包。
单引号值的行为类似于原始字符串文字。
您可以在格式化函数中转义双引号,并用双引号设置描述值。
{{ $value | printf "%.2f" }}
您也可以将描述提供为标量。
description: |
{{ $labels.pod }} in {{ $labels.environment}} is using more than 90% of allocated RAM
Memory = {{ $value | printf "%.2f" }}
Environment = {{ $labels.environment}}