prometheus服务发现之consul

文章目录


前言

我们平时使用 prometheus 收集监控数据,例如通过 node_exporter 获取监控数据,那每次新增一个监控的节点,我们都得相对应地修改 prometheus 的配置文件并重启他,相当麻烦,于是,prometheus 就提供了服务发现地机制,可以动态新增监控的节点。


一、Consul 在这里的作用

consul 这里是用于实现prometheus的服务发现,可以让prometheus动态地发现和监控在 Consul 注册的服务,实现便捷的注册新的监控节点。

二、原理

将节点信息(exporter)注册到consul,然后将consul注册到promethesu,这样prometheus就能自动识别里面对应的节点信息。不需要每次新增删除一个监控节点,还得修改prometheus的配置并重启,只需要调用consul的API就可以注册进去,实现动态新增删除。

根据服务名区分node_exporter、process_exporter等不同的组件,然后每个组件都可以注册多个节点(注册中心一个服务多个实例集群的概念)。

三、实现过程

安装 consul

下载:
https://releases.hashicorp.com/consul/1.17.0/consul_1.17.0_linux_amd64.zip

解压,进去目录,启动

bash 复制代码
nohup ./consul agent -dev -data-dir=/usr/local/consul/data -client 0.0.0.0 &

访问 consul

http://192.168.231.56:8500

节点信息(exporter)注册进去consul

把节点的实际 ip 替换下面的 ${ip}

bash 复制代码
curl -X PUT -d '{ "id": "${ip}", "name": "node_exporter", "address": "${ip}", "port": 9100, "tags": ["prometheus"], "checks": [{"http": "http://${ip}:9100/metrics","interval": "10s"}]}'  http://192.168.231.56:8500/v1/agent/service/register

节点信息(exporter)从consul解除注册:

把节点的实际 ip 替换下面的 ${ip}

bash 复制代码
curl --request PUT http://192.168.231.56:8500/v1/agent/service/deregister/${ip}

prometheus配置consul地址

下面用你节点的实际 ip 替换

bash 复制代码
scrape_configs:
  - job_name: 'node_exporter'
    consul_sd_configs:
      - server: '192.168.231.56:8500'
        services: ['node_exporter']

总结

欢迎指出我的错误!

相关推荐
学不完的12 小时前
ZrLog 高可用架构监控部署指南(Prometheus + Grafana)
linux·运维·架构·负载均衡·grafana·prometheus·ab测试
kft13141 天前
Docker 部署 3 节点 Consul 集群
docker·容器·consul
桌面运维家2 天前
Prometheus服务器监控告警实战指南
运维·服务器·prometheus
秦渝兴3 天前
MySQL容器部署Prometheus+Granfana全流程
grafana·prometheus
人间打气筒(Ada)3 天前
go实战案例:如何基于 Conul 给微服务添加服务注册与发现?
开发语言·微服务·zookeeper·golang·kubernetes·etcd·consul
布史4 天前
Prometheus Python Client 实操指南:从零实现自定义 Exporter
网络·python·prometheus
JiaHao汤6 天前
微服务注册中心深度解析:Eureka、Consul、Nacos 从原理到实战
spring cloud·微服务·eureka·consul
Yu_摆摆6 天前
windows部署prometheus+windows_exporter+grafana+alertmanager实现监控CPU、内存、磁盘并邮件告警
windows·grafana·prometheus
indexsunny8 天前
互联网大厂Java面试实战:从Spring Boot到微服务架构的深度解析
java·spring boot·spring cloud·kafka·prometheus·security·microservices
**蓝桉**8 天前
Prometheus的服务发现机制
服务发现·prometheus