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

参考:zipkin使用mysql保存数据

主要在跟踪服务上配置:

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

  1. CREATE TABLE IF NOT EXISTS zipkin_spans (
  2. `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
  3. `trace_id` BIGINT NOT NULL,
  4. `id` BIGINT NOT NULL,
  5. `name` VARCHAR(255) NOT NULL,
  6. `parent_id` BIGINT,
  7. `debug` BIT(1),
  8. `start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',
  9. `duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query'
  10. ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
  11.  
  12. ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate';
  13. ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations';
  14. ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';
  15. ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
  16. ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';
  17.  
  18. CREATE TABLE IF NOT EXISTS zipkin_annotations (
  19. `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
  20. `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',
  21. `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',
  22. `a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',
  23. `a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',
  24. `a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',
  25. `a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',
  26. `endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',
  27. `endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',
  28. `endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',
  29. `endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null'
  30. ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
  31.  
  32. ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
  33. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
  34. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';
  35. ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';
  36. ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces';
  37. ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces';
  38.  
  39. CREATE TABLE IF NOT EXISTS zipkin_dependencies (
  40. `day` DATE NOT NULL,
  41. `parent` VARCHAR(255) NOT NULL,
  42. `child` VARCHAR(255) NOT NULL,
  43. `call_count` BIGINT
  44. ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
  45.  
  46. ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

  

pom.xml 添加如下配置:

  1. <!-- zipkin storage mysql. -->
  2. <dependency>
  3. <groupId>io.zipkin.java</groupId>
  4. <artifactId>zipkin-storage-mysql</artifactId>
  5. <version>2.4.1</version><!-- 此版本与zipkin版本对应 -->
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter-jdbc</artifactId>
  10. </dependency>
  11. <!-- 这是mysql驱动,如果自己配置也行,加这个依赖也行 -->
  12. <dependency>
  13. <groupId>mysql</groupId>
  14. <artifactId>mysql-connector-java</artifactId>
  15. </dependency>
  16. <!--/ zipkin storage mysql. -->

  

配置:

  1. server:
  2. port: 9411
  3. spring:
  4. datasource:
  5. schema: classpath:/mysql.sql # 已经存在数据库及其表,则可不写
  6. url: jdbc:mysql://localhost:3306/zipkin
  7. username: root
  8. password: root
  9. # Switch this on to create the schema on startup:
  10. initialize: true
  11. continueOnError: true
  12. sleuth:
  13. enabled: false
  14. zipkin:
  15. storage:
  16. type: mysql

  

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

  1. package com.thunisoft.maybeesleuthcenter;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.context.annotation.Bean;
  6. import zipkin.server.EnableZipkinServer;
  7. import zipkin.storage.mysql.MySQLStorage;
  8.  
  9. import javax.sql.DataSource;
  10.  
  11. @EnableZipkinServer
  12. @SpringBootApplication
  13. public class MaybeeSleuthcenterApplication {
  14.  
  15. public static void main(String[] args) {
  16. SpringApplication.run(MaybeeSleuthcenterApplication.class, args);
  17. }
  18.  
  19. @Bean
  20. public MySQLStorage mySQLStorage(DataSource datasource) {
  21. return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build();
  22. }
  23. }

  

Spring Cloud Sleuth 服务跟踪 将跟踪信息存储到数据库的更多相关文章

  1. Spring Cloud Sleuth服务链路追踪(zipkin)(转)

    这篇文章主要讲述服务追踪组件zipkin,Spring Cloud Sleuth集成了zipkin组件. 一.简介 Spring Cloud Sleuth 主要功能就是在分布式系统中提供追踪解决方案, ...

  2. Spring Cloud(十三):Spring Cloud Sleuth服务链路追踪(zipkin)(转)

    这篇文章主要讲述服务追踪组件zipkin,Spring Cloud Sleuth集成了zipkin组件. 一.简介 Spring Cloud Sleuth 主要功能就是在分布式系统中提供追踪解决方案, ...

  3. Spring Cloud Sleuth 服务跟踪

    项目结构: 一跟踪服务中心,用于收集和展示跟踪情况. 一个服务提供者. 一个服务消费者. 服务跟踪中心: pom.xml添加如下依赖: <dependency> <groupId&g ...

  4. Spring Cloud 微服务分布式链路跟踪 Sleuth 与 Zipkin

    Zipkin 是一个开放源代码分布式的跟踪系统,由 Twitter 公司开源,它致力于收集服务的定时数据,以解决微服务架构中的延迟问题,包括数据的收集.存储.查找和展现.它的理论模型来自于Google ...

  5. Spring Cloud Sleuth服务跟踪

    监控 使用zipkin(https://zipkin.io/) 监控服务构建: (普通的springBoot项目) <!--引入的zipkinServer依赖--> <depende ...

  6. 第11章 分布式服务跟踪: Spring Cloud Sleuth

    通常一个由客户端发起的请求在后端系统中会经过多个不同的微服务调用来协同产生最后的请求结果, 在复杂的微服务架构系统中, 几乎每一个前端请求都会形成一条复杂的分布式服务调用链路, 在每条链路中任何一个依 ...

  7. 【SpringCloud构建微服务系列】分布式链路跟踪Spring Cloud Sleuth

    一.背景 随着业务的发展,系统规模越来越大,各微服务直接的调用关系也变得越来越复杂.通常一个由客户端发起的请求在后端系统中会经过多个不同的微服务调用协同产生最后的请求结果,几乎每一个前端请求都会形成一 ...

  8. 【Spring Cloud】Spring Cloud之Spring Cloud Sleuth,分布式服务跟踪(1)

    一.Spring Cloud Sleuth组件的作用 为微服务架构增加分布式服务跟踪的能力,对于每个请求,进行全链路调用的跟踪,可以帮助我们快速发现错误根源以及监控分析每条请求链路上的性能瓶颈等. 二 ...

  9. 阿里高级架构师教你使用Spring Cloud Sleuth跟踪微服务

    随着微服务数量不断增长,需要跟踪一个请求从一个微服务到下一个微服务的传播过程,Spring Cloud Sleuth 正是解决这个问题,它在日志中引入唯一ID,以保证微服务调用之间的一致性,这样你就能 ...

随机推荐

  1. JAVA日期查询:季度、月份、星期等时间信息

    package com.stt.dateChange; import java.text.SimpleDateFormat; import java.util.Calendar; import jav ...

  2. Django form入门详解--1

     form在django中的作用: 1.可以用于自动生成form的html 2.数据校验 3.与model一在一起使用.可以大的方便数据驱动型网站的开发 编程中有许多的东西是“不可描述”的.只有动手去 ...

  3. 关于有些.aidl源码的eclipse编译后生成.java文件的错

    最近下载了一个aidl源码.导入到eclipse.一直报错.无法运行到. (我是1号图) 2. .然后怎么想都不知道怎么解决.百度和谷歌了n遍. 还是找不到.后来在一个不起眼的地方看到说: aidl不 ...

  4. android - 调用系统分享功能分享图片

    step1: 编写分享代码, 将Uri的生成方式改为由FileProvider提供的临时授权路径,并且在intent中添加flag 注意:在Android7.0之后,调用系统分享,传入URI的时候可能 ...

  5. C++中的typedef typename 作用

    今天在代码里看到了这样一段代码: typedef typename RefBase::weakref_type weakref_type; 起初一直搞不懂为什么要加个typename,后来搜索了一下才 ...

  6. step-by-step-creating-a-sql-server-2012-alwayson-availability-group/

    https://blogs.technet.microsoft.com/canitpro/2013/08/19/step-by-step-creating-a-sql-server-2012-alwa ...

  7. Oracle客户端使用sqlldr导数据中文乱码问题解决方法

    String strctl = "OPTIONS (skip=0)" + // 0是从第一行开始 1是 从第二行 CHARACTERSET AL32UTF8 是为了解决导入中文为乱 ...

  8. [AWS vs Azure] 云计算里AWS和Azure的探究(6) - Amazon Simple Storage Service 和 Microsoft Azure Blob Storage

    这几天Nasuni公司出了一份报告,分析了各个云厂商的云存储的性能,包括Amazon S3,Azure Blob Storage, Google Drive, HP以及Rackspace.其中性能上A ...

  9. Mac OS X 下安装使用 Docker

    它依赖于 LXC(Linux Container),能从网络上获得配置好的 Linux 镜像,非常容易在隔离的系统中运行自己的应用.也因为它的底层核心是个 LXC,所以在 Mac OS X 下需要在 ...

  10. GNU make简介

    引言 接触开源项目有一段时间了,对自动化编译工具一直很好奇.近期有时间正好整理下GNU make.后续可以深入了解下. 本文主要整理GNU make的学习的基本资料,同时简要介绍make的功能.语法. ...