修改 promethues.yml

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

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

    static_configs:
      - targets: ["localhost:9090"]
  - job_name: 'file_sd_test' #这里配置的是基于配置文件的服务发现
    scrape_interval: 10s # 定时刷新时间 
    file_sd_configs:
    - files:
       - /opt/prometheus/config/*.yml # 存放服务的配置文件

在/opt/prometheus/config/ 下创建yml文件

vim  /opt/prometheus/config/file_sd_test.yml

配置内容

- targets:
   - 192.168.10.3:9100
   - 192.168.10.21:9100  
  labels:
    app: node