码迷,mamicode.com
首页 > 编程语言 > 详细

Distributed traceability with Spring Cloud: Sleuth and Zipkin

时间:2018-12-02 10:30:55      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:Once   alt   sed   under   str   ror   learning   zip   error   

 

I. Sleuth

0. Concept

  • Trace
      A set of spans that form a call tree structure, forms the trace of the request.
  • Span
      It is the basic unit of work, for example a call to a service. They are identified with a span ID and a trace ID to which span is owned. They have start and end, and with it you get track the response time between requests.
  • Tag
      Key/value pair that identifies certain information in the span. It doesn‘t contain timestamps, it just identifies.

 

Annotation: Used to record the existence of an event in time. With Brave instrumentation, we no longer need to set special events for Zipkin to understand who the client and server are, where the request started, and where it ended. For learning purposes, however, we mark these events to highlight what kind of an action took place.

  • cs: Client Sent. The client has made a request. This annotation indicates the start of the span.
  • sr: Server Received: The server side got the request and started processing it. Subtracting the cs timestamp from this timestamp reveals the network latency.
  • ss: Server Sent. Annotated upon completion of request processing (when the response got sent back to the client). Subtracting the sr timestamp from this timestamp reveals the time needed by the server side to process the request.
  • cr: Client Received. Signifies the end of the span. The client has successfully received the response from the server side. Subtracting the cs timestamp from this timestamp reveals the whole time needed by the client to receive the response from the server.

 技术分享图片

 

 

 1. pom

 

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>

 

 

2. config

    1) sampler

---
spring:
  sleuth:
    sampler: 
      probability: 1.0

 

 

II. zipkin

0. way

    1) http

技术分享图片

    2) Messaging Brokers

技术分享图片

 0. zipkin client

 

1) pom

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>

 

 

2) config

   (1) base url

---
spring:
  zipkin:
    base-url: http://localhost:9411

 

  (2) sender

      A. RabbitMQ
---
spring:
  zipkin:
    sender:
      type: RABBIT

 

      B. Kafka
---
spring:
  zipkin:
    sender:
      type: KAFKA

 

      C. Web

          default

 

 

1. zipkin server

    upgrade to Spring Boot 2.0 NoClassDefFoundError UndertowEmbeddedServletContainerFactory

 

1) down

    https://mvnrepository.com/artifact/io.zipkin.java/zipkin-server

    v2.11.8

 

2) run

 

III. MQ

1. RabbatMQ

     0) pom

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
        </dependency>

 

 

    1) config

---
spring:
  rabbitmq:
    addresses: 192.168.1.115
    port: 15672
    username: admin
    password: admin
    virtual-host: sleuth

 

 

 

2. Kafka

    0) pom

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-kafka</artifactId>
        </dependency>

 

    1) config

spring:
  kafka:
    bootstrap-servers:
      - 192.168.1.186:9092
      - 192.168.1.187:9092
      - 192.168.1.188:9092

 

 

Reference:

   1. Trazabilidad Distribuida con Spring Cloud: Sleuth y Zipkin

 

Distributed traceability with Spring Cloud: Sleuth and Zipkin

标签:Once   alt   sed   under   str   ror   learning   zip   error   

原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/10052026.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!