这里写目录标题
1、简介
zipkin是一个分布式的跟踪系统,由Twitter公司开发的,是根据Google发表的那一片论文Dapper, a Large-Scale Distributed Systems Tracing Infrastructure来设计的。zipkin的主要功能是收集来自各个系统的监控数据。
zipkin主要包括四个模块:
Collector 接受或者收集各个应用传输的数据
Storage:负责存储接收到的数据,默认是存储在内存当中的,也可以支持存在MySQL当中
API:负责查询Storage中存储的数据,主要是提供给Web UI来使用
Web:主要是提供简单的web界面
工作流程
一个应用的代码发起HTTP get请求,经过Trace框架拦截,然后
把当前调用链的Trace信息添加到HTTP Header里面
记录当前调用的时间戳
发送HTTP请求,把trace相关的header信息携带上
调用结束之后,记录当前调用话费的时间
然后把上面流程产生的 信息汇集成一个span,把这个span信息上传到zipkin的Collector模块
Zipkin提供了可插拔数据存储方式:In-Memory、MySql、Cassandra以及Elasticsearch
2、例子(服务器端)
以mem为例子:
config
#the common configuration
#the common of springCloud
spring.application.name=zipkin-server
server.port=9001
spring.main.allow-bean-definition-overriding=true
management.metrics.web.server.auto-time-requests=false
#��������Ϊzipkin����kafka
#�洢���ͣ�ȱʧ�������ʱ��Ĭ��ʹ���ڴ�
zipkin.storage.type=mem
zipkin.collector.kafka.bootstrap-servers=10.9.44.14:9092
zipkin.collector.kafka.zookeeper=10.9.44.13:2181
#kafka���⣬������ʱĬ��ʹ��zipkin
zipkin.collector.kafka.topic=zipkin_test
#logging.level.root=debug
pom
```java
<?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>com.example</groupId>
<artifactId>bdf_zipkin</artifactId>
<name>链路收集服务</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.sdyy</groupId>
<artifactId>bdf_parent</artifactId>
<version>4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.spring>3.2.9.RELEASE</version.spring>
<version.jackson>2.4.4</version.jackson>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.10.0</version>
</dependency>
<!-- kafka -->
<!--sleuth日志发送到kafka-->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-collector-kafka</artifactId>
<version>2.11.4</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</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>
<repositories>
<repository>
<id>aliyun-repos</id>
<name>Aliyun Repository</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun-repos</id>
<name>Aliyun Repository</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
2、例子(客户端)
config
#zipkin配置
spring.zipkin.base-url=http://10.9.44.16:9001/
spring.sleuth.sampler.percentage=1
#spring.zipkin.sender.type=web
spring.sleuth.web.client.enabled=true
spring.sleuth.sampler.probability=1
pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<!-- <version>2.1.0.RELEASE</version>-->
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<!-- <version>2.1.0.RELEASE</version>-->
</dependency>
https://www.cnblogs.com/xiangkejin/archive/2018/05/16/9046238.html