发现 target 的配置,定义在配置文件的 job 中
$ cat ./files-sd/prometheus.yml
# my global config
global:
scrape_interval: 10s
evaluation_interval: 10s
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- '10.139.32.97:9093'
- '10.135.50.73:9093'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "alerts/*.yml"
scrape_configs:
- job_name: 'Prometheus'
file_sd_configs: # 基于文件的服务发现关键字
- files: # 指定要加载的文件列表
- 'targets/prometheus-*.yaml' # 文件加载的路径,文件加载支持 glob 通配符
refresh_interval: 2m # 每隔 2 分钟重新加载一次文件中定义的 targets,默认为 5m
- job_name: 'nodes'
file_sd_configs:
- files:
- 'targets/nodes-*.yaml'
refresh_interval: 2m
$ cat targets/nodes-linux.yaml
- targets:
- 172.17.0.8:9100
- 172.17.0.9:9100
labels:
app: node-exporter
job: node
$
$ cat targets/prometheus-server.yaml
- targets:
- 172.17.0.6:9090 # prometheus-server 机器
labels:
app: prometheus
job: prometheus
$
启动 Prometheus
./prometheus --config.file=./files-sd/prometheus.yml