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

总结

欢迎指出我的错误!

相关推荐
lbb 小魔仙1 天前
OpenClaw + cpolar 实战:远程 NAS、分享小游戏、RDP,再配置公网 AI 入口
数据库·人工智能·redis·oracle·prometheus
QYRdata1 天前
年均增速24.2%!机器人数据湖未来六年增长动能强劲
网络·机器人·服务发现
netyeaxi2 天前
Consul:Consul中index介绍
consul
QYRdata2 天前
ICMP云管理平台2026-2032年CAGR达13.5% 未来发展潜力凸显
云计算·服务发现
zhoupenghui1682 天前
Golang pprof 工具详解:监控、压测与调优实战指南
prometheus·pprof
八角Z2 天前
iOS App 审核变慢:从提交量增长到风险分层审核
服务发现
QYRdata3 天前
2026-2032年云DevOps工具年复合增长率16.5%,开启高效运维新篇章
服务发现
ggaofeng4 天前
prometheus时序数据库
prometheus
QYRdata6 天前
隐私合规技术迎来拐点:数据主体请求自动化年复合增长率14.0%(2026-2032)
大数据·服务发现
A心有千千结7 天前
Nginx网关可观测建设:打通流量入口,加速线上故障诊断
nginx·prometheus·devops