【问题标题】:Automate adding new Node Exporters to the targets array of prometheus.yml自动将新节点导出器添加到 prometheus.yml 的目标数组
【发布时间】:2017-06-27 11:38:54
【问题描述】:

我的环境中有一个基本的 prometheus.yml 文件,即 ..

###
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: prometheus-core
data:
  prometheus.yml: |
    global:
      scrape_interval: 10s
      scrape_timeout: 10s
      evaluation_interval: 10s

    rule_files:
      - '/etc/prometheus-rules/*.rules'

    scrape_configs:
       # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: 'prometheus'

        # Override the global default and scrape targets from this job every 5 seconds.
        scrape_interval: 5s

        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.

        static_configs:
          - targets: ['localhost:9090'] 

现在,如果我将新节点添加到我的环境中,我的 prometheus.yml 文件应该会自动更新并将节点添加到下面的目标,即

###
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: prometheus-core
data:
  prometheus.yml: |
    global:
      scrape_interval: 10s
      scrape_timeout: 10s
      evaluation_interval: 10s

    rule_files:
      - '/etc/prometheus-rules/*.rules'

    scrape_configs:
       # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: 'prometheus'

        # Override the global default and scrape targets from this job every 5 seconds.
        scrape_interval: 5s

        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.

        static_configs:
          - targets: ['localhost:9090','12.10.17.6:9100','12.10.17.19:9100'] 

谁能建议我如何做到这一点?

【问题讨论】:

    标签: docker kubernetes prometheus kubectl


    【解决方案1】:

    Prometheus 支持 Kubernetes 服务发现机制,详见documentation。

    因此,您应该添加类似于以下内容的部分,而不是 static_configs 部分:

    scrape_configs:
    - job_name: 'kubernetes-service-endpoints'
    
      kubernetes_sd_configs:
      - role: endpoints
    
    ...
    

    请参阅此example configuration file 了解它是如何完成的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 2012-01-08
      • 2021-03-16
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      相关资源
      最近更新 更多