解決如何定位哪一段微服務間的過程耗時問題
zipkin爲分佈式鏈路調用監控系統,聚合各業務系統調用延遲數據,達到鏈路調用監控跟蹤。zipkin類似於日誌的高級版,跟蹤監控。訪問地址:localhost:9411/zipkin/
如何使用 ZipKin
1.添加starter-zipkin依賴(包含了sleuth-zipkin、starter-sleuth依賴)
2.配置zipkin的base-url
3.抽樣的百分比觀察,比如默認只把百分之10的發到zipkin,配置sleuth-sampler-percentage爲1,1就是所有的都發過去
- docker 方式運行 zipkin
<!--包含sleuth和zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
spring:
application:
name: order
cloud:
config:
discovery:
enabled: true
service-id: CONFIG
profile: test
stream:
bindings:
myMessage:
group: order
content-type: application/json
zipkin:
base-url: http://localhost:9411/
sleuth:
sampler:
percentage: 1
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 3000
getProductInfoList:
execution:
isolation:
thread:
timeoutInMilliseconds: 3000
feign:
hystrix:
enabled: true
logging:
level:
org.springframework.cloud.netflix.feign: debug
- org.springframework.cloud.netflix.feign: debug:只對這個包進行 debug 日誌輸出。
- percentage:設置抽樣比例,1就是100% ,0.1就是10%,默認 0.1
- 鏈路追蹤的記錄,第一個當前服務名,第二個鏈路ID整條就一個,第三個是各個階段的ID各自不同。第四個值是否輸出到外部(默認:false,如果配置了百分比則爲 true),比如zipkin去觀察。
- 效果圖