基於文件的服務發現方式不須要依賴其餘平臺與第三方服務,用戶只需將要新的target信息以yaml或json文件格式添加到target文件中 ,prometheus會按期從指定文件中讀取target信息並更新。node
vim /usr/local/prometheus-2.1/targets.json [ { "targets": [ "192.168.20.136:9100"], "labels": { "instance": "nodeone", "job": "expor_test1" } }, { "targets": [ "localhost:9090"], "labels": { "job": "prometheus" } }, { "targets": [ "192.168.20.137:9100"], "labels": { "instance": "nodetwo", "job": "expor_test2" } } ]
global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: ['localhost:9093'] rule_files: # - "/usr/local/prometheus-2.1/rule.yml" # - "/usr/local/prometheus-2.1/rule2.yml" scrape_configs: - job_name: 'file_ds' #此處定義了自動發現的採集任務 file_sd_configs: - files: - targets.json #採集文件名
./prometheus &
查看web界面targets 出現targets.json 所定義的3個job。web