简介
Zipkin是一套Twitter开发的开源的APM工具 (Application Performance Management) ,可以用于微服务的调用链监控。
类似的APM系统还有:PinPoint、Google Dapper、淘宝鹰眼等。
相比起PinPoint,Zipkin的优势是语言无关性,但是对代码有一定的入侵。
Zipkin包含4个组件:
- Collector 收集器
- Storage 存储,默认是InMemory
- API 查询接口
- UI WEB界面
运行示意图:

官网及GitHub
服务端安装及运行
Zipkin服务端提供了多种运行方式,都很简便。使用源码方式可以有更多的可定制性。
Docker方式
Docker方式:
1
| docker run -d -p 9411:9411 openzipkin/zipkin
|
JAR包方式
1 2
| wget -O zipkin.jar 'https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec' java -jar zipkin.jar
|
源码方式
pom.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
<dependencies> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-autoconfigure-ui</artifactId> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-server</artifactId> </dependency> </dependencies>
|
application.yml:
1 2
| server.port: 9411 spring.application.name: zen-zipkin
|
服务端WEB界面
服务端启动后,以在浏览器中看一下WEB界面是否正常:
http://localhost:9411
微服务端配置
pom.xml:
1 2 3 4
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-sleuth-zipkin</artifactId> </dependency>
|
application.yml:
1 2 3 4 5 6 7
| spring: zipkin: base-url: http://localhost:9411 sleuth: sampler: percentage: 1.0
|
其中percentage是采样率,默认0.1
当微服务启动后,就可以在Zipkin的界面中进行调用链的监控了:
