如果你的服务少了,在调用服务时,谁依赖谁应该能看的很清楚,但是成百上千个服务,a调用b,b又调用c,a又调用c,x调用y
那么这么长的服务链我们如何清楚的知道他们之间的调用关系以便系统出现问题时进行定位追踪,解决
那么ZipKin登场了
ZipKin:是一个开放源代码的分布式跟踪系统,由 Twitter 公司开源,它致力于收集服务的定时数据,以解决微服务架构中的延迟问题,包括数据的收集、存储、查找和展现,每个服务向 ZipKin 报告计时数据,ZipKin 会根据调用关系通过 ZipKin UI 生成依赖关系图,显示了多少跟踪请求通过每个服务,该系统让开发者可通过一个 Web 前端轻松的收集和分析数据,例如用户每次请求服务的处理时间等,可方便的监测系统中存在的瓶颈
听着这功能就感觉很牛逼,来一发走起
但在使用ZipKin之前先要了解它的一些术语,就像想使用一个新的产品就要先阅读它的说明书一样
好了继续,创建hello-spring-cloud-zipkin项目
pom.xml
4.0.0
com.funtl
hello-spring-cloud-dependencies
1.0.0-SNAPSHOT
../hello-spring-cloud-dependencies/pom.xml
hello-spring-cloud-zipkin
jar
hello-spring-cloud-zipkin
http://www.funtl.com
2018-Now
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-starter-test
test
io.zipkin.java
zipkin
io.zipkin.java
zipkin-server
io.zipkin.java
zipkin-autoconfigure-ui
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.boot
spring-boot-maven-plugin
com.funtl.hello.spring.cloud.zipkin.ZipKinApplication
主要增加了 3 个依赖,io.zipkin.java:zipkin
、io.zipkin.java:zipkin-server
、io.zipkin.java:zipkinautoconfigureui
注意版本号为:2.10.1 可以托管到
dependencies项目中
dependencies项目的pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
com.funtl
hello-spring-cloud-dependencies
1.0.0-SNAPSHOT
pom
hello-spring-cloud-dependencies
http://www.funtl.com
2018-Now
1.8
UTF-8
UTF-8
Finchley.RELEASE
2.10.1
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
io.zipkin.java
zipkin
${zipkin.version}
io.zipkin.java
zipkin-server
${zipkin.version}
io.zipkin.java
zipkin-autoconfigure-ui
${zipkin.version}
org.apache.maven.plugins
maven-compiler-plugin
true
org.apache.maven.plugins
maven-jar-plugin
false
true
true
true
org.apache.maven.plugins
maven-resources-plugin
org.apache.maven.plugins
maven-install-plugin
org.apache.maven.plugins
maven-clean-plugin
org.apache.maven.plugins
maven-antrun-plugin
org.apache.maven.plugins
maven-dependency-plugin
org.apache.maven.plugins
maven-javadoc-plugin
prepare-package
jar
net.alchim31.maven
yuicompressor-maven-plugin
1.5.1
prepare-package
compress
UTF-8
false
true
30000
true
**/*.js
**/*.css
**/*.min.js
**/*.min.css
src/main/java
**/*.java
src/main/resources
aliyun-repos
Aliyun Repository
http://maven.aliyun.com/nexus/content/groups/public
true
false
sonatype-repos
Sonatype Repository
https://oss.sonatype.org/content/groups/public
true
false
sonatype-repos-s
Sonatype Repository
https://oss.sonatype.org/content/repositories/snapshots
false
true
spring-snapshots
Spring Snapshots
https://repo.spring.io/snapshot
true
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false
aliyun-repos
Aliyun Repository
http://maven.aliyun.com/nexus/content/groups/public
true
false
创建项目的application文件 ZipKinApplication.class
需要加上注解@EnableZipkinServer 开启 Zipkin Server 功能 还有eureka客户端,要注册到eureka上
package com.einblatt.hello.spring.cloud.zipkin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import zipkin.server.internal.EnableZipkinServer;
@SpringBootApplication
@EnableZipkinServer
@EnableEurekaClient
public class ZipKinApplication {
public static void main(String[] args) {
SpringApplication.run(ZipKinApplication.class,args);
}
}
application.yml
spring:
application:
name: hello-spring-cloud-zipkin
server:
port: 9411 //zipkin默认端口
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
management:
metrics:
web:
server:
auto-time-requests: false
追踪服务,每个项目都要进行跟踪,包括eureka,也就是将需要追踪的服务注册到zipkin上,除了dependencies
项目外
增加spring-cloud-starter-zipkin 依赖
org.springframework.cloud
spring-cloud-starter-zipkin
并且在这些项目的application.yml中增加
spring:
zipkin:
base-url: http://localhost:9411
测试zipkin是否追踪成功,访问任意被跟踪的服务
然后再访问http://localhost:9411/
若能追踪到你访问的服务则配置zipkin成功!