Sleuth則是用來共方便的集成Zipkin。

簡述

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

調用跟蹤系統的業務場景

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

Spring Cloud Sleuth

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

Zipkin

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

使用

  • Zipkin可以通過http收集信息,也可以通過mq收集信息
  1. 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");}
}
  1. 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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/387072.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/387072.shtml
英文地址,請注明出處:http://en.pswp.cn/news/387072.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Spring Cloud 中 分布式事務解決方案 -- 阿里GTS的使用

1&#xff1a;依賴引入<!--gts相關--><!--數據庫連接--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>mysql&…

《HTTP 權威指南》筆記:第十五章 實體與編碼

&#xfffc; 如果把 「HTTP 報文」想象為因特網貨運系統的「箱子」,那么「HTTP 實體」就是報文中的實際的「貨物」. 其中,實體又包含了「實體首部」 和 「實體主體」,實體首部用于描述各種參數,實體主體就是原始貨物. 常見的實體首部 實體的大小: Content-Length 定義: 報文的…

Spring Cloud Sleuth進階實戰

為什么需要Spring Cloud Sleuth 微服務架構是一個分布式架構&#xff0c;它按業務劃分服務單元&#xff0c;一個分布式系統往往有很多個服務單元。由于服務單元數量眾多&#xff0c;業務的復雜性&#xff0c;如果出現了錯誤和異常&#xff0c;很難去定位。主要體現在&#xff…

Element表格嵌入復選框以及單選框

1&#xff0c;element 表格嵌入CheckBox 效果圖如下&#xff1a; 2&#xff0c;element結合checkBox實現單選效果如下&#xff1a; html代碼&#xff1a; <template><div><p>shopInfo</p><el-tableref"multipleTable":data"tableDat…

溫故之 “插入排序”

概念&#xff1a;將一個數據插入已經排好序的有序數組中&#xff0c;從而得到一個新的多一個數據的有序數組。 概念理解~~ 將要排序的是一個亂的數組int[] arrays {3, 2, 1, 3, 3}; 在未知道數組元素的情況下&#xff0c;我們只能把數組的第一個元素作為已經排好序的有序數據&…

實驗二3

#include "stdafx.h" #include "stdio.h" int main(int argc, char* argv[]) {int a,b,c; scanf("%d %d %d",&a,&b,&c);if(ab&&bc) printf("等邊三角形");else if((ab&&b!c)||(ac&&c!b)||(bc&a…

webpack來打包你的vue項目,如發現你的vendor.js過大

1.如果你使用了webpack來打包你的vue項目&#xff0c;如發現你的vendor.js過大則可以參考本文的解決方案. 2.造成過大的原因是因為在main.js導入第三庫太多時,webpack合并js時生成了vendor.js(我們習慣把第三方庫放在vendor里面)造成的.如下圖在main.js引用element-ui等第三方…

TF01 簡介

總覽 如何從實體中提取特征&#xff0c;對于很多傳統機器學習算法的性能有巨大影響。 一旦解決了數據表達和特征提取&#xff0c;很多人工智能任務也就解決了90%。 對許多機器學習算法來說&#xff0c;特征提取不是一件簡單的事情。 深度學習解決的核心問題之一就是自動的將簡…

K8s基本概念入門

序言 沒等到風來&#xff0c;綿綿小雨&#xff0c;所以寫個隨筆&#xff0c;聊聊k8s的基本概念。 k8s是一個編排容器的工具&#xff0c;其實也是管理應用的全生命周期的一個工具&#xff0c;從創建應用&#xff0c;應用的部署&#xff0c;應用提供服務&#xff0c;擴容縮容應用…

idea出現找不到實體類

今天經理遇到一個很奇怪的問題&#xff1a; 在使用idea時&#xff0c;就是包真實存在&#xff0c;但是包中的實體類卻無法智能提示&#xff0c;也無法導入成功&#xff1b; 我推薦的解決辦法是重新導入&#xff0c;但是沒有用&#xff0c;經理在網上找了很多解決方式&#xff0…

TF02 入門

計算模型——圖 數據模型——張量 運行模型——會話 TensorFlow計算模型——計算圖 計算圖是TF中最基本的一個概念&#xff0c;TF中的所有計算都會被轉化為計算圖上的結點。 TF是一個通過計算圖的形式來表述計算的編程系統。TF中的每一個計算都是計算圖上的一個節點&#x…

ElasticSearch、Logstash和Kiabana三個開源工具。

一 方案背景 通常&#xff0c;日志被分散的儲存不同的設備上。如果你管理數十上百臺服務器&#xff0c;你還在使用依次登錄每臺機器的傳統方法查閱日志。這樣是不是感覺很繁瑣和效率低下。開源實時日志分析ELK平臺能夠完美的解決日志收集和日志檢索、分析的問題&#xff0c;ELK…

「一本通 6.4 例 4」曹沖養豬(CRT)

復習一下 擴展中國剩余定理 首先考慮兩個同余方程\[ x \equiv a_1\; mod\; m_1\\ x \equiv a_2\; mod\; m_2 \]化成另一個形式\[ x n_1 * m_1 a_1\\ x n_2 * m_2 a_2 \] 聯立可得\[ n_1 * m_1 a_1 n_2 * m_2 a_2\\ n_1 * m_1 - n_2 * m_2 a_2 - a_1 \]有解的前提是\[ \…

06 MapReduce工作機制

MapReduce作業的執行流程 1、提交作業 在提交JobConf對象之後&#xff0c;用戶程序調用JobClient的runJob方法。 runJob方法會先行調用JobSubmissionProtocol接口所定義的submitJob方法&#xff0c;並將作業提交給JobTracker。 緊接著&#xff0c;runJob不斷循環&#xff0…

solr elasticsearch比較

solr&#xff1a; 優點 1、Solr有一個更大、更成熟的用戶、開發和貢獻者社區。 2、支持添加多種格式的索引&#xff0c;如&#xff1a;HTML、PDF、微軟 Office 系列軟件格式以及 JSON、XML、CSV 等純文本格式。 3、Solr比較成熟、穩定。 4、不考慮建索引的同時進行搜索&#xf…

力扣(LeetCode)292. Nim游戲 巴什博奕

你和你的朋友&#xff0c;兩個人一起玩 Nim游戲&#xff1a;桌子上有一堆石頭&#xff0c;每次你們輪流拿掉 1 - 3 塊石頭。 拿掉最后一塊石頭的人就是獲勝者。你作為先手。 你們是聰明人&#xff0c;每一步都是最優解。 編寫一個函數&#xff0c;來判斷你是否可以在給定石頭數…

Spring Cloud應用監控與管理Actuator

由于我們把一個復雜高耦合的單體系統拆分成了多個小型服務&#xff0c;所以部署應用的數量在不斷增長&#xff0c;造成維護復雜度大大提升。所以我們需要一套自動化的監控運維機制&#xff0c;這套運維機制可以不間斷的獲取每個服務應用的各種指標&#xff0c;并根據這些指標信…