基于文件发现不需要重启或热加载peometheus
----prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
file_sd_configs:
- refresh_interval: 10s
files:
- "targets/target.yml"
- job_name: "node_exporter"
file_sd_configs:
- refresh_interval: 10s #每隔十秒读取一次文件
files:
- "targets/node_exporter.yml"
- job_name: "pushgateway"
file_sd_configs:
- refresh_interval: 10s
files:
- "targets/pushgateway.yml"
[root@localhost targets]# pwd
/opt/prometheus/targets
[root@localhost targets]# ls
node_exporter.yml pushgateway.yml target.yml
[root@localhost targets]# cat node_exporter.yml
- targets: ['192.168.49.217:9100']
labels:
job: node_exporter
[root@localhost targets]# cat pushgateway.yml
- targets: ['192.168.49.217:9091']
labels:
job: pushgateway
[root@localhost targets]# cat target.yml
- targets: ['192.168.49.217:9090']
labels:
job: prometheus
配置完重启peometheus正常运行后修改对应服务的文件
--添加标签测试
[root@localhost targets]# cat target.yml
- targets: ['192.168.49.217:9090']
labels:
job: prometheus
env: test
可以看到web端自动展示新添加的标签