1基于文件服务发现
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'nodes'
file_sd_configs:
- files:
- targets/node*.yaml
refresh_interval: 2m
[root@db002-hf-aiui prometheus]# tree targets/
targets/
└── node03.yaml
0 directories, 1 file
[root@db002-hf prometheus]# cat targets/node03.yaml
- targets:
- 172.16.110.11:9101
labels:
app: node15
job: node-15
启动服务
/usr/local/prometheus/prometheus --config.file /usr/local/prometheus/prometheus-file.yml
2 consul服务发现
2.1 consul的部署
2.2 基础consul的服务发现
Prometheus的配置
scrape_configs:
- job_name: 'consul-node'
consul_sd_configs:
- server: '172.16.154.13:8500'
tags:
- "nodes"
refresh_interval: 5s
consul中的配置
[root@db002-hf config]# pwd
/usr/local/consul/config
[root@db002-hf config]# ls
node.json
[root@db002-hf config]# cat node.json
{
"services":[{
"id":"node02",
"name":"node02",
"address":"172.16.110.12",
"port":9101,
"tags":["nodes"],
"checks":[{
"http":"http://172.16.110.12:9101/mertics",
"interval":"5s"
}]
},
{
"id":"node03",
"name":"node03",
"address":"172.16.110.13",
"port":9101,
"tags":["nodes"],
"checks":[{
"http":"http://172.16.110.13:9101/mertics",
"interval":"5s"
}]
},
{
"id":"node_exporter",
"name":"node01",
"address":"172.16.110.11",
"port":9101,
"tags":["nodes"],
"checks":[{
"http":"http://172.16.110.11:9101/mertics",
"interval":"5s"
}]
}]
}
API形式注册,consul reload 也不会去掉api形式的注册。即使文件中没有下面这个节点的信息
curl -X PUT -d '{"id": "node04","name": "nodes","address": "172.16.110.14","port": 9101,"tags": ["nodes"],"checks": [{"http": "http://172.16.110.14:9101/metrics", "interval": "5s"}]}' http://172.16.110.10:8500/v1/agent/service/register