gpt4 book ai didi

docker - 自动将新的节点导出器添加到prometheus.yml的目标数组

转载 作者:行者123 更新时间:2023-12-02 11:41:27 25 4
gpt4 key购买 nike

我的环境中有一个基本的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']

有人可以建议我如何实现这一目标吗?

最佳答案

Prometheus支持Kubernetes服务发现机制,有关详细信息,请参见documentation

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

scrape_configs:
- job_name: 'kubernetes-service-endpoints'

kubernetes_sd_configs:
- role: endpoints

...

查看此 example configuration file的操作方法。

关于docker - 自动将新的节点导出器添加到prometheus.yml的目标数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44779354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com