SpringCloud - ZipKin 快速入門(Sleuth & ZipKin)

解決如何定位哪一段微服務間的過程耗時問題

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就是所有的都發過去

5c2f075e0001a06f19201080.jpg (1920×1080)

5abdbc3a0001d60719201080.jpg (1920×1080)

  • 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
    5e930a9b0001acc419201080.jpg (1920×1080)

5e23aa2a0001dd2319201080.jpg (1920×1080)

  • 鏈路追蹤的記錄,第一個當前服務名,第二個鏈路ID整條就一個,第三個是各個階段的ID各自不同。第四個值是否輸出到外部(默認:false,如果配置了百分比則爲 true),比如zipkin去觀察。

5ba351b00001204d19201080.jpg (1920×1080)

5e930ac90001238319201080.jpg (1920×1080)

  • 效果圖
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章