zipkin 官网
zipkin gitHub 仓库地址
zipkin server 配置信息 官方地址
code.7z

一、Introduce

1.1、brief introduce

zipkin 官方介绍

Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in service architectures. Features include both the collection and lookup of this data.

大意如下:

Zipkin 是一个分布式追踪系统。它有助于收集计时数据,这些数据由于解决服务架构中的延迟问题。 Zipkin 提供了对收集来数据进行整理和整理之后的查找的功能。

1.2、Zipkin UI 界面

链路追踪图

01.png
zipkin 官方介绍

If you have a trace ID in a log file, you can jump directly to it. Otherwise, you can query based on attributes such as service, operation name, tags and duration. Some interesting data will be summarized for you, such as the percentage of time spent in a service, and whether or not operations failed.

大意如下

通过 trace ID , 服务,操作名称,标记,访问时长等可以进行链路的信息查询,链路信息上总结了如:本次请求花费总时间,各个服务节点间的时间花费及百分比,请求成功失败,甚至请求 URL ,请求方法等都能够进行展示。

服务依赖图

02.png
zipkin 官方介绍

The Zipkin UI also presents a Dependency diagram showing how many traced requests went through each application. This can be helpful for identifying aggregate behavior including error paths or calls to deprecated service

大意如下

Zipkin 还提供了依赖关系图,用来显示每个应用程序中有多少跟踪请求。这有助于识别聚合行为,包括:错误路径或者不被推荐的服务调用。

二、Getting Started

使用 docker 启动,进行测试

Zipkin 提供的 Docker 案例
Docker Hub Zipkin 地址

2.1、Spring Cloud 链路测试代码

项目结构

04.png

项目依赖

05.png

访问 API http://localhost:28080/sleuth-client/hello?name=zhixing

zuul -> sleuth-client -> sleuth-server

2.2、Zipkin In Memory 部署

重启 zipkin 服务,之前收集的数据,失效。

官方提供的 zipkin 启动方式

step1、启动 docker 容器

  1. docker run -d -p 9411:9411 --name zipkin-in-memory openzipkin/zipkin:2.12.9

step2、访问界面 http://ip:9411

03.png

step3、访问 API 查看请求链路信息

06.png
07.png

2.3、Zipkin In Mysql 部署

zipkin 收集到的数据持久化到 Mysql 中,重新内容仍存在

step1、启动 mysql 服务节点,并创建 zipkin 库,同时初始化脚本

Zipkin Mysql 初始化脚本

  1. docker run --name mysql_1 -p 3307:3306 -v ~/mysql_1/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d docker.io/mysql:5.7

数据库信息如下:
08.png

step2、启动 zipkin 服务,指定 Mysql 信息

Docker-Compose 参考配置

  1. version: '2'
  2. services:
  3. zipkin:
  4. image: openzipkin/zipkin:2.12.9
  5. container_name: zipkin
  6. environment:
  7. - STORAGE_TYPE=mysql
  8. - MYSQL_DB=zipkin
  9. - MYSQL_USER=root
  10. - MYSQL_PASS=123456
  11. - MYSQL_HOST=192.168.2.154
  12. - MYSQL_TCP_PORT=3307
  13. ports:
  14. - 9411:9411

启动

  1. docker-compose up -d

step3、访问 API 查看请求链路信息(同上)

依赖如下图
09.png