【问题标题】:Prometheus Operator change the scrape_intervalPrometheus Operator 更改 scrape_interval
【发布时间】:2020-11-04 15:05:36
【问题描述】:

我想将 Prometheus 的 scrape_interval 设置为 15 秒。我下面的配置不起作用,最后一行有错误。我想知道我应该如何配置 15 秒 scrape_interval

apiVersion: monitoring.coreos.com/v1
    kind: Prometheus
    metadata:
      name: main
    spec:
      serviceAccountName: prometheus
      replicas: 1
      version: v1.7.1
      serviceMonitorNamespaceSelector: {}
      serviceMonitorSelector:
        matchLabels:
          team: frontend
      ruleSelector:
        matchLabels:
          role: alert-rules
          prometheus: rules
      resources:
        requests:
          memory: 400Mi
    scrape_interval: 15s  ##Error in this line.

我在编译上面的配置时收到了这个错误消息:

error: error validating "promethus.yml": error validating data: ValidationError(Prometheus): unknown field "scrape_interval" in com.coreos.monitoring.v1.Prometheus; if you choose to ignore these errors, turn validation off with --validate=false

谢谢!

【问题讨论】:

    标签: docker kubernetes prometheus prometheus-operator


    【解决方案1】:

    scrape_interval 可能是 prometheus 配置中的参数名称,而不是 k8s 中的 Prometheus 对象(由 prometheus-operator 读取并用于生成实际配置)。

    您可以在prometheus operator documentation 中看到您要查找的参数是scrapeInterval。确保缩进正确,这应该是spec: 的一部分。

    请注意,您不必全局更改抓取间隔。您可以在 ServiceMonitor 对象中定义每次抓取目标的时间间隔。

    【讨论】:

      【解决方案2】:

      scrape_interval 应该在全局 Prometheus configuration 之下:

      Prometheus 配置为YAML。普罗米修斯下载来了 在名为prometheus.yml 的文件中包含示例配置,这是一个 开始的好地方。

      Here 是有效配置 YAML 的示例。请注意:

      # my global config
      global:
        scrape_interval:     15s
        evaluation_interval: 30s
        # scrape_timeout is set to the global default (10s).
      

      您的名为“promethus.yml”的文件带有apiVersion: monitoring.coreos.com/v1 与我上面提到的配置文件prometheus.yml 不同,因此添加scrape_interval 会导致验证错误。 您不能将 Prometheus 配置与 Prometheus Operator 的配置混合使用。这些是不同的概念。

      我还建议通过 the official guide 更好地掌握 Prometheus,它是 configuration options。或者坚持使用Prometheus Operator

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-29
        • 2017-03-06
        • 1970-01-01
        • 2020-10-08
        • 1970-01-01
        • 1970-01-01
        • 2020-01-31
        • 2021-02-12
        相关资源
        最近更新 更多