zipkin的数据存储可以存在4个地方:

  • 内存(仅用于测试,数据不会持久化,zipkin-server关掉,数据就没有了)

    • 这也是之前使用的
  • mysql
    • 可能是最熟悉的方式
  • es
  • Cassandra

一、代码(基于 第二十八章 springboot + zipkin(brave定制-AsyncHttpClient)

1、pom.xml

         <dependency>
             <groupId>io.zipkin.brave</groupId>
             <artifactId>brave-mysql</artifactId>
             <version>3.9.0</version>
        </dependency>

2、ZipkinConfig添加如下

     @Bean
     public MySQLStatementInterceptorManagementBean mySQLStatementInterceptorManagementBean(Brave brave) {
         return new MySQLStatementInterceptorManagementBean(brave.clientTracer());
     }

二、数据库

1、建库

  • 自己创建库(eg.mytestdb)就好

2、建表

  • 在mytestdb中执行zipkin准备好的脚本mysql.sql来创建三张表以及各个索引。

mysql.sql位置:https://github.com/openzipkin/zipkin/blob/master/zipkin-storage/mysql/src/main/resources/mysql.sql

或者直接将整个zipkin项目克隆下来,再进去看内容。

mysql.sql内容如下:

CREATE TABLE IF NOT EXISTS zipkin_spans (
  `trace_id` BIGINT NOT NULL,
  `id` BIGINT NOT NULL,
  `name` ) NOT NULL,
  `parent_id` BIGINT,
  `debug` ),
  `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;

ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id`, `id`) COMMENT 'ignore insert on duplicate';
ALTER TABLE zipkin_spans ADD INDEX(`trace_id`, `id`) COMMENT 'for joining with zipkin_annotations';
ALTER TABLE zipkin_spans ADD INDEX(`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` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',
  `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',
  `a_key` ) 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` ) 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` ) COMMENT 'Null when Binary/Annotation.endpoint is null'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;

ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
ALTER TABLE zipkin_annotations ADD INDEX(`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` ) NOT NULL,
  `child` ) NOT NULL,
  `call_count` BIGINT
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;

ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

执行脚本之后,数据库出现三张表,如下:

三、启动命令

  • STORAGE_TYPE=mysql MYSQL_HOST=192.192.192.192 MYSQL_TCP_PORT=3306 MYSQL_DB=mytestdb MYSQL_USER=root MYSQL_PASS=123456 nohup java -jar zipkin-server-1.5.1-exec.jar &

    • STORAGE_TYPE:存储类型,这里是mysql
    • MYSQL_HOST和MYSQL_TCP_PORT:创建connection
    • MYSQL_USER和MYSQL_PASS:用户名和密码

四、测试

启动4个service,然后swagger测试,最后查看zipkin和数据库表即可。

【第二十九章】 springboot + zipkin + mysql的更多相关文章

  1. 第二十九章 springboot + zipkin + mysql

    zipkin的数据存储可以存在4个地方: 内存(仅用于测试,数据不会持久化,zipkin-server关掉,数据就没有了) 这也是之前使用的 mysql 可能是最熟悉的方式 es Cassandra ...

  2. 第二十五章 springboot + hystrixdashboard

    注意: hystrix基本使用:第十九章 springboot + hystrix(1) hystrix计数原理:附6 hystrix metrics and monitor 一.hystrixdas ...

  3. Gradle 1.12用户指南翻译——第二十九章. Checkstyle 插件

    其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...

  4. “全栈2019”Java多线程第二十九章:可重入锁与不可重入锁详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  5. “全栈2019”Java第二十九章:数组详解(中篇)

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  6. 【第二十八章】 springboot + zipkin(brave定制-AsyncHttpClient)

    brave本身没有对AsyncHttpClient提供类似于brave-okhttp的ClientRequestInterceptor和ClientResponseInterceptor,所以需要我们 ...

  7. SpringBoot | 第二十九章:Dubbo的集成和使用

    前言 今年年初时,阿里巴巴开源的高性能服务框架dubbo又开始了新一轮的更新,还加入了Apache孵化器.原先项目使用了spring cloud之后,已经比较少用dubbo.目前又抽调回原来的行业应用 ...

  8. 第二十四章 springboot注入servlet

    问:有了springMVC,为什么还要用servlet?有了servlet3的注解,为什么还要使用ServletRegistrationBean注入的方式? 使用场景:在有些场景下,比如我们要使用hy ...

  9. 第二十九章 System V共享内存

    共享内存数据结构 共享内存函数 shmget int shmget(key_t key, size_t size, int shmflg); 功能: 用于创建共享内存 参数: key : 这个共享内存 ...

随机推荐

  1. python 面向对象 析构方法

    实例化但从来没有调用他,就浪费了,就应该自动删除它 这个实例一直存在内存里 python有个垃圾自动回收机制 , 每段时间会自动刷新整个内存,把内存垃圾东西删除   析构函数: 在实例释放.销毁的时候 ...

  2. Javaweb开发请求

    1.Ajax jQuery对Ajax支持:$.ajax({  }); ==>常用参数:url:请求地址,type:post|get,data:请求参数,dataType:服务器返回数据类型,su ...

  3. [LeetCode] 627. Swap Salary_Easy tag: SQL

    Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m v ...

  4. [LeetCode] 221. Maximal Square _ Medium Tag: Dynamic Programming

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...

  5. Python 之 os.walk()

    原文地址https://www.cnblogs.com/JetpropelledSnake/p/8982495.html          http://www.runoob.com/python/o ...

  6. winform dataGridView DataGridViewComboBoxColumn 下拉框事件代码

    有一个dataGridView ,有一列是DataGridViewComboBoxColumn .我用动态绑定,在绑定数据的时候.我们也给这一列绑定数据 在dataGridView的RowsAdded ...

  7. 7.4 Models -- Pushing Records into the Store

    一.概述 1. store是作为一个所有records的缓存,这些records已经被你的应用程序加载.在你的app中如果你的路由或者一个controller请求一条record,如果它在缓存中这个s ...

  8. [转载]C#深拷贝的方法

    首先了解下深拷贝和浅拷贝的定义: 浅拷贝(影子克隆):只复制对象的基本类型,对象类型,仍属于原来的引用.      深拷贝(深度克隆):不紧复制对象的基本类,同时也复制原对象中的对象.就是说完全是新对 ...

  9. #C++初学记录(算法3)

    C - 不要62 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司 ...

  10. LinkedList详解

    一.LinkedList的介绍与特点. 1.继承实现关系. 实现了双端队列接口Deque,因此具有双端队列的功能:addFirt,addLast,offerFirt,offerLast,removeF ...