本文介绍了Prometheus Docker 无法以`Template: (dynamic): parse: template: :10: undefined variable "$labels"`开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Nomad 上运行 Prometheus.一切看起来都很好,但是当我在 annotations 中添加带有模板的警报规则时,它失败了.

I am trying to run Prometheus on Nomad. Everything things look fine but when I add an alert rule with templating in annotations it fails.

这是一个简单的警报规则:

here is a simple alert rule:

groups:
- name: alertmanager.rules
  rules:
  - alert: AlertmanagerDown
    expr: up{job="alertmanager"} == 0
    for: 1s
    labels:
      severity: critical
    annotations:
      description: 'Alertmanager on {{ $labels.role }} instance {{ $labels.node }} has not produced any metrics for 5 minutes'
      summary: 'Alertmanager is down on {{ $labels.role }} instance {{ $labels.node }}'

容器失败,Template: (dynamic): parse: template: :10: undefined variable "$labels"

如果我删除 annotations 部分,它开始时没有任何问题.

If I remove annotations section it starts without any issue.

推荐答案

必须将 left_delimiterright_delimiter 设置为 {{ 以外的其他内容和 }}https://www.nomadproject.io/docs/job-specification/template.html#left_delimiter

Had to set left_delimiter and right_delimiter to something other than {{ and }}https://www.nomadproject.io/docs/job-specification/template.html#left_delimiter

这篇关于Prometheus Docker 无法以`Template: (dynamic): parse: template: :10: undefined variable "$labels"`开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 00:25