zipkin源碼 1.簡介

簡介

zipkin是分佈式跟蹤系統,在微服務架構中,它能夠獲取實時的數據幫助解決請求延遲問題。zipkin收集並展現調用鏈數據。zipkin是基於谷歌的Dapper系統設計的。 image架構

zipkin架構

image

首先在app使用zipkin的客戶端,收集server,client(後面會講)的調用關係數據,經過reporter上傳到Collector,而後Collector經過Storage進行存儲,最後UI展現調用鏈信息。app

zipkin的基本概念

span

基本工做單元,一次鏈路調用建立一個span,能夠是httpclient,db調用。span經過parentSpanId進行關聯分佈式

trace

表明一個完整的請求,期間可能橫跨多個服務,用惟一標識。tace是多個span的集合。微服務

Annotation

Annotation是span的tag集合。它主要有5種類型:url

cs - Client Start,表示客戶端發起請求

sr - Server Receive,表示服務端收到請求

ss - Server Send,表示服務端完成處理,並將結果發送給客戶端

cr - Client Received,表示客戶端獲取到服務端返回信息

lc - local component,表示本地span,不能跨進程,好比一次file io操做

BinaryAnnotation

能夠在此tag種添加業務信息spa

完整的報文

[
  {
    "traceId": "a0e07d61b5f6060a",
    "id": "a0e07d61b5f6060a",
    "name": "get",
    "timestamp": 1479457971341000,
    "duration": 3872769,
    "annotations": [
      {
        "timestamp": 1479457971341000,
        "value": "sr",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      },
      {
        "timestamp": 1479457975213769,
        "value": "ss",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      }
    ],
    "binaryAnnotations": [
      {
        "key": "exception",
        "value": "asdas",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      },
      {
        "key": "http.status_code",
        "value": "200",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      },
      {
        "key": "http.url",
        "value": "/start",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      }
    ]
  },
  {
    "traceId": "a0e07d61b5f6060a",
    "id": "3be8fed4e9846694",
    "name": "get",
    "parentId": "a0e07d61b5f6060a",
    "timestamp": 1479457971444000,
    "duration": 41291,
    "annotations": [
      {
        "timestamp": 1479457971444000,
        "value": "cs",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      },
      {
        "timestamp": 1479457971485291,
        "value": "cr",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      }
    ],
    "binaryAnnotations": [
      {
        "key": "http.url",
        "value": "http://www.baidu.com/",
        "endpoint": {
          "serviceName": "service1",
          "ipv4": "172.16.8.79"
        }
      }
    ]
  }
]
相關文章
相關標籤/搜索