29th Chapter Springboot + Zipkin + mysql

Source: Internet
Author: User
Tags cassandra

Zipkin data storage can exist in 4 places:

    • Memory (for testing only, data is not persisted, Zipkin-server is turned off, data is gone)
      • This is also the previous use of
    • Mysql
      • Probably the most familiar way.
    • Es
    • Cassandra

First, code (based on the 28th Chapter Springboot + Zipkin (Brave custom-asynchttpclient))

1, Pom.xml

1         <Dependency>2             <groupId>Io.zipkin.brave</groupId>3             <Artifactid>Brave-mysql</Artifactid>4             <version>3.9.0</version>5         </Dependency>

2, Zipkinconfig Add the following

1     @Bean 2      Public Mysqlstatementinterceptormanagementbean Mysqlstatementinterceptormanagementbean (Brave Brave) {3          returnnew  Mysqlstatementinterceptormanagementbean (Brave.clienttracer ()); 4     }

Second, the database

1. Build the Library

    • Create your own library (EG.MYTESTDB) just fine

2. Build a table

    • Execute Zipkin prepared script Mysql.sql in Mytestdb to create three tables and individual indexes.

Mysql.sql Location: Https://github.com/openzipkin/zipkin/blob/master/zipkin-storage/mysql/src/main/resources/mysql.sql

Or simply clone the entire Zipkin project and go inside to see the content.

Mysql.sql content is as follows:

1 CREATE TABLE IF  not EXISTSZipkin_spans (2' trace_id 'BIGINT  not NULL,3' ID 'BIGINT  not NULL,4' Name 'VARCHAR(255) not NULL,5' parent_id 'BIGINT,6' Debug 'BIT(1),7' Start_ts 'BIGINTCOMMENT'Span.timestamp (): Epoch Micros used for Endts query and to implement TTL',8' Duration 'BIGINTCOMMENT'span.duration (): Micros used for minduration and maxduration query'9) ENGINE=InnoDB Row_format=compressed;Ten  One ALTER TABLEZipkin_spansADD UNIQUE KEY(' trace_id ', ' id ') COMMENT'Ignore insert on duplicate'; A ALTER TABLEZipkin_spansADD INDEX(' trace_id ', ' id ') COMMENT'For joining with Zipkin_annotations'; - ALTER TABLEZipkin_spansADD INDEX(' trace_id ') COMMENT'For Gettracesbyids'; - ALTER TABLEZipkin_spansADD INDEX(' name ') COMMENT'For gettraces and Getspannames'; the ALTER TABLEZipkin_spansADD INDEX(' Start_ts ') COMMENT'For gettraces ordering and range'; -  - CREATE TABLE IF  not EXISTSZipkin_annotations ( -' trace_id 'BIGINT  not NULLCOMMENT'coincides with zipkin_spans.trace_id', +' span_id 'BIGINT  not NULLCOMMENT'coincides with Zipkin_spans.id', -' A_key 'VARCHAR(255) not NULLCOMMENT'Binaryannotation.key or annotation.value if type = =-1', +' A_value ' BLOB COMMENT'Binaryannotation.value (), which must be smaller than 64KB', A' A_type 'INT  not NULLCOMMENT'Binaryannotation.type () or-1 if Annotation', at' A_timestamp 'BIGINTCOMMENT'used to implement TTL; Annotation.timestamp or Zipkin_spans.timestamp', -' Endpoint_ipv4 'INTCOMMENT'NULL when binary/annotation.endpoint is null', -' Endpoint_ipv6 'BINARY( -) COMMENT'NULL when Binary/annotation.endpoint is Null, or no IPv6 address', -' Endpoint_port 'SMALLINTCOMMENT'NULL when binary/annotation.endpoint is null', -' Endpoint_service_name 'VARCHAR(255) COMMENT'NULL when binary/annotation.endpoint is null' -) ENGINE=InnoDB Row_format=compressed; in  - ALTER TABLEZipkin_annotationsADD UNIQUE KEY(' trace_id ', ' span_id ', ' a_key ', ' A_timestamp ') COMMENT'Ignore Insert on duplicate'; to ALTER TABLEZipkin_annotationsADD INDEX(' trace_id ', ' span_id ') COMMENT'For joining with Zipkin_spans'; + ALTER TABLEZipkin_annotationsADD INDEX(' trace_id ') COMMENT'For Gettraces/byids'; - ALTER TABLEZipkin_annotationsADD INDEX(' Endpoint_service_name ') COMMENT'For gettraces and Getservicenames'; the ALTER TABLEZipkin_annotationsADD INDEX(' A_type ') COMMENT'For gettraces'; * ALTER TABLEZipkin_annotationsADD INDEX(' A_key ') COMMENT'For gettraces'; $ Panax Notoginseng CREATE TABLE IF  not EXISTSZipkin_dependencies ( -` Day' DATE not NULL, the' Parent 'VARCHAR(255) not NULL, +' Child 'VARCHAR(255) not NULL, A' Call_count 'BIGINT the) ENGINE=InnoDB Row_format=compressed; +  - ALTER TABLEZipkin_dependenciesADD UNIQUE KEY(` Day', ' parent ', ' child ');
View Code

After executing the script, the database appears with three tables, as follows:

Third, start the command

    • Storage_type=mysql mysql_host=192.192.192.192 mysql_tcp_port=3306 mysql_db=mytestdb MYSQL_USER=root MYSQL_PASS= 123456 nohup Java-jar Zipkin-server-1.5.1-exec.jar &
      • Storage_type: Storage type, this is MySQL
      • Mysql_host and Mysql_tcp_port: Creating connection
      • Mysql_user and Mysql_pass: User name and password

Iv. Testing

Start 4 service, then swagger the test, and finally view the Zipkin and database tables.

Reference:

    • Https://github.com/openzipkin/zipkin/tree/master/zipkin-server: There are various configuration options for storing to MySQL, Cassandra, ES, and related startup commands.
    • Https://github.com/openzipkin/zipkin/tree/master/zipkin-storage/mysql: There is Zipkin source for MySQL storage.

29th Chapter Springboot + Zipkin + mysql

Related Article

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.