【SpringCloud】06 Link tracking Sleuth+zipkin

link tracing

In the microservice construction of large systems, a system is split into many microservices. These modules are responsible for different functions and are combined into a system that can ultimately provide rich functionality. In this architecture, onceRequests often involve multiple services. Internet applications are built on different sets of software modules. These software modules may be developed by different teams, implemented using different programming languages, and may be distributed on thousands of servers across multiple different data The center [area] means that there will also be some problems with this architectural form:

l How to quickly find problems?

l How to determine the scope of fault impact?

l How to sort out service dependencies and the rationality of dependencies?

l How to analyze link performance issues and real-time capacity planning?

Insert image description here

Locate the fault of the request: which microservice it occurred on.

Concept: ----》Install a GPS on each microservice node. ----In the program----Log. We can locate the response errors by looking at the logs.

Collection-----displayed into a unified interface.

The first one is to help you generate log records on each microservice.

The second technology is to collect these logs and display them on a graphical interface.

1. Sleuth

Its role is to generate logging records for microservices.

Trace (the complete link of a request – including many spans (microservice interface))
A group of Spans with the same Trace ID (throughout the entire link) are connected in series to form a tree structure. In order to implement request tracking, when a request reaches the entry endpoint of the distributed system, the service tracking framework only needs to create a unique identifier (i.e. TraceId) for the request. At the same time, when flowing within the distributed system, the framework always keeps passing the unique identifier. value until the entire request is returned. Then we can use this unique identifier to connect all requests together to form a complete request link.
Span
Represents a basic set of work units. In order to count the delay of each processing unit, when a request reaches each service component, its start, specific process and end are also marked with a unique identifier (SpanId). Through the start and end timestamps of SpanId, we can count the calling time of the span. In addition, we can also obtain the name of the event. Request information and other metadata.
Annotation
Use it to record events over a period of time. Important notes for internal use:
l cs (Client Send) The client sends a request to start a request
l sr (Server Received) The server receives the request and starts processing it, sr-cs = 网络延迟(服务调用的时间)
l ss (Server Send) The server has completed processing and is ready to be sent to the client. ss - sr = 服务器上的请求处理时间
l cr (Client Reveived) The client receives the response from the server and the request ends. cr - cs = 请求的总时间

Insert image description here

1.1 How to use sleuth

Introduce sleuth dependency into microservices—in the entire parent project
so that all microservices will have the sleuth package

<!--引入sleuth依赖-->
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
</dependencies>

Insert image description here
The response time of the entire request link of the browser
Insert image description here
is more than 500 milliseconds. Which server failed. You can view the logs generated by sleuth and calculate the timestamp yourself. This solution is very troublesome.

We collect the logs generated by sleuth through zipkin and display them graphically.

2. zipkin

Function: Collect logs generated by sleuth on microservices and display them to customers in a graphical mode.

zipkin has server [server] and client [microservice]
Insert image description here

2.1 Run zipkin server

java -jar zipkin-server-2.12.9-exec.jar

Insert image description here


Insert image description here


Microservice access zipkin

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

Connect zipkin to the corresponding microservice
Insert image description here


Insert image description here
Use configuration—do configuration management of microservices

sleuth+zipkin completes link tracking—location error

Guess you like

Origin blog.csdn.net/qq_60969145/article/details/128050195