Prometheus 基于文件的服务发现
Prometheus 基于文件的服务发现
官方文档:https://github.com/prometheus/prometheus/tree/master/discovery
服务发现支持: endpoints,ingress,kubernetes,node,pod,service。
Prometheus也提供了服务发现功能,可以从consul,dns,kubernetes,file等等多种来源发现新的目标。
其中最简单的是从文件发现服务。
? azure_sd_configs
? consul_sd_configs
? dns_sd_configs
? ec2_sd_configs
? openstack_sd_configs
? file_sd_configs
? gce_sd_configs
? kubernetes_sd_configs
? marathon_sd_configs
? nerve_sd_configs
? serverset_sd_configs
? triton_sd_configs
Prometheus 支持服务发现的来源:
1、编写配置文件:vim prometheus.yml
scrape_configs: - job_name: 'prometheus' # 使用基于文件服务发现 file_sd_configs: # 指定服务发现的目录及配置文件 - files: ['/usr/local/prometheus/sd_config/*.yml'] # 每过5秒动态发现服务配置 refresh_interval: 5s
2、创建目录
mkdir /usr/local/prometheus/sd_config
3、写入配置文件
vim /usr/local/prometheus/sd_config/test.yml
# 添加本地主机并填入标签 - targets: ['localhost:9090'] labels: idc: bj