SpringCloud Sleuth/Zipkin学习

您所在的位置:网站首页 微服务全链路追踪 SpringCloud Sleuth/Zipkin学习

SpringCloud Sleuth/Zipkin学习

2023-06-16 20:34| 来源: 网络整理| 查看: 265

SpringCloud Sleuth/Zipkin

文章目录 SpringCloud Sleuth/Zipkin1 Sleuth/Zipkin 简介2 Sleuth/ZipKin-搭建链路监控实例

1 Sleuth/Zipkin 简介 在微服务框架中,一个由客户端发起的请求在后端系统中会经过多个不同的的服务节点调用, 来协同产生最后的请求结果,每一个请求都会形成一条复杂的分布式服务调用链路。链路中的任何一环出现高延时或错误都会引起整个请求最后的失败, 因此对整个服务的调用进行链路追踪和分析就非常的重要Sleuth 和 Zipkin 的简单关系图

image-20230602215705449

2 Sleuth/ZipKin-搭建链路监控实例

第一步、首先需要运行zipkin的jar包

进入jar包所在目录,输入cmd 进入命令窗口

image-20230604171258266

浏览器输入:http://localhost:9411

image-20230604171424152

第二步、添加 sleuth+zipkin 依赖

org.springframework.cloud spring-cloud-starter-zipkin

第三步、修改application.yml 文件,指定zipkin

server: port: 10000 spring: application: name: member-service-provider #名称,可以自己指定 zipkin: base-url: http://localhost:9411 sleuth: # sleuth+zikpin sampler: # 采样率在 0-1之间, 1 表示全部采集 probability: 1 datasource: type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://localhost:3308/e_commerce_center_db?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: 123456 # 配置 MyBatis mybatis: mapper-locations: classpath:mapper/*.xml # 指定mapper.xml文件位置 type-aliases-package: com.xjz.springcloud.entity # 实体类的包路径 # eureka 客户端配置 eureka: client: register-with-eureka: true #将自己注册到 eureka-Server # 是否从 eureka-Server 抓取注册信息,默认为true,单节点无所谓 # 集群必须设置为 true # 才能配合 ribbon使用负载均衡 fetch-registry: true service-url: #defaultZone: http://localhost:9001/eureka # 将本微服务注册到多个 eureka-server,使用逗号隔开 defaultZone: http://eureka9001.com:9001/eureka,http://eureka9002.com:9002/eureka # instance: # # 客户端向服务端发送心跳的时间间隔 1s(默认是30) # lease-renewal-interval-in-seconds: 1 # # 服务端收到最后一次心跳后等待的时间上限 # # 时间单位(秒),默认是90s,超时将剔除服务 # lease-expiration-duration-in-seconds: 2

第四步、测试

1.浏览器输入: http://localhost/member/consumer/get/1 , 多访问几次,方便看监控结果,这里因为端口号默认为80 ,所以不需要输入端口号

image-20230604172234344

查看监控&分析结果

image-20230604172311016

点击查找后,进入如下界面

image-20230604172358170

点击后可查看服务调用链路

image-20230604172441843

查看服务调用的依赖关系

image-20230604172514741



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3