日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

spring cloud学习进阶篇:Spring Cloud Sleuth + Zipkin 实现分布式跟踪解决方案

發布時間:2024/1/17 javascript 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring cloud学习进阶篇:Spring Cloud Sleuth + Zipkin 实现分布式跟踪解决方案 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

簡述

  • 使用 spring cloud 用到最多的是各種rest服務調用,Twitter的Zipkin 是一種實現分布式跟蹤解決方案,Sleuth則是用來共方便的集成Zipkin。

調用跟蹤系統的業務場景

  • 隨著服務的拆分,系統的模塊變得越來越多,不同的模塊可能由不同的團隊維護,一個請求可能會涉及到幾十個服務的協同處理, 牽扯到多個團隊的業務系統,那么如何快速準確的定位到線上故障?比較成熟的解決方案是通過調用鏈的方式,把一次請求調用過程完整的串聯起來,這樣就實現了對請求調用路徑的監控。
  • 故障快速定位
    • 通過調用鏈跟蹤,一次請求的邏輯軌跡可以用完整清晰的展示出來。 開發中可以在業務日志中添加調用鏈ID,可以通過調用鏈結合業務日志快速定位錯誤信息。
  • 各個調用環節的性能分析
    • 在調用鏈的各個環節分別添加調用時延,可以分析系統的性能瓶頸,進行針對性的優化。
  • 各個調用環節的可用性,持久層依賴等
    • 通過分析各個環節的平均時延,QPS等信息,可以找到系統的薄弱環節,對一些模塊做調整,如數據冗余等。
  • 數據分析等
    • 調用鏈是一條完整的業務日志,可以得到用戶的行為路徑,匯總分析應用在很多業務場景。

    Spring Cloud Sleuth

    • Spring Cloud Sleuth為Spring Cloud實現分布式跟蹤解決方案。

    Zipkin

    • 為分布式鏈路調用監控系統,聚合各業務系統調用延遲數據,達到鏈路調用監控跟蹤。

    使用

    • Zipkin可以通過http收集信息,也可以通過mq收集信息
  • Zipkin server代碼
    • pom.xml
    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.xx.xxx.server</groupId><artifactId>zipkin-server</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>zipkin-server</name><description>zipkin追蹤服務</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><zipkin.version>2.3.1</zipkin.version><spring-cloud.version>Edgware.SR2</spring-cloud.version></properties><dependencies><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-server</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-sleuth-zipkin-stream</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-sleuth</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-stream-rabbit</artifactId></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-autoconfigure-ui</artifactId><scope>runtime</scope></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-autoconfigure-storage-mysql</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-sleuth-core</artifactId></dependency><!--spring boot--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>1.5.4.RELEASE</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
    • application.yml
    server:port: 9411 spring:application:name: zipkin-serversleuth:enabled: false #rabbitmq設置,如果使用http收集信息可以不用設置rabbitmq:host: 172.16.10.71port: 5672username: adminpassword: adminlistener:simple:concurrency: 1max-concurrency: 10acknowledge-mode: auto #數據庫設置,如果不使用數據庫可以不需要設置,需要創建zipkin數據庫datasource:name: zipkindriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/zipkin?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=falseusername: rootpassword: 123456# 會自動生成數據庫表結構schema: classpath:/mysql.sqlinitialize: truecontinue-on-error: true zipkin:storage:type: mysql
    • java
    @SpringBootApplication @EnableZipkinStreamServer public class ZipkinServerApplication{public static void main(String[] args) {new SpringApplicationBuilder(ZipkinServerApplication.class).run(args);System.out.println("Server start succ");} }
  • client 代碼
    • pom.xml添加sleuth&zipkin依賴
    <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-sleuth-core</artifactId> </dependency> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-sleuth</artifactId> </dependency> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-sleuth-zipkin-stream</artifactId> </dependency> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-stream-rabbit</artifactId> </dependency>
    • application.yml
    #spring spring:zipkin:enabled: true# zipkin server地址,如果使用mq收集,這個就不要配置base-url: http://localhost:9411# 應采樣的請求百分比。例如1.0= 100%的請求應該被抽樣。精度僅為全數(即不支持0.1%的痕跡)。開發過程使用1.0,生產根據實際情況設置sleuth:sampler:percentage: 1.0rabbitmq:host: 172.16.10.71port: 5672username: adminpassword: adminlistener:simple:concurrency: 1max-concurrency: 10acknowledge-mode: auto

    先啟動server,然后啟動應用服務,然后在應用服務上調用其他服務

    打開server中zipkin監控面板:http://localhost:9411

    轉載于:https://my.oschina.net/aulbrother/blog/1641863

    創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

    總結

    以上是生活随笔為你收集整理的spring cloud学习进阶篇:Spring Cloud Sleuth + Zipkin 实现分布式跟踪解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。