prometheus 基于文件的目标发现
1、创建目录
cd /usr/local/prometheus/conf mkdir -pv targets/{nodes,docker}
2、修改prometheus.yml文件
scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node_exporter' file_sd_configs: - files: - targets/nodes/*.json refresh_interval: 1m - job_name: 'docker' file_sd_configs: - files: - targets/docker/*.json refresh_interval: 1m
3、新增targets/nodes/nodes.json文件
[{ "targets": [ "192.168.31.151:9100", "192.168.31.82:9100", "192.168.31.144:9100" ] }]
4、新增targets/docker/docker.json文件
[{ "targets": [ "192.168.31.151:8080", "192.168.31.144:8080", "192.168.31.82:8080" ], "labels": { "datacenter":"sh" } }]
5、重载
ps -ef|grep prom |grep -v grep|awk '{print $2}'|xargs kill -HUP