SpringCloud教程十一:Sleuth+Mysql服務鏈路追蹤
springcloud中的服務鏈路追蹤,之前我們已經講過一次了,在實際應用中,我們經常需要將鏈路服務的記錄儲存下來,以實現服務的監測和分析,那麼這就需要用到資料庫了。下面我們來實現一下。資料庫表結構:
CREATE TABLE `zipkin_annotations` ( `trace_id_high` bigint(20) NOT NULL DEFAULT '0' COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit', `trace_id` bigint(20) NOT NULL COMMENT 'coincides with zipkin_spans.trace_id', `span_id` bigint(20) NOT NULL COMMENT 'coincides with zipkin_spans.id', `a_key` varchar(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1', `a_value` blob COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB', `a_type` int(11) NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation', `a_timestamp` bigint(20) DEFAULT NULL COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp', `endpoint_ipv4` int(11) DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null', `endpoint_ipv6` binary(16) DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address', `endpoint_port` smallint(6) DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null', `endpoint_service_name` varchar(255) DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null', UNIQUE KEY `trace_id_high` (`trace_id_high`,`trace_id`,`span_id`,`a_key`,`a_timestamp`) COMMENT 'Ignore insert on duplicate', KEY `trace_id_high_2` (`trace_id_high`,`trace_id`,`span_id`) COMMENT 'for joining with zipkin_spans', KEY `trace_id_high_3` (`trace_id_high`,`trace_id`) COMMENT 'for getTraces/ByIds', KEY `endpoint_service_name` (`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames', KEY `a_type` (`a_type`) COMMENT 'for getTraces', KEY `a_key` (`a_key`) COMMENT 'for getTraces' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED CREATE TABLE `zipkin_dependencies` ( `day` date NOT NULL, `parent` varchar(255) NOT NULL, `child` varchar(255) NOT NULL, `call_count` bigint(20) DEFAULT NULL, `error_count` bigint(20) DEFAULT NULL, UNIQUE KEY `day` (`day`,`parent`,`child`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED CREATE TABLE `zipkin_spans` ( `trace_id_high` bigint(20) NOT NULL DEFAULT '0' COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit', `trace_id` bigint(20) NOT NULL, `id` bigint(20) NOT NULL, `name` varchar(255) NOT NULL, `parent_id` bigint(20) DEFAULT NULL, `debug` bit(1) DEFAULT NULL, `start_ts` bigint(20) DEFAULT NULL COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL', `duration` bigint(20) DEFAULT NULL COMMENT 'Span.duration(): micros used for minDuration and maxDuration query', UNIQUE KEY `trace_id_high` (`trace_id_high`,`trace_id`,`id`) COMMENT 'ignore insert on duplicate', KEY `trace_id_high_2` (`trace_id_high`,`trace_id`,`id`) COMMENT 'for joining with zipkin_annotations', KEY `trace_id_high_3` (`trace_id_high`,`trace_id`) COMMENT 'for getTracesByIds', KEY `name` (`name`) COMMENT 'for getTraces and getSpanNames', KEY `start_ts` (`start_ts`) COMMENT 'for getTraces ordering and range' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED
配置檔案:
server.port=7085 spring.application.name=zipkin-server eureka.instance.hostname=127.0.0.1 #rabbitmq配置 spring.rabbitmq.host=172.16.1.29 spring.rabbitmq.port=5672 spring.rabbitmq.username=admin spring.rabbitmq.password=a123456 #zipkin資料儲存到資料庫中需要進行如下配置 #表示當前程式不使用sleuth spring.sleuth.enabled=false #表示zipkin資料儲存方式是mysqlzipkin.storage.type=mysql #資料庫指令碼建立地址,當有多個是可使用[x]表示集合第幾個元素 #spring.datasource.schema[0]=classpath:/zipkin.sql #spring boot資料來源配置 # 資料庫訪問配置 # 主資料來源,預設的 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://172.16.1.28:3306/springcloudspring.datasource.username=cweserver spring.datasource.password=cweserveryzhh # 下面為連線池的補充設定,應用到上面所有資料來源中 # 初始化大小,最小,最大 spring.datasource.initialSize=5 spring.datasource.minIdle=5 spring.datasource.maxActive=20 # 配置獲取連線等待超時的時間 spring.datasource.maxWait=60000 # 配置間隔多久才進行一次檢測,檢測需要關閉的空閒連線,單位是毫秒 spring.datasource.timeBetweenEvictionRunsMillis=60000 # 配置一個連線在池中最小生存的時間,單位是毫秒 spring.datasource.minEvictableIdleTimeMillis=300000 spring.datasource.validationQuery=SELECT 1 FROMDUAL spring.datasource.testWhileIdle=true spring.datasource.testOnBorrow=false spring.datasource.testOnReturn=false # 開啟PSCache,並且指定每個連線上PSCache的大小 spring.datasource.poolPreparedStatements=true spring.datasource.maxPoolPreparedStatementPerConnectionSize=20 # 配置監控統計攔截的filters,去掉後監控介面sql無法統計,'wall'用於防火牆 spring.datasource.filters=stat,wall,log4j # 通過connectProperties屬性來開啟mergeSql功能;慢SQL記錄 spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
pom檔案:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Edgware.SR1</spring-cloud.version> </properties> <dependencies> <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> <!--zipkin--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId> <version>1.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> <version>1.3.1.RELEASE</version> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-autoconfigure-ui</artifactId> </dependency> <!--資料庫--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.29</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <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>
啟動類:
@EnableZipkinStreamServer @EnableEurekaClient @SpringBootApplicationpublic class ZipkinserverApplication { public static void main(String[] args) { SpringApplication.run(ZipkinserverApplication.class, args); }}
相關推薦
SpringCloud教程十一:Sleuth+Mysql服務鏈路追蹤
springcloud中的服務鏈路追蹤,之前我們已經講過一次了,在實際應用中,我們經常需要將鏈路服務的記錄儲存下來,以實現服務的監測和分析,那麼這就需要用到資料庫了。下面我們來實現一下。資料庫表結構:CREATE TABLE `zipkin_annotations` (
spring cloud微服務快速教程之(十一) Sleuth(zipkin) 服務鏈路追蹤
0、前言 微服務架構上眾多微服務通過REST呼叫,可能需要很多個服務協同才能完成一個介面功能,如果鏈路上任何一個服務出現問題或者網路超時,都會形成導致介面呼叫失敗。隨著業務的不斷擴張,服務之間互相呼叫會越來越複雜。如何清晰地記錄服務的呼叫鏈路,方便將來問題的定位,Spring cloud sleuth元
SpringCloud系列十一:SpringCloudStream(SpringCloudStream 簡介、創建消息生產者、創建消息消費者、自定義消息通道、分組與持久化、設置 RoutingKey)
javax sun 就是 eas nts discovery junit4 IE 程序包 1、概念:SpringCloudStream 2、具體內容 2.1、SpringCloudStream 簡介 SpringCloudStream 就是使用了基於消息系統的微服務處理架構
業余草 SpringCloud教程 | 第九篇: 服務鏈路追蹤(Spring Cloud Sleuth)(Finchley版本)
描述 -s util ont packaging tdd res [] 新建 這篇文章主要講述服務追蹤組件zipkin,Spring Cloud Sleuth集成了zipkin組件。 一、簡介 Add sleuth to the classpath of a Spr
史上最簡單的SpringCloud教程 | 第九篇: 服務鏈路追蹤(Spring Cloud Sleuth)(Finchley版本)
這篇文章主要講述服務追蹤元件zipkin,Spring Cloud Sleuth集成了zipkin元件。 一、簡介 Add sleuth to the classpath of a Spring Boot application (see below for Maven
SpringCloud學習筆記(一):搭建Eureka服務和叢集
環境版本:Springboot:2.1.0 Springcloud:Finchley.SR2 (一)搭建eureka服務註冊中心 1、建立springboot專案 建立springboot專案直接在官網https://s
Spring Boot系列教程十一: Mybatis使用分頁外掛PageHelper
一.前言 上篇部落格中介紹了spring boot整合mybatis的方法,基於上篇文章這裡主要介紹如何使用分頁外掛PageHelper。在MyBatis中提供了攔截器介面,我們可以使用PageHelp最為一個外掛裝入到SqlSessionFactory,實現攔截器功能。
【QT】QT從零入門教程(十一):QT自定義視窗
首先是借鑑了網上的部落格,實現無邊框,自由拖動的自定義視窗效果。 #ifndef CUSTOMWINDOW_H #define CUSTOMWINDOW_H #include <QtGui> #include <QtWidg
史上最簡單的SpringCloud教程 | 第九篇: 服務鏈路追蹤(Spring Cloud Sleuth)
這篇文章主要講述服務追蹤元件zipkin,Spring Cloud Sleuth集成了zipkin元件。 一、簡介 Add sleuth to the classpath of a Spring Boot application (see below fo
十一:對微服務呼叫鏈監控的理解
微服務專欄地址 目錄 1. 簡介 微服務的呼叫鏈監控是解決微服務的複雜性帶來的一系列問題的強有效手段之一,從一下幾個方面來先理解微服務呼叫鏈監控相關: 簡介 什麼是呼叫鏈 為什麼要監控呼叫鏈 要監控哪些方面 呼叫鏈監控原理是什麼 5.1
RabbitMQ入門教程(十一):訊息屬性Properties
簡介 傳送訊息可以為訊息指定一些引數 Delivery mode: 是否持久化,1 - Non-persistent,2 - Persistent Headers:Headers can have
WebGL簡易教程(十一):紋理
目錄 1. 概述 2. 例項 2.1. 準備紋理 2.2. 配置紋理 2.3. 使用紋理 3. 結果 4. 參考
Spring Cloud Sleuth服務鏈路追蹤(mysql儲存鏈路資料)(Finchley版本)
在Spring Cloud Sleuth服務鏈路追蹤(Finchley版本)中,我們使用Spring Cloud Sleuth和zipkin的整合實現了服務鏈路的追蹤,但是遺憾的是鏈路資料儲存在記憶體中,無法持久化。zipkin的持久化可以結合Elasticsearch,MySQL實現。本節
SpringCloud微服務雲架構構建B2B2C電子商務平臺之-(九)服務鏈路追蹤(Spring Cloud Sleuth)
這篇文章主要講述服務追蹤元件zipkin,Spring Cloud Sleuth集成了zipkin元件。 一、簡介Add sleuth to the classpath of a Spring Boot application (see below for Maven and Gradle examples
springCloud(F版)(5)——Sleuth服務鏈路追蹤zipkin元件
SpringCloud提供了Sleuth框架用於服務追蹤,集成了zipkin元件。zipkin-server有現成的jar包直接啟動就好,當然你也可以自己建立一個豐富他的功能。客戶端也及其簡單,只要pom.xml引入依賴,配置檔案指定zipkin-server的url就行了。 前面博文我們建
SpringCloud學習記錄——Sleuth服務鏈路追蹤(Zipkin實現)
1、簡介。Spring Cloud Sleuth 主要功能就是在分散式系統中提供追蹤解決方案,並且相容支援了 zipkin,你只需要在pom檔案中引入相應的依賴即可。(呃呃,講人話就是:“既然是搞分散式微服務架構,那麼隨著專案的越來越大,微服務就會越來越多,微服務之間的呼叫會
《springcloud — Finchley.RELEASE版》第八篇 服務鏈路追蹤Sleuth
Sleuth簡述 微服務架構是通過業務來劃分服務的,對外暴露的介面,可能需要很多個服務協同才能完成一個介面功能,如果鏈路上任何一個服務出現問題,都會形成導致介面呼叫失敗。此時查找出現問題的微服務是很困難的。Spring Cloud Sleuth主要功能就是在分散式系統中提供
SpringCloud 學習筆記------服務鏈路追蹤(Spring Cloud Sleuth)
一、理論準備 目前以我的理解能力,能看明白的就是一句話——哪個介面呼叫了哪個介面,傳遞了什麼資料,花了多長時間。 Spring Cloud Sleuth 主要功能就是在分散式系統中提供追蹤解決方案,並且相容支援了 zipkin,你只需要在pom檔案中引入相應的依賴
SpringCloud(7)服務鏈路追蹤Sleuth
1.簡介 Spring Cloud Sleuth 主要功能就是在分散式系統中提供追蹤解決方案,並且相容支援了 zipkin,你只需要在pom檔案中引入相應的依賴即可。本文主要講述服務追蹤元件zipkin,Spring Cloud Sleuth集成了zipkin元件。 2.術語 Span:基本工作單
spring cloud 入門系列八:使用spring cloud sleuth整合zipkin進行服務鏈路追蹤
好久沒有寫部落格了,主要是最近有些忙,今天忙裡偷閒來一篇。 =======我是華麗的分割線========== 微服務架構是一種分散式架構,微服務系統按照業務劃分服務單元,一個微服務往往會有很多個服務單元,一個請求往往會有很多個單元參與,一旦請求出現異常,想要去定位問題點真心不容易,因此需要有個東西去跟蹤