Prometheus提供服务发现功能,能够从consul、dns、kubernetes等多种来源发现目标。其中,基于文件的服务发现是Prometheus服务发现最简单的。

编写prometheus.yml

- job_name: 'pushgateway'
honor_labels: true
file_sd_configs:
# 指定服务发现的目录及配置文件
- files: ['/etc/prometheus/conf/*.yml']
# 每过5s动态发现服务配置
refresh_interval: 5s

创建目录

mkdir -p /etc/prometheus/conf

写入配置文件

[root@localhost conf]# cat test.yml 
- targets: ['localhost:9091','localhost:9092']
labels:
area: nj

更新prometheus配置

# 检查配置
./promtool check config prometheus.yml
# 发送hup信号
kill -hup 17386

刷新浏览器页面,可以看到添加的标签