I. Introduction of Zipkin
Zipkin is an open source project for Twitter, based on Google Dapper. We can use it to collect trace data from the request link on each server, and through the rest API interface it provides to help us query the tracking data to implement the monitoring program of the distributed system, so as to detect the delay rising problem in the system and find out the root of the system performance bottleneck. In addition to the development-oriented API interface, it also provides a handy UI component to help us intuitively search for tracking information and analyze request link details, such as: You can query the processing time of each user request in a certain period of time.
Demonstrates the Zipkin infrastructure, which consists of 4 core components:
- Collector: Collector component, which is primarily used to process trace information sent from an external system and translates this information into a zipkin internal processing span format to support subsequent storage, analysis, and presentation functions.
- Storage: A storage component that primarily handles the trace information received by the collector, which is stored in memory by default, and we can modify this storage policy to store trace information in the database by using other storage components.
- RESTful API: API component, which is used primarily to provide external access interfaces. For example, to show the client tracking information, or external system access to implement monitoring.
- Web UI: A UI component, an upper-level application based on API component implementations. Users of UI components can easily and intuitively query and analyze trace information.
Ii. Basic integration of sleuth and Zipkin
First step: Build Zipkin Server
1. Create a basic spring boot application, named zipkin-server
, and pom.xml
introduce the dependent dependencies of Zipkin server in, as follows:
<Dependency> <groupId>Io.zipkin.java</groupId> <Artifactid>Zipkin-server</Artifactid></Dependency><Dependency> <groupId>Io.zipkin.java</groupId> <Artifactid>Zipkin-autoconfigure-ui</Artifactid></Dependency>
2. Create the application main class ZipkinApplication
and @EnableZipkinServer
use annotations to start Zipkin Server, as follows:
@EnableZipkinServer@SpringBootApplicationpublicclass zipkinapplication { Public Static void Main (string[] args) { springapplication.run (zipkinapplication. class , args);} }
3. Add configuration information:
application.properties
do some simple configuration in, such as: Set the service port number is 9411
(client integration, the automation configuration will connect the 9411
port, so the server set the port 9411
, the client can save this configuration).
spring.application.name=zipkin-serverserver.port=9411
4. Access http://localhost:9411/
, we can see the Zipkin Management page as shown:
Step two: Introduce and configure Zipkin services for your application
After the Zipkin server is built, we also need to configure the application to output trace information to Zipkin server. For trace-1
trace-2
example, we have made the following modifications to them:
1. trace-1
trace-2
pom.xml
Introduction spring-cloud-sleuth-zipkin
of dependencies in and, as shown below. (Spring-cloud-starter-zipkin)
< dependency > < groupid > org.springframework.cloud</ Span style= "COLOR: #800000" >groupid > < artifactid > Spring-cloud-sleuth-zipkin</ artifactid > </ dependency >
2. trace-1
increase the trace-2
application.properties
configuration information for Zipkin server in and, as shown below (if in the zip-server
application, we set its port to 9411
, and both are locally debugged, this parameter can also be not configured, Because the default value is http://localhost:9411
).
spring.zipkin.base-url=http://localhost:9411
Testing and analysis
Here we have done all the basic work of accessing Zipkin server, we can continue to eureka-server
, trace-1
and trace-2
start up, and then we do some test experiments to have some preliminary understanding of its operating mechanism.
We first trace-1
send several requests to http://localhost:9101/trace-1
the interface: When we have the last value true
of trace information in the log, the trace information is output to Zipkin Server. So at this point we can go to Zipkin Server Management page to select the appropriate query criteria, Find Traces
Click, you can query the log has just appeared in the trace information (also can be based on the log of the Trace ID, In the top right-hand corner of the page, search in the box, as shown in the following page:
By clicking on trace-1
the tracking information at the bottom end, we can also get the tracking details collected by sleuth, which includes the time consuming of requests we are concerned about.
By clicking on the menu Dependencies
in the navigation bar, we can also view the System request link dependency graph generated by Zipkin server based on the trace information analysis:
Transferred from: http://blog.didispace.com/spring-cloud-starter-dalston-8-4/
12, Springcloud display tracking data Sleuth+zipkin