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` 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; 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` 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; 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` VARCHAR(255) NOT NULL,
`child` VARCHAR(255) 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 + hystrixdashboard

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

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

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

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

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

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

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

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

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

  6. 【第二十九章】 springboot + zipkin + mysql

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

  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. MySQL索引原理及慢查询优化-zz

    https://tech.meituan.com/mysql-index.html MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色,但所 ...

  2. idea 2017破解方法

    http://blog.csdn.net/zx110503/article/details/78734428

  3. 怎样在 fedora 28 上 打开 .jnlp 文件

    最近使用 iDrac 和 iLO 总是会使用到 .jnlp 文件, 为了方便,今天把设置过程记录下来. JNLP 文件,全名为 Java Network Launching Protocol 文件, ...

  4. 【转】Java学习---内存溢出的排查经历

    [原文]https://www.toutiao.com/i6595365358301872643/ 前言 OutOfMemoryError 问题相信很多朋友都遇到过,相对于常见的业务异常(数组越界.空 ...

  5. 微信支付回调,XXE攻击漏洞防止方法

    最近微信支付回调发现的XXE攻击漏洞(什么是XXE攻击,度娘.bing去搜,一搜一大把),收到通知后即检查代码, 微信给的解决方法是如果你使用的是: XmlDocument: XmlDocument ...

  6. jquery实现根据所选时间生成页面元素

    最近做项目,碰见这样的一个需求 根据所选的时间动态生成值班安排,日期格式需要带星期,如: 代码如下: 1.首先放两个文本框,时间插件用的是My97DataPicker,再放一个table,简单设置一下 ...

  7. PyQt5--MainWindow

    # -*- coding:utf-8 -*- ''' Created on Sep 14, 2018 @author: SaShuangYiBing ''' import sys from PyQt5 ...

  8. 如何为已有的类没有生成toString的方法增强生成toString方法

    1:只要提到增强,我的第一思路就是代理,动态代理.但是仅仅是一个toString其实没必要使用代理模式了,有点大材小用了(动态代理其实也是最后通过反射生成toString的方法). 2:简单粗暴,可以 ...

  9. ElasticSearch + Logstash + Kibana 搭建笔记

    ElasticSearch 安装 1.下载 ElasticSearch,本文使用的版本为 5.5.1. 2.配置 path.data: /data/es #数据路径 path.logs: /data/ ...

  10. 数据同步canal服务端HA配置

    canal服务端HA模式,本人并未使用过,为保证文章的完整性,从以下地址摘抄该部分内容,待以后验证及使用 https://github.com/alibaba/canal/wiki/AdminGuid ...