Micro Services SpringCloud of zipkin link track (turn)

As business grows, leading to increasingly complex system to split a front-end system call link request may eventually need to call many times to complete the back-end service, when the entire request slow or unavailable, we can not know that the request is authorized by a or due to some back-end services, then we need to figure out how to read fast positioning service point of failure to remedy. Then there is the birth of a distributed system call tracking.

Spring Cloud Sleuth

In general, a distributed service tracking system, has three main parts: data collection, data storage and data display. Depending on the size of the system, each structural part has a certain variation. For example, for large-scale distributed systems, data storage, real-time data can be divided into two parts and the whole amount of data, real-time data for troubleshooting (troubleshooting), the full amount of data for system optimization; data collection in addition to supporting the development of platform-independent and language-independent system data collection, further comprising asynchronous data collection (need to track messages in the queue, ensure the continuity of the call), and ensuring less invasive; display data also involves data mining and analysis. Although each part can become very complex, but the basic principles are similar.

 

Tracking unit tracking service from the client initiates a request (request) was arrived at the border began tracking system, the tracking system to process until a response is returned (response) to the client, called a "trace". Each trace in the number of service calls, record calls for what services, as well as time-consuming and so each call information at each service call, buried in a call record, called a "span". In this way, a number of orderly span on the formation of a trace. In the process of the system providing service to the outside world, we will continue to have the request and response occurs, will continue to generate a trace, with a span of these trace record, can depict a service system topology. Comes the response time span, as well as the success of the request and other information, can be in the event of problems, to find unusual services; based on historical data, but also analyze where poor performance, optimize positioning performance goals from the overall system level .

Spring Cloud Sleuth provides a link between the service call tracking. By Sleuth can clearly understand what a service request through the service, each service takes a long process. So that we can easily clarify the relationships among micro-calling service. In addition Sleuth can help us:

Time-consuming analysis: it can be easily learned by Sleuth takes each sample requested to analyze the service call which is time-consuming;
visualization Error: uncaught exception for the program, you can see through the integration Zipkin service interface;
link optimization: call for more frequent service, we can implement some optimization measures for these services.
Zipkin spring cloud sleuth may bind, to send information to Zipkin, using the memory to store information Zipkin utilizing zipkin ui to display data.

test

1. Start zipkin server

Because it is pure blog http://www.ityouknow.com/springcloud/2018/02/02/spring-cloud-sleuth-zipkin.html reference to smile, but when prompted me to create zipkin-server project introduced notes @EnableZipkinServer can not be used. Recommend using the default zipkin jar package, you can view the specific use github documentation. Here under the Download jar, and then use the stored memory, java -jar zipkin-server-2.17.0-exec.jar.

Copy the code
/**
 * @deprecated Custom servers are possible, but not supported by the community. Please use our
 * <a href="https://github.com/openzipkin/zipkin#quick-start">default server build</a> first. If you
 * find something missing, please <a href="https://gitter.im/openzipkin/zipkin">gitter</a> us about
 * it before making a custom server.
 *
 * <p>If you decide to make a custom server, you accept responsibility for troubleshooting your
 * build or configuration problems, even if such problems are a reaction to a change made by the
 * OpenZipkin maintainers. In other words, custom servers are possible, but not supported.
 */
Copy the code

2. The project to add support zipkin

In SpringColudZuulSimple, EurekaClient introduced dependent spring-cloud-starter-zipkin.

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

Then set the properties application.properties

spring.zipkin.base-url=http://localhost:9411
spring.sleuth.sampler.probability=1.0

spring.zipkin.base-url Zipkin specified address server, spring.sleuth.sampler.percentage sampling ratio is set to 1.0, all that is required.
Spring Cloud Sleuth Sampler have a strategy that can be controlled by this sampling algorithm implementation class. Sampler will not hinder generate related span id, but the impact will export related operations and additional event tag. The default sampling algorithm implemented Sleuth is Reservoir sampling, a specific category is PercentageBasedSampler, the default sampling ratio: 0.1 (i.e., 10%). However, we can be set by spring.sleuth.sampler.percentage, the set value is between 0.0 and 1.0, 1.0 represents a full acquisition.

3. Verify

In turn starts EurekaServer, EurekaClient, SpringColudZuulSimple, and then enter in the browser HTTP: // localhost:? 8890 / the Spring-Cloud-Producer / cuiyw the Hello name = & token = 123 , refresh a few times, and then at http: // localhost: 9411 page click the query, you can see the following information.

 

 

 Click on each record can see specific information and time-consuming sequence of each.

Click dependency analysis, we can see the relationship between the project calls

 

 

 

 to sum up

Memory way here used to store data, production environments typically use the message queue RabbitMQ, Kafka or mysql database storage, specific use of official documents can be viewed zipkin.

 Reference: http: //www.ityouknow.com/springcloud/2018/02/02/spring-cloud-sleuth-zipkin.html

Guess you like

Origin www.cnblogs.com/sunshijia1993/p/11593131.html