Автоматизируйте добавление новых экспортеров узлов в массив целей prometheus.yml
У меня есть базовый файл 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']
Кто-нибудь может подсказать, как мне этого добиться?
1 ответ
Prometheus поддерживает механизмы обнаружения службы Kubernetes, подробности см. В документации.
Так что вместо static_configs
раздел, вы должны добавить раздел, похожий на этот:
scrape_configs:
- job_name: 'kubernetes-service-endpoints'
kubernetes_sd_configs:
- role: endpoints
...
Посмотрите этот пример файла конфигурации, чтобы узнать, как это делается.