Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin
2024-10-19 19:42:07
前言:随着微服务系统的增加,服务之间的调用关系变得会非常复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得非常重要了。spring cloud sleuth实现了对分布式服务的监控解决方案。
前情回顾请参考:
Spring Cloud 微服务二:API网关spring cloud zuul
Spring Cloud 微服务三: API网关Spring cloud gateway
Spring Cloud 微服务四:熔断器Spring cloud hystrix
Spring Cloud 微服务五:Spring cloud gateway限流
- 概览
- sleuth集成zipkin
- 搭建zipkin服务,可以通过docker或者jar包的方式启动,具体可参考:https://github.com/openzipkin.本章主要使用spring的方式启动。首先新建一个module sleuth-server,在pom中引入以下依赖,版本我使用的与springboot 2.0.8.RELEASE相对应的2.11.7版本,该版本已经在父工程中定义。
<artifactId>sleuth-server</artifactId> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
</dependency>
</dependencies> - 在启动类添加@EnableZipkinServer注解,表示该工程是一个服务器
@SpringBootApplication
@EnableZipkinServer
public class SleuthServerApplication {
public static void main(String[] args) {
SpringApplication.run(SleuthServerApplication.class, args);
}
} - 配置application.yml,加入zipkin配置
server:
port: 9411 debug: true
spring:
application:
name: sleuth-server
management:
metrics:
web:
server:
auto-time-requests: false - 启动sleuth-server,访问http://localhost:9411进入主界面
- 接下来配置user-consumer,在该工程的pom文件中添加zipkin依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency> - application.yml中添加sleuth以及zipkin配置
zipkin:
base-url: http://localhost:9411/
sleuth:
sampler:
probability: 1.0 - 同样配置user-service
- 启动user-service,user-consumer,访问服务,会在zipin页面上查询到。
- 搭建zipkin服务,可以通过docker或者jar包的方式启动,具体可参考:https://github.com/openzipkin.本章主要使用spring的方式启动。首先新建一个module sleuth-server,在pom中引入以下依赖,版本我使用的与springboot 2.0.8.RELEASE相对应的2.11.7版本,该版本已经在父工程中定义。
Spring cloud sleuth实现了分布式系统的链路监控,用户可以通过可视化、交互式页面查看服务调用情况,并能够自动更关心服务调用状态
最新文章
- 如何编写高效的jQuery代码
- Xml命名空间浅析
- 我是一只it小小鸟阅读笔记
- 【NOIP TG 解方程】
- 关于canvas 易忘属性
- swift论坛正式上线
- JS中的call()和apply()方法理解和使用
- java 内省
- kafka安装使用和遇到的坑
- .net core系列之《.net core内置IOC容器ServiceCollection》
- 再谈 tp的 实例化 类 的自动加载
- pyqt 不规则形状窗口显示
- [剑指Offer]50-第一个只出现一次的字符
- python3.3中print换行
- 如何使QLineEdit禁止编辑
- android 数据存储&;lt;一&;gt;----android短信发送器之文件的读写(手机+SD卡)
- MyEclipse持续性开发教程:用JPA和Spring管理数据(二)
- UVAlive5135_Mining Your Own Business
- Python列表练习题
- Yura