ZipKin介绍
Zipkin是一款开源的分布式实时数据追踪系统(Distributed Tracking System),基于 Google Dapper的论文设计而来,由 Twitter 公司开发贡献。其主要功能是聚集来自各个异构系统的实时监控数据。
ZipKin架构
ZipKin可以分为两部分,一部分是zipkin server,用来作为数据的采集存储、数据分析与展示;zipkin client是zipkin基于不同的语言及框架封装的一些列客户端工具,这些工具完成了追踪数据的生成与上报功能,架构如下:
实现流程
1、下载:
下载地址:https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec
2、运行:java -jar zipkin-server-2.8.3-exec.jar
3、访问:zipkin Server 运行后默认的访问地址:http://localhost:9411
4、调用链分析
启动4个服务,调用关系如下:brave-webmvc-example服务调用brave-webmvc-example2,brave-webmvc-example2分别调用brave-webmvc-example3和brave-webmvc-example4(代码地址),链路关系如下图:
要看清数据结构,首先要清楚数据结构的意思,看下图:
右上角JSON节目可以看到4个服务的调用数据如下图:
[
{
"traceId": "a4aa11d855699355",
"id": "a4aa11d855699355",
"name": "get /start",
"timestamp": 1526110753393795,
"duration": 3873359,
"annotations": [
{
"timestamp": 1526110753393795,
"value": "sr",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110757267154,
"value": "ss",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
}
],
"binaryAnnotations": [
{
"key": "ca",
"value": true,
"endpoint": {
"serviceName": "",
"ipv6": "::1",
"port": 64570
}
},
{
"key": "http.method",
"value": "GET",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.path",
"value": "/start",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.class",
"value": "HomeController",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.method",
"value": "start",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
}
]
},
{
"traceId": "a4aa11d855699355",
"id": "cf49951d471ac7c5",
"name": "get /foo",
"parentId": "a4aa11d855699355",
"timestamp": 1526110753583404,
"duration": 3650640,
"annotations": [
{
"timestamp": 1526110753583404,
"value": "cs",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110754327066,
"value": "sr",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110757234044,
"value": "cr",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110757235819,
"value": "ss",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
}
],
"binaryAnnotations": [
{
"key": "ca",
"value": true,
"endpoint": {
"serviceName": "",
"ipv4": "127.0.0.1",
"port": 64578
}
},
{
"key": "http.method",
"value": "GET",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.method",
"value": "GET",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.path",
"value": "/foo",
"endpoint": {
"serviceName": "brave-webmvc-example",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.path",
"value": "/foo",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.class",
"value": "HomeController",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.method",
"value": "foo",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
}
]
},
{
"traceId": "a4aa11d855699355",
"id": "c2c029d693ecc49b",
"name": "get /bar",
"parentId": "cf49951d471ac7c5",
"timestamp": 1526110754397322,
"duration": 1583187,
"annotations": [
{
"timestamp": 1526110754397322,
"value": "cs",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110755367168,
"value": "sr",
"endpoint": {
"serviceName": "brave-webmvc-example3",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110755810759,
"value": "ss",
"endpoint": {
"serviceName": "brave-webmvc-example3",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110755980509,
"value": "cr",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
}
],
"binaryAnnotations": [
{
"key": "ca",
"value": true,
"endpoint": {
"serviceName": "",
"ipv4": "127.0.0.1",
"port": 64583
}
},
{
"key": "http.method",
"value": "GET",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.method",
"value": "GET",
"endpoint": {
"serviceName": "brave-webmvc-example3",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.path",
"value": "/bar",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.path",
"value": "/bar",
"endpoint": {
"serviceName": "brave-webmvc-example3",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.class",
"value": "HomeController",
"endpoint": {
"serviceName": "brave-webmvc-example3",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.method",
"value": "bar",
"endpoint": {
"serviceName": "brave-webmvc-example3",
"ipv4": "192.168.1.101"
}
}
]
},
{
"traceId": "a4aa11d855699355",
"id": "e3968cec8747ce95",
"name": "get /tar",
"parentId": "cf49951d471ac7c5",
"timestamp": 1526110756017988,
"duration": 1194871,
"annotations": [
{
"timestamp": 1526110756017988,
"value": "cs",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110757081683,
"value": "sr",
"endpoint": {
"serviceName": "brave-webmvc-example4",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110757212859,
"value": "cr",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"timestamp": 1526110757222145,
"value": "ss",
"endpoint": {
"serviceName": "brave-webmvc-example4",
"ipv4": "192.168.1.101"
}
}
],
"binaryAnnotations": [
{
"key": "ca",
"value": true,
"endpoint": {
"serviceName": "",
"ipv4": "127.0.0.1",
"port": 64584
}
},
{
"key": "http.method",
"value": "GET",
"endpoint": {
"serviceName": "brave-webmvc-example4",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.method",
"value": "GET",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.path",
"value": "/tar",
"endpoint": {
"serviceName": "brave-webmvc-example4",
"ipv4": "192.168.1.101"
}
},
{
"key": "http.path",
"value": "/tar",
"endpoint": {
"serviceName": "brave-webmvc-example2",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.class",
"value": "HomeController",
"endpoint": {
"serviceName": "brave-webmvc-example4",
"ipv4": "192.168.1.101"
}
},
{
"key": "mvc.controller.method",
"value": "tar",
"endpoint": {
"serviceName": "brave-webmvc-example4",
"ipv4": "192.168.1.101"
}
}
]
}
]