六、Prometheus服务发现

目录

一、prometheus的服务发现

1、基于文件的服务发现

二、基于consul的服务发现


一、prometheus的服务发现

        Prometheus默认是采用pull的方式拉取监控数据的,每一个被抓取的目标都要暴露一个HTTP接口,prometheus通过这个接口来获取相应的指标数据,这种方式需要由prometheus-server决定采集的目标服务器有哪些,通过配置在scrape_configs中的各种job来实现,无法动态感知新服务,如果后面新增了节点或组件,就需要手动修改prometheus配置,然后重启服务或重新加载配置,所以出现了动态服务发现。

        每次增加exporter修改Prometheus.yml估计早就烦了

        Prometheus配置文件Prometheus.yml里配置需要监听的服务是,是按照服务名写死的,如果后面增加了节点或者组件信息,就得手动修改配置,并重启Prometheus或热加载太麻烦,那么能否动态的监听服务呢?有多种

1、基于文件的服务发现

        prometheus可以从指定的文件中动态发现监控目标,如果文件发生修改,prometheus会根据文件内容动态增加/删除target,无需重启服务。

        基于文件的服务发现主要是通过prometheus job配置中的consul_file_configs字段来配置

演示:

1、先创建target文件
[root@rabbitmq_2 prometheus]# mkdir target
2、创建yml文件
-rw-r--r--. 1 prometheus prometheus 425 12月 25 15:05 targets.yml
- targets : ['localhost:9090']
  labels:
    job: prometheus

- targets: ["localhost:9100"]
  labels:
    job: Prometheus服务器
    instance: Prometheus服务器

- targets: ["192.168.134.132:9100"]
  labels:
    job: node-exporter
    instance: test主服务器

- targets: ["192.168.134.132:9104"]
  labels:
    job: mysql_exporter
    instance: mysql服务

- targets: ["localhost:9091"]
  labels:
    job: pushgateway
3、编辑Prometheus配置,添加job,内容如下:
scrape_configs:

  - job_name: "file-sd-test"
    file_sd_configs:
    - refresh_interval: 10s    
      files:
      - "/opt/prometheus/prometheus/targets/targets.yml"
热加载一下 就好了
[root@rabbitmq_2 prometheus]# curl -X POST http://localhost:9090/-/reload

基于文件的服务发现和基于配置的服务发现的区别就是:不用重新加载prometheus,直接修改targets文件,prometheus会自动加载

二、基于consul的服务发现

        官网:Consul by HashiCorp

        只需要在consul中维护监控组件配置,prometheus就能够动态发现配置了。

Consul是一个分布式的服务发现和键/值存储系统

 后续更新。

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

繁华依在

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值