Prometheus基于Eureka的服务发现
Prometheus基于Eureka的服务发现
一、背景
目前我们的项目是使用Spring Cloud构建的微服务,使用的是Eureka作为注册中心,且项目中使用到Prometheus做服务监控。此处简单记录一下 eureka 作为 prometheus 的服务发现。
二、实现步骤
1、eureka 客户端注册到prometheus中
修改 application.yml 文件
spring:
application:
name: order-provider-10004
server:
port: 10004
management:
endpoints:
web:
exposure:
include: 'prometheus,metrics,info,health' # 暴露出 prometheus 端口
metrics:
tags:
application: ${spring.application.name} # 增加每个指标的全局的tag,及给每个指标一个 application的 tag,值是 spring.application.name的值
server:
port: 10005
# 注册到 eureka 上
eureka:
client:
service-url:
defaultZone: http://localhost:10003/eureka/ #连接到服务注册中心的地址,如果服务注册中心开启了权限需要设置 http://username:password@ip:port/eureka/格式
instance:
prefer-ip-address: true
metadata-map:
# 集成到prometheus,以下的这些数据都会加入到prometheus的重新标记之前的标签中,比如sys.module会变成
"prometheus.scrape": "true"
"prometheus.path": "/actuator/prometheus"
"prometheus.port": "${management.server.port}"
"sys.module": "order"
主要是上方 metadata-map 中的配置。
2、prometheus中的写法
修改 prometheus.yml 文件
- job_name: 'eureka'
eureka_sd_configs:
# 指定 eureka 的服务发现地址
- server: 'http://localhost:10003/eureka'
relabel_configs:
# 重写 metrics 的路径
- source_labels: ["__meta_eureka_app_instance_metadata_prometheus_path"]
action: replace
target_label: __metrics_path__
regex: (.+)
# 增加一个自定义label sys_model 它的值从配置eureka中获取
- source_labels: ["__meta_eureka_app_instance_metadata_sys_module"]
action: replace
target_label: sys_module
regex: (.+)
# 重写管理端口
- source_labels: [__address__, __meta_eureka_app_instance_metadata_prometheus_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
1、重写 metrics 的 path。
2、重写 管理端口。
3、增加一个自定义的标签。
实现效果查看下方的效果图。
最终实现的抓取端口的路径 http://10.1.129.254:10005/actuator/prometheus
注意:
1、/actuator/prometheus 由上方的 metrics_path 重写。
2、10.1.129.254:10005 由上方的 address 重写。
3、实现效果

上图展示的短裤是 10004 而不是 10005,是因为我没有在 application.yml 中指定 management.server.port 时截的图。
三、完整代码
https://gitee.com/huan1993/spring-cloud-parent/tree/master/prometheus/eureka-prometheus-parent
四、参考链接
1、https://github.com/prometheus/prometheus/blob/release-2.25/documentation/examples/prometheus-eureka.yml
2、https://prometheus.io/docs/prometheus/latest/configuration/configuration/#eureka_sd_config
Prometheus基于Eureka的服务发现的更多相关文章
- Prometheus 基于文件的服务发现
Prometheus 基于文件的服务发现 官方文档:https://github.com/prometheus/prometheus/tree/master/discovery 服务发现支持: end ...
- Prometheus基于文件的服务发现
Prometheus基于文件的服务发现 一.基于文件的服务发现 1.prometheus.yml 配置文件的写法 2.file_sd 目录下的文件 3.配置结果 二.注意事项 三.参考链接 一.基于文 ...
- prometheus — 基于文件的服务发现
基于文件的服务发现方式不需要依赖其他平台与第三方服务,用户只需将要新的target信息以yaml或json文件格式添加到target文件中 ,prometheus会定期从指定文件中读取target信息 ...
- prometheus 基于DNS的目标发现
prometheus 基于DNS的目标发现 DNS服务发现依赖于查询A.AAAA或SRV DNS记录. 1.基于 SRV 记录发现 scrape_configs: - job_name: 'webap ...
- 基于Eureka的服务治理
代码地址如下:http://www.demodashi.com/demo/11927.html 一.服务的注册与发现 关系调用说明: 服务生产者启动时,向服务注册中心注册自己提供的服务 服务消费者启动 ...
- Prometheus Consul实现自动服务发现
Prometheus Consul实现自动服务发现 1.概述 Consul 是一个支持多数据中心分布式高可用的服务发现和配置共享的服务软件. Consul 由 HashiCorp公司用Go语言开发 ...
- java版gRPC实战之七:基于eureka的注册发现
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- prometheus 基于文件的目标发现
prometheus 基于文件的目标发现 1.创建目录 cd /usr/local/prometheus/conf mkdir -pv targets/{nodes,docker} 2.修改prome ...
- 【Eureka】服务发现调用
[Eureka]服务发现调用 转载:https://www.cnblogs.com/yangchongxing/p/10779832.html 1.使用 Netfix Feign 客户端调用服务 首先 ...
随机推荐
- epoll经典代码示例
1. epoll原理 原理性的知识不再另做说明,我在这里附上收藏整理的两篇经典文章: select与epoll的本质关系. select.poll.epoll之间的区别. 2. epoll服务器端经典 ...
- linux主机安全加固-个人经验
说明:我并没有一个系统的网络安全知识体系,随笔里面提到的内容是个人在从事运维行业这几年中总结出来的一点经验,仅供大家参考. 说到linux主机安全加固,我可以想到的就是三个方向吧,基线整改.访问控制和 ...
- IO流实现简单的文件的剪切
思路: 判断 即将 复制的文件是文件夹还是文件 遍历需要复制的源文件夹 如果是文件夹,就通过流创建一个同样的子文件夹 如果是文件,就复制过去 接下来上代码 public class Demo1 { p ...
- 创建一个People类型,有年龄、工资、性别三个属性。 定义一个方法叫做找对象,找对象方法传过来一个人;
创建一个People类型,有年龄.工资.性别三个属性. 定义一个方法叫做找对象,找对象方法传过来一个人: 首先如果性别相同,就输出"我不是同性恋", 如果对方是男的,年龄小于28, ...
- 计算字符串的长度.len,RuneCountInString
内置函数len(),可以返回字符串/数组/切片/map/channel的长度. unicode/utf8包 函数:RuneCountInString(输入一个字符串),返回int类型的字符串长度.由于 ...
- docker run配置参数
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] -d, --detach=false 指定容器运行于前台还是后台,默认为false -i, - ...
- 性能再提升70%?大咖前瞻带你揭开.NET6的神秘面纱!
本月初微软官宣.NET 6 的RC1即将在11月正式发布,这意味着.NET6正式版跟我们见面的时间又近了一步.在之前的.NET6预览版本中,微软加入了大量新功能特性,而在最终版本中将不再额外加入新的内 ...
- 织梦arclist文章标题字数太短
解决dedecms UTF-8首页文章标题显示字数太短的办法原因分析:因为UTF-8编码1个中文汉字占用的是3个字节,GBK占用的是2个字节,所以,原先$titlelen = AttDef($titl ...
- gin 源码阅读(1) - gin 与 net/http 的关系
gin 是目前 Go 里面使用最广泛的框架之一了,弄清楚 gin 框架的原理,有助于我们更好的使用 gin. 这个系列 gin 源码阅读会逐步讲明白 gin 的原理. gin 概览 想弄清楚 gin, ...
- (一)es 概述与安装
一.基本概念介绍 1. es 核心术语 核心概念 ES -> 数据库 索引index -> 表 文档 document -> 行(记录) 字段 fields -> 列 早期版本 ...