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

总结

欢迎指出我的错误!

相关推荐
.柒宇.6 小时前
运维常见面试题_07_配置管理与监控(Ansible · Prometheus · Alertmanager)· 容器编排(Kubernetes)
运维·k8s·ansible·prometheus
玉&心2 天前
在grafana中引入prometheus的数据监控
grafana·prometheus
Dovis(誓平步青云)2 天前
从Redis指标采集到异常告警:redis_exporter + Prometheus 完整实战
服务器·数据库·人工智能·redis·架构·prometheus·vibe coding
吉甫作诵4 天前
Prometheus 安装配置:Consul 自动发现与 Thanos Sidecar 持久化
prometheus·consul
溜达的大象4 天前
Prometheus怎么监控没有公网IP的服务器?Node Exporter远程采集实战
服务器·tcp/ip·prometheus
测试狗科研平台6 天前
从实验室到量产:测试狗新材料中试的技术路径与平台支撑
测试工具·服务发现·材料工程
八角Z6 天前
AI Agent作为经济参与者的兴起:机器经济与传统金融体系的并存与交织
大数据·人工智能·服务发现
Livia要学习9 天前
Prometheus架构解析
prometheus
云烟成雨TD10 天前
Micrometer 系列【63】统一观测:基于 Spring Boot 的生产级演示案例 | 基于 OTLP 集成 Prometheus + Jaeger
spring boot·云原生·prometheus
Anita-lee11 天前
泛娱乐出海 APP 运营研究:用户量下滑成因与多语种客服数据化运营解决方案
大数据·产品运营·服务发现·娱乐