参见上一篇博客:Spring Cloud Sleuth 服务跟踪

参考:zipkin使用mysql保存数据

主要在跟踪服务上配置:

在数据库创建数据库表:(可不创建,在classpath中添加对应的sql文件也可,有效率问题,详细上面链接文章)

CREATE TABLE IF NOT EXISTS zipkin_spans (`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',`trace_id` BIGINT NOT NULL,`id` BIGINT NOT NULL,`name` VARCHAR(255) NOT NULL,`parent_id` BIGINT,`debug` BIT(1),`start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',`duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate';
ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations';
ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';
ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';CREATE TABLE IF NOT EXISTS zipkin_annotations (`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',`trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',`span_id` BIGINT 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 NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',`a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',`endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',`endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',`endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',`endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';
ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';
ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces';
ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces';CREATE TABLE IF NOT EXISTS zipkin_dependencies (`day` DATE NOT NULL,`parent` VARCHAR(255) NOT NULL,`child` VARCHAR(255) NOT NULL,`call_count` BIGINT
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

  

pom.xml 添加如下配置:

<!-- zipkin storage mysql. -->
<dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-storage-mysql</artifactId><version>2.4.1</version><!-- 此版本与zipkin版本对应 -->
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 这是mysql驱动,如果自己配置也行,加这个依赖也行 -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId>
</dependency>
<!--/ zipkin storage mysql. -->

  

配置:

server:port: 9411
spring:datasource:schema: classpath:/mysql.sql # 已经存在数据库及其表,则可不写url: jdbc:mysql://localhost:3306/zipkinusername: rootpassword: root
# Switch this on to create the schema on startup:initialize: truecontinueOnError: truesleuth:enabled: false
zipkin:storage:type: mysql

  

在启动类添加数据源驱动:

package com.thunisoft.maybeesleuthcenter;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import zipkin.server.EnableZipkinServer;
import zipkin.storage.mysql.MySQLStorage;import javax.sql.DataSource;@EnableZipkinServer
@SpringBootApplication
public class MaybeeSleuthcenterApplication {public static void main(String[] args) {SpringApplication.run(MaybeeSleuthcenterApplication.class, args);}@Beanpublic MySQLStorage mySQLStorage(DataSource datasource) {return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build();}
}

  

Spring Cloud Sleuth 服务跟踪 将跟踪信息存储到数据库相关推荐

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

    2019独角兽企业重金招聘Python工程师标准>>> 简述 使用 spring cloud 用到最多的是各种rest服务调用,Twitter的Zipkin 是一种实现分布式跟踪解决 ...

  2. Spring Cloud微服务java B2B2C商城系统,数据库设计规范

    易写科技java B2B2C电商系统,采用SpringMVC+Spring+Mybatis,基于Maven构建,是行业最适合二次开发的电商系统. B2B2C多商家商城系统,基于SpringMVC+Sp ...

  3. 五分钟学会 Spring Cloud Sleuth:分布式请求链路跟踪(小白必看,一看就会教程)

    Spring Cloud Sleuth:分布式请求链路跟踪 Spring Cloud Sleuth 简介 给服务添加请求链路跟踪 整合Zipkin获取及分析日志 使用Elasticsearch存储跟踪 ...

  4. Spring微服务实战第9章 使用Spring Cloud Sleuth和Zipkin进行分布式跟踪

    文章目录 第9章 使用Spring Cloud Sleuth和Zipkin进行分布式跟踪 9.1 Spring Cloud Sleuth与关联ID 9.1.1 将Spring Cloud Sleuth ...

  5. Spring Cloud微服务系统架构的一些简单介绍和使用

    Spring Cloud 目录 特征 云原生应用程序 Spring Cloud上下文:应用程序上下文服务 引导应用程序上下文 应用程序上下文层次结构 改变Bootstrap的位置Properties ...

  6. (十二)java版b2b2c社交电商spring cloud分布式微服务:使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪...

    Spring Cloud Sleuth Spring cloud b2b2c电子商务社交平台源码请加企鹅求求:一零三八七七四六二六.一般的,一个分布式服务跟踪系统,主要有三部分:数据收集.数据存储和数 ...

  7. Spring Cloud Sleuth+Zipkin 构建微服务链路跟踪系统

    什么是链路跟踪系统? 在微服务中,多个服务分布在不同物理机器上,各个服务之间相互调用.如何清晰地记录服务调用过程,并在出现问题的时候能够通过查看日志和服务之间的调用关系来定位问题,这样的系统就叫做链路 ...

  8. SpringCloud 从菜鸟到大牛之九 服务跟踪 spring CLoud sleuth + Zikpin

    spring CLoud sleuth + Zikpin 记得下面这张架构图 Annotation

  9. 跟踪React流–将Spring Cloud Sleuth与Boot 2结合使用

    Spring Cloud Sleuth在OpenZipkin Brave的基础上增加了对Spring工具的支持, 从而使Spring Boot应用程序的分布式跟踪变得异常简单. 这是关于使用此出色的库 ...

最新文章

  1. 怎么卸载云骑士装机大师
  2. java ide 进行图形化界面时不能显示汉字_主流开源IDE汇总,Java程序员一定能用上!...
  3. 严重: Dispatcher initialization failed java.lang.RuntimeException
  4. App用户体验的一点思考
  5. 多图 | 操作系统中,进程与线程怎么设计的?
  6. linux 内核 工作队列,Linux内核新旧工作队列机制的剖析和比较
  7. 易语言自定义数据类型转c,一步一步跟我学易语言之自定义数据类型
  8. 精选| 2021年9月R新包推荐(第58期)
  9. 从“朕已阅”到“翻牌子”,程序员的仪式感可以有多重?
  10. 【ACL2019】轻松了解张岳实验室的六篇paper
  11. 微型orm fluentdata
  12. ZOJ1109_Language of FatMouse(STL/map)
  13. iOS---UIScrollView实现相册循环
  14. JavaScript数字精度丢失的一些问题
  15. 水滴IP教你如何查询QQ好友的IP地址
  16. 一张图片放两个二维码_经验 | 图片排版的「17个实用技巧」
  17. 光纤模块与光纤收发器使用方法
  18. Python爬虫笔记【一】模拟用户访问之验证码清理(4)
  19. 改善用户体念:jsp+Ajax实现实时上传,删除,导入Excel进度条
  20. 原生js获取本地ip地址(自己用)

热门文章

  1. python制作ios游戏_python自动化生成IOS的图标
  2. java异常_聊聊Java中的异常及处理
  3. flutter 类似日期选择器控件_一切皆组件的Flutter,安能辨我是雄雌
  4. 五连阳回调买入法_短线高手总结的强势股回调买入法,散户需牢记
  5. pringboot 单元测试 空指针_单元测试中的 FIRST 原则
  6. cudnn 安装失败_Win10下安装tensorflow环境的一些坑
  7. 如何利用Python调用一些搜索引擎网站?
  8. 使用BH1750测量激光发射器的强度
  9. python 快速排序_小白入门知识详解:Python实现快速排序的方法(含实例代码)...
  10. php mysql 遍历 嵌套_PHP / mySQL – 如何将嵌套行提取到multidimensinal数组中