Springcloud Study of Sleuth&zipkin "two"

Source: Internet
Author: User

In this article we retrofit and upgrade the legacy of the previous link tracking

First, the tracking data stored in the MySQL database

By default Zipkin stores the collected data in memory (In-memeroy), but inevitably brings a few problems:

      • After the service restarts, the historical data is lost.
      • Prone to oom errors when data volumes are too large

This is usually done in conjunction with MySQL or Elasticsearch, so we first store the collected data in the MySQL database

1, the transformation of zipkin-server dependence

Gradle configuration:

Dependencies {compile (' Org.springframework.cloud:spring-cloud-starter-eureka ') Compile (' Org.springframework.cloud:spring-cloud-starter-config ')  //compile (' io.zipkin.java:zipkin-server ')Compile' Org.springframework.cloud:spring-cloud-starter-sleuth 'Compile (' Io.zipkin.java:zipkin-autoconfigure-ui ') Runtime (' Mysql:mysql-connector-java ') Compile (' Org.springframework.boot:spring-boot-starter-jdbc ') Compile (' Org.springframework.cloud:spring-cloud-sleuth-zipkin-stream ') Compile (' Org.springframework.cloud:spring-cloud-stream ') Compile (' Org.springframework.cloud:spring-cloud-stream-binder-kafka ')}
View Code

This replaces the original io.zipkin.java:zipkin-server with Spring-cloud-sleuth-zipkin-stream, which contains support for MySQL storage. Add spring-boot-starter-jdbc and MySQL dependencies at the same time, plus Kafka support.

    

    Note: It is best to execute the script here in the database, and of course we can initialize the configuration in the following configuration file.

2. Key configuration items in Yaml:
Spring:  DataSource:    username:root    password:root    url:jdbc:mysql://  Localhost:3306/myschool?characterencoding=utf-8&usessl=false    true    continue  true  Kafka:    bootstrap-servers:localhost:9092server:  9000 Zipkin:  storage:    type:mysql
View Code

Pay attention to Zipkin.storage. type specified as MySQL

3. Change the Startup class
 PackageCom.hzgj.lyrk.zipkin.server;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;Importorg.springframework.cloud.sleuth.zipkin.stream.enablezipkinstreamserver;@ Enablezipkinstreamserver@springbootapplication Public classzipkinserverapplication { Public Static voidMain (string[] args) {Springapplication.run (zipkinserverapplication.class, args); }}
View Code

Notice here to change @enablezipkinserver to @enablezipkinstreamserver.

Second, change trace to asynchronous message

This step is mainly used to improve performance and stability, the service will be collected in the span of the message middleware to lose the Zipkin, without the control of the address where.

1, Transformation order-server dependence:

Gradle

 compile (' org.springframework.cloud:spring-cloud-starter-eureka-server ' )  //  compile (' Org.springframework.cloud : Spring-cloud-sleuth-zipkin ')  compile ' org.springframework.cloud:spring-cloud-starter-sleuth '  compile ( span> ' org.springframework.cloud:spring-cloud-starter-config ' ) compile ( ' Org.springframework.cloud:spring-cloud-stream ' ) compile ( ' Org.springframework.cloud:spring-cloud-stream-binder-kafka ' ) compile ( ' Org.springframework.kafka:spring-kafka ' ) compile ( ' Org.springframework.cloud:spring-cloud-starter-bus-kafka ') 
View Code

Here to change the original Spring-cloud-sleuth-zipkin to Spring-cloud-sleuth-stream, do not guess the inside must be based on spring-cloud-stream implementation

2. Yaml Key Attribute configuration:
Server:   8100Logging: level  :    org.springframework.cloud.sleuth:DEBUGspring:  Sleuth:    Sampler:      1.0
View Code

Note: Setting a low sample rate here will result in the drop of span. We also set the Sleuth log output to debug

3, the same transformation of other micro-services

  

Iii. Results of verification

Relevant data in the database:

Springcloud Study of Sleuth&zipkin "two"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.