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']

总结

欢迎指出我的错误!

相关推荐
星哥说事19 小时前
Zabbix与Prometheus在服务器及网络设备管理中的应用
服务器·zabbix·prometheus
cui_win2 天前
Prometheus实战教程 - mysql监控
mysql·prometheus·压测
拾忆,想起2 天前
Dubbo服务调用幂等性深度解析:彻底解决重复请求的终极方案
微服务·性能优化·服务发现·dubbo
nVisual2 天前
Prometheus连接nVisual实现资产拓扑业务关联分析
prometheus
Swift社区3 天前
数据库连接池监控最佳实践:用 Prometheus + Grafana 打造可视化监控体系
数据库·grafana·prometheus
yunson_Liu3 天前
grafana限制folder普通用户访问
grafana·prometheus
技术破壁人4 天前
《Prometheus + Grafana 监控体系实战》—— 从指标采集到智能告警!
grafana·prometheus
soft20015254 天前
Rocky Linux 9.6 环境下,Prometheus + Grafana 生产级安装手册
linux·grafana·prometheus
广目软件4 天前
GM DC Monitor一体化监控预警平台部署手册2025-12-10
运维·自动化·ansible·zabbix·运维开发·prometheus
Live in Shanxi.4 天前
Prometheus监控服务器及K8s集群资源
服务器·kubernetes·prometheus