服务追踪 Spring Cloud Sleuth
调用接口耗时非常严重,通过链路追踪得到链路花费的时间
导入依赖
<!--包含sleuth 和 zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
查看链路
第一个值:服务名
第二个:tranceId
第三个:spanId,一个基本单元,一个链路请求可以包括多个span_id,比如 发送一个http请求
最后一个值:表示是否收集
Zipkin
gitHub:https://github.com/openzipkin...
docker 安装 开启 9411端口docker run -d -p 9411:9411 openzipkin/zipkin
配置服务器地址:
spring:
application:
name: order
cloud:
config:
discovery:
enabled: true
service-id: config
profile: dev
# stream:
# bindings:
# myMessage: order
zipkin:
base-url: localhost:9411/
# 抽样百分比 1-》百分百
sleuth:
sampler:
percentage: 1
查看链路
分布式追踪系统:
- 数据采集
- 数据存储
- 查询展示
OpenTracing
优势:
- 来自CNCF
- ZIPKIN,TRACER,JREGER,GRPC等
Annotation:
事件类型:
- cs(Client Send):客户端发起请求的时间
- cr(Client Received):客户端收到处理完请求的时间
- ss(Server Send):服务端处理完逻辑的时间
- sr(Server Rceived):服务端收到调用段请求的时间
请求时间:
客户端调用时间=cr-cs
服务端处理时间=sr-ss
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。