Prometheus的服务发现

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的部署

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值