SpringCloud使用zipkin实现链路追踪入门

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"
        }
      }
    ]
  }
]

zipkin高端代码链接

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bst@微胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值