zipkin学习--07--Springboot 集成 Zipkin--持久化到数据库

2023-10-26

一、介绍

  1. Zipkin目前只支持mysql数据库
  2. 只需要修改 Zipkin服务端

二、总体结构

在这里插入图片描述

代码位置:https://gitee.com/DanShenGuiZu/learnDemo/tree/master/zipkin-learn

2.1、环境安装


 
docker run -d -p 3306:3306 --name mysql57  -e MYSQL_ROOT_PASSWORD=root   mysql:5.7 


 
 
 

三、代码修改

3.1、pom

pom 修改

在这里插入图片描述

整个pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>fei.zhou</groupId>
    <artifactId>zipkin-demo01-server9411</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>zipkin-demo01-server9411</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath/>
    </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>Camden.SR6</spring-cloud.version>
    </properties>

    <dependencies>
        <!--增加zipkin的依赖 -->
        <!--        <dependency>-->
        <!--            <groupId>io.zipkin.java</groupId>-->
        <!--            <artifactId>zipkin-server</artifactId>-->
        <!--        </dependency>-->

        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
        </dependency>
        <!--将http方式改为通过MQ通信的修改 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        </dependency>
        <!--mysql 持久化-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

    </dependencies>

    <!--依赖管理,用于管理spring-cloud的依赖 -->
    <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>

    <build>
        <plugins>
            <!--使用该插件打包 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

3.2、zipkin.sql

在这里插入图片描述

 
DROP TABLE IF EXISTS `zipkin_annotations`;
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 NULL 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) NULL DEFAULT NULL COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',
  `endpoint_ipv4` int(11) NULL DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null',
  `endpoint_ipv6` binary(16) NULL DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',
  `endpoint_port` smallint(6) NULL DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null',
  `endpoint_service_name` varchar(255)  NULL DEFAULT NULL COMMENT 'Null when Binary/Annotation.endpoint is null',
  UNIQUE INDEX `trace_id_high`(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) USING BTREE COMMENT 'Ignore insert on duplicate',
  UNIQUE INDEX `trace_id_high_4`(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) USING BTREE COMMENT 'Ignore insert on duplicate',
  INDEX `trace_id_high_2`(`trace_id_high`, `trace_id`, `span_id`) USING BTREE COMMENT 'for joining with zipkin_spans',
  INDEX `trace_id_high_3`(`trace_id_high`, `trace_id`) USING BTREE COMMENT 'for getTraces/ByIds',
  INDEX `endpoint_service_name`(`endpoint_service_name`) USING BTREE COMMENT 'for getTraces and getServiceNames',
  INDEX `a_type`(`a_type`) USING BTREE COMMENT 'for getTraces',
  INDEX `a_key`(`a_key`) USING BTREE COMMENT 'for getTraces',
  INDEX `trace_id`(`trace_id`, `span_id`, `a_key`) USING BTREE COMMENT 'for dependencies job',
  INDEX `trace_id_high_5`(`trace_id_high`, `trace_id`, `span_id`) USING BTREE COMMENT 'for joining with zipkin_spans',
  INDEX `trace_id_high_6`(`trace_id_high`, `trace_id`) USING BTREE COMMENT 'for getTraces/ByIds',
  INDEX `endpoint_service_name_2`(`endpoint_service_name`) USING BTREE COMMENT 'for getTraces and getServiceNames',
  INDEX `a_type_2`(`a_type`) USING BTREE COMMENT 'for getTraces',
  INDEX `a_key_2`(`a_key`) USING BTREE COMMENT 'for getTraces',
  INDEX `trace_id_2`(`trace_id`, `span_id`, `a_key`) USING BTREE COMMENT 'for dependencies job'
) ENGINE = InnoDB;

-- ----------------------------
-- Table structure for zipkin_dependencies
-- ----------------------------
DROP TABLE IF EXISTS `zipkin_dependencies`;
CREATE TABLE `zipkin_dependencies`  (
  `day` date NOT NULL,
  `parent` varchar(255)  NOT NULL,
  `child` varchar(255)  NOT NULL,
  `call_count` bigint(20) NULL DEFAULT NULL,
  UNIQUE INDEX `day`(`day`, `parent`, `child`) USING BTREE,
  UNIQUE INDEX `day_2`(`day`, `parent`, `child`) USING BTREE
) ENGINE = InnoDB;

-- ----------------------------
-- Table structure for zipkin_spans
-- ----------------------------
DROP TABLE IF EXISTS `zipkin_spans`;
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) NULL DEFAULT NULL,
  `debug` bit(1) NULL DEFAULT NULL,
  `start_ts` bigint(20) NULL DEFAULT NULL COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',
  `duration` bigint(20) NULL DEFAULT NULL COMMENT 'Span.duration(): micros used for minDuration and maxDuration query',
  UNIQUE INDEX `trace_id_high`(`trace_id_high`, `trace_id`, `id`) USING BTREE COMMENT 'ignore insert on duplicate',
  UNIQUE INDEX `trace_id_high_4`(`trace_id_high`, `trace_id`, `id`) USING BTREE COMMENT 'ignore insert on duplicate',
  INDEX `trace_id_high_2`(`trace_id_high`, `trace_id`, `id`) USING BTREE COMMENT 'for joining with zipkin_annotations',
  INDEX `trace_id_high_3`(`trace_id_high`, `trace_id`) USING BTREE COMMENT 'for getTracesByIds',
  INDEX `name`(`name`) USING BTREE COMMENT 'for getTraces and getSpanNames',
  INDEX `start_ts`(`start_ts`) USING BTREE COMMENT 'for getTraces ordering and range',
  INDEX `trace_id_high_5`(`trace_id_high`, `trace_id`, `id`) USING BTREE COMMENT 'for joining with zipkin_annotations',
  INDEX `trace_id_high_6`(`trace_id_high`, `trace_id`) USING BTREE COMMENT 'for getTracesByIds',
  INDEX `name_2`(`name`) USING BTREE COMMENT 'for getTraces and getSpanNames',
  INDEX `start_ts_2`(`start_ts`) USING BTREE COMMENT 'for getTraces ordering and range'
) ENGINE = InnoDB;
 

3.3、application.properties

server.port=9411
spring.application.name=zipkin-demo01-server9411


#连接rabbitmq服务器配置
spring.rabbitmq.host=IP
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=123456


#------------zipkin数据保存到数据库中需要进行如下配置------------
#表示当前程序不使用sleuth
spring.sleuth.enabled=false
#表示zipkin数据存储方式是mysql
zipkin.storage.type=mysql

#数据库脚本创建地址,当有多个时可使用[x]表示集合第几个元素,脚本可到官网下载,需要先手动到数据库执行
spring.datasource.schema[0]=classpath:/zipkin.sql

#spring boot数据源配置
spring.datasource.url=jdbc:mysql://IP:3306/test4?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8\
  &useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.initialize=true
spring.datasource.continue-on-error=true

四、测试

在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

zipkin学习--07--Springboot 集成 Zipkin--持久化到数据库 的相关文章

  • win8/win10操作系统如何通过Legacy BIOS与UEFI两种模式安装

    感谢联想的工程师 Win8系统相对于Win7系统在开机速度上有相当大的提升 这是因为Win8系统为了提升系统性能和对硬件的优化 加入了诸如开机引导及应用预缓存等技术 而其中的UEFI BIOS引导 则能使平台开机更智能 开机速度更快 对比采
  • java中Math,Systerm,Object,Integer类中的一些常见方法

    一 Math类 int abs int 返回绝对值 double ceil double 向上取整 double floor double 向下取整 int round float 四舍五入取整 int max int m int n 返回
  • Springboot 之 JDBC 多数据源实现

    简介 Springboot 中使用 JdbcTemplate 实现多数据源比较简单 查看 JdbcTemplate 源码 可以发现 JdbcTemplate 提供了传入 DataSource 的方式构建不同的 JdbcTemplate 实例
  • Elasticsearch(六)--ES文档的操作(中)---修改文档

    一 前言 上篇文章我们了解了ES的插入和批量插入文档的操作 分别通过ES的kibana客户端以及Java高级Rest客户端进行学习 那么本篇则进入到对文档的修改操作 同新增文档 也有更新单条文档和批量更新文档操作 但还多出一个根据条件更新文

随机推荐

  • Jlink使用技巧之烧写SPI Flash存储芯片

    文章目录 前言 准备 硬件连接 1 打开 2 连接SPI Flash芯片 3 打开程序文件 4 下载 5 程序文件的读取 6 程序文件的保存 7 命令行工具的使用 支持的芯片列表 速度说明 参考资料 JLink软件的下载 前言 大多数玩单片
  • 【异步编程】Promise

    Promise的基本用法 创建promise对象 Promise对象代表一个异步操作 有三种状态 pending 进行中 fulfilled 已成功 和rejected 已失败 Promise构造函数接受一个函数作为参数 该函数的两个参数分
  • Linux基础命令-正则表达式和通配符

    Linux基础命令 正则表达式和通配符 正则表达式和通配符 一 正则表达式 1 正则表达式概念 2 字符匹配 3 匹配次数 4 位置锚定 5 分组 6 后向引用 7 扩展正则表达式 二 通配符 1 通配符 2 Shell常见通配符 3 sh
  • python中类的self的含义

    import torch 省略部分代码 网络模型 预测部分 class Net1 def init self input test self inputn test scaler1 transform input test self inp
  • 排序算法之快速排序及其C语言代码实现

    概述 快速排序 Quicksort 是对冒泡排序的一种改进 快速排序由C A R Hoare在1962年提出 它的基本思想是 通过一趟排序将要排序的数据分割成独立的两部分 其中一部分的所有数据都比另外一部分的所有数据都要小 然后再按此方法对
  • IDA工具安装、分享

    往期推荐 ARM处理器寻址方式 ARM指令集 ARM汇编语言程序结构 Android与ARM处理器 IDA工具被称之为是世界顶级的交互汇编 掌握IDA工具界面上的快捷功能 导航条主界面功能以及汇编窗口常用快捷键的使用 实战分析 了解ARM指
  • 接口一定要实现序列化Serializable吗?

    背景 最近在做项目的过程中 发现一个问题 我们服务之间调用的feign接口及对外提供的接口 里面的对象都实现了序列化 但是以前我们的对外接不写序列化 也没有啥问题 在这里的时候 就有点疑惑 1 为什么要进行序列化 2 每个实体bean都必须
  • Linux内核Backlog笔记

    一 listen方法传入的backlog参数 net core somaxconn 这个参数具体意义 先看看Linux Socket的listen解释 man listen include
  • C++报错类型elemType classType::member is protected within this context的解决思路

    C 报错类型elemType classType member is protected within this context的解决思路 问题背景 在对象类尝试增加友元函数 什么是友元函数 在类中增加友元类 问题背景 在查看 lt lt
  • yolo算法

    YOLO系列算法是一类典型的one stage目标检测算法 其利用anchor box将分类与目标定位的回归问题结合起来 从而做到了高效 灵活和泛化性能好 所以在工业界也十分受欢迎 接下来我们介绍YOLO 系列算法 1 yolo算法 Yol
  • 【VMware】虚拟机不能全屏的解决方法

    之前装了vmware workstation 8 最近装上新的ubuntu发现不能全屏 网上搜索后发现是因为没有安装vmware tools 现在就将本人安装vmware tools的过程介绍如下 1 加载vmwaretools 1 如下图
  • SQL语句中的in/exist/NOT IN/NOT EXIST的联系与区别

    IN EXIST NOT IN NOT EXIST的效率比较 由于使用使用not in 进行查询时 不会使用索引 所以not in 在任何情况下 效率都是最差的 而not exist和 exist两者效率是一致的 接下来主要辨析IN和EXI
  • DAMA学习笔记

    第1章 数据管理 1 1 引言 1 数据管理 为了实现数据价值 制定计划 制度并执行 监督 2 数据管理专业人员 技术人员 数据库管理员 网络管理员 程序员 和业务人员 数据管理专员 数据策略师 首席数据官 1 1 1 业务驱动因素 信息和
  • C++ Template Class List

    转载请注明 http blog csdn net c602273091 article details 50717999 Introduction STL STL Standard Template Library 标准模板库 是惠普实验室
  • 时序分析 30 金融资产预测 - 蒙特卡洛模拟

    金融资产预测 蒙特卡洛模拟 商业经营活动中经常需要预测其收入 成本和利润 企业中的金融团队很可能会被要求构建金融模型进行场景分析 例如在不同的假设的情况下分析最好的情况 正常情况和最差的情况 这样做的目的主要是为管理层提供在不同的市场情况下
  • Overleaf latex绘制三线表

    在 begin document 前加入以下内容 usepackage array 需要用到该宏包 usepackage footnote makesavenoteenv tabular 示例 begin table htbp captio
  • Windows向日葵连接Ubuntu时“连接已断开”解决方案

    环境 控制端 Windows10 系统 向日葵版本12 5 1 44969 被控端 Ubuntu20 04 系统 默认gdm3桌面 向日葵版本11 0 0 36662 问题描述 使用windows端向日葵远程连接ubuntu主机时出现 连接
  • 【springboot】 整合 jasypt 配置信息加密

    项目集成jasypt的方式 引入jasypt spring boot加密组件 通过jasypt spring boot这个开箱即用的加密组件来引入Jasypt这个强大的加密库 方式一 在Springboot应用程序中 如果使用了 Sprin
  • 2020最新版Python学习路线图--Python基础重点知识

    Python学习路线图的第一阶段Python基础的学习 Python学习这一阶段的学习目标是掌握Python基础语法 具备基础的编程能力 建立起Python学习编程思维以及面向对象程序设计思想 能够熟练使用Python技术完成针对小问题的程
  • zipkin学习--07--Springboot 集成 Zipkin--持久化到数据库

    一 介绍 Zipkin目前只支持mysql数据库 只需要修改 Zipkin服务端 二 总体结构 代码位置 https gitee com DanShenGuiZu learnDemo tree master zipkin learn 2 1