【问题标题】:Error with external_labels config in alertmanager.yml section of helm Prometheus values.yamlhelm Prometheus values.yaml 的 alertmanager.yml 部分中的 external_labels 配置出错
【发布时间】:2021-11-03 21:16:02
【问题描述】:

我已经使用 helm 将 prometheus 安装到我的 kubernetes 集群中,如下所示;

helm list
NAME        NAMESPACE   REVISION    UPDATED                                 STATUS      CHART               APP VERSION
prometheus  prometheus  9           2021-09-07 08:54:54.262013 +0100 +01    deployed    prometheus-14.6.0   2.26.0

我正在尝试在 values.yaml 中应用 external_labels 来识别发送到 Alertmanager 的时间序列。我已经使用 prometheus 文档来获得我认为正确的配置,如下所示;

alertmanagerFiles:
  alertmanager.yml:
    global:
      external_labels:
        environment: 'perf'

我的安装没问题;

helm upgrade --install prometheus .

但是由于以下错误,我的 prometheus-server pod 崩溃了;

level=error ts=2021-09-06T18:49:25.059Z caller=coordinator.go:124 component=configuration msg="Loading configuration file failed" file=/etc/config/alertmanager.yml err="yaml: unmarshal errors:\n  line 2: fie │
│ ld external_labels not found in type config.plain"

这里的许多答案都指向缩进问题,但是我看不出我做错了什么……来自 Prometheus 文档;

global:
  # The labels to add to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    [ <labelname>: <labelvalue> ... ]

一两个星期以来,我一直在摸不着头脑 - 希望能有第二双更有经验的眼睛,谢谢! ????

【问题讨论】:

    标签: kubernetes prometheus kubernetes-helm prometheus-alertmanager


    【解决方案1】:

    我已经设法让这个工作..首先我把配置放在完全错误的地方。我在查看 prometheus alertmanager 的 github 页面时发现了这一点,但我看不到“良好配置测试”中定义的字段,因此必须在其他地方进行配置..

    确实 prometheus 配置 page 这么说 - 所以我在 ## Prometheus 服务器 ConfigMap 条目下添加了一个部分;

    serverFiles:
      prometheus.yml:
        global:
          external_labels:
            environment: perf
    

    这也不起作用,吊舱崩溃了。事实证明,这应该在 values.yaml 中配置 prometheus-server 容器本身的部分中进行配置 - 其中顶级字段 = 服务器,我们可以看到这里也配置了默认的全局值。所以我在这个部分添加了 external_labels;

    server: 
      global:
        scrape_interval: 1m
        scrape_timeout: 10s
        evaluation_interval: 1m
        external_labels:
          environment: perf
    

    当我使用helm upgrade --install prometheus . 升级时,我现在可以在kubectl get cm prometheus-server -o yaml 中看到正确的配置,而且我的寻呼机职责警报现在会在摘要中显示环境名称。

    关于如何在不必杀死 pod/创建 OOM 等的情况下测试警报的一个小技巧是创建一个警报 expr:它会不断触发(例如 kube_pod_container_status_restarts_total &gt; 3),这是我偶然做的,但被证明非常有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 2021-06-17
      • 1970-01-01
      • 2021-02-12
      • 2021-12-10
      • 2021-07-29
      相关资源
      最近更新 更多