【问题标题】:can't evaluate field instance in type struct : AlertManager无法评估结构类型中的字段实例:AlertManager
【发布时间】:2020-09-21 13:39:03
【问题描述】:

我已经使用 AlertManager 服务器(与 Prometheus 安装在同一台服务器中)配置了关于 CloudWatch 导出器关闭时的警报。规则如下:

groups:
- name: Alerts
  rules:

      # Alert for any instance that is unreachable for >5 minutes.
      - alert: CloudWatchExporterDown
        expr: up{instance="localhost:9106",job="cloudwatch_exporter"} == 0
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Instance {{ .instance }} down"
          description: "{{ .instance }} of job {{ .job }} has been down for more than 5 minutes."

现在我在 /var/log/messages 中有这些错误:

Sep 21 03:55:50 ip-10-193-192-40 prometheus: level=warn ts=2020-09-21T03:55:50.728Z caller=alerting.go:343 component="rule manager" alert=CloudWatchExporterDown msg="Expanding alert template failed" err="error executing template __alert_CloudWatchExporterDown: template: __alert_CloudWatchExporterDown:1:92: executing \"__alert_CloudWatchExporterDown\" at <.instance>: can't evaluate field instance in type struct { Labels map[string]string; ExternalLabels map[string]string; Value float64 }" data="unsupported value type"

我想知道规则有什么问题?为什么不计算表达式 { .instance }?

【问题讨论】:

    标签: json prometheus prometheus-alertmanager


    【解决方案1】:

    普罗米修斯正在使用Go language templating

    标签和注释值可以使用控制台模板进行模板化。 $labels 变量保存警报实例的标签键/值对。可以通过 $externalLabels 变量访问配置的外部标签。 $value 变量保存警报实例的评估值。

    从您可以找到的文档和示例中,正确的表达式应该使用$labels

    summary: "Instance {{ $labels.instance }} down"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 2019-06-08
      • 1970-01-01
      • 2019-11-02
      • 2020-10-21
      • 1970-01-01
      • 2022-08-16
      相关资源
      最近更新 更多