3_spring Cloud Technical Analysis-Spring cloud Sleuth

Source: Internet
Author: User
3_spring Cloud Technical Analysis-Spring cloud Sleuth More Dry goodsDistributed Combat (dry) Spring Cloud Combat (dry) MyBatis Combat (dry) Spring boot Combat (dry) React Get started Combat (dry) build small and medium-sized Internet Enterprise Architecture (dry) Python Learning continuous update Elasticsearc H notes

Pring Cloud Sleuth is implemented from the idea of Google's dapper paper, providing link tracking for the Spring Cloud series. This article starts with the use of spring cloud sleuth. One, the purpose of providing link tracking. By sleuth It is clear what service a request has been through. It is convenient to clarify the call relationship between services. Visual error. For exceptions that are not caught by the program, you can see them on the Zipkin interface. Analysis time-consuming. It is easy to see the time-consuming of each sampling request through sleuth, and to analyze which service calls are time-consuming. When the time-consuming of service invocation increases with the increase of the request volume, it can also provide some reminders for the service's expansion. Optimize the link. For frequent calls to a service, or parallel calls, and so on, you can do some optimization measures for the business. ii. Application integration Spring Cloud Sleuth

Spring Cloud Sleuth can combine Zipkin to send information to Zipkin, use Zipkin storage to store information, and use the Zipkin UI to present data. It is also possible to simply record the data in the log. 1. Use only Sleuth+log configuration

MAVEN Configuration

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId> spring-cloud-dependencies</artifactid>
	<version>Camden.SR6</version>
	<type>pom </type>
	<scope>import</scope>
</dependency>
<dependency>
	< Groupid>org.springframework.cloud</groupid>
	<artifactid>spring-cloud-starter-sleuth</ Artifactid>
</dependency>

In this way, only the jar package can be introduced. If you configure log4j, this will print out the following log

2017-04-08 23:56:50.459 INFO [Bootstrap,38d6049ff0686023,d1b8b0352d3f6fa9,false] 8764-[nio-8080-exec-1] Demo. Jpasingledatasourceapplication:step 2:handling print
2017-04-08 23:56:50.459 INFO [bootstrap,38d6049ff0686023, D1b8b0352d3f6fa9,false] 8764-[nio-8080-exec-1] Demo. Jpasingledatasourceapplication:step 1:handling Home

[Bootstrap,38d6049ff0686023,d1b8b0352d3f6fa9,false] is more than the original log, [appname,traceid,spanid,exportable]. AppName: Service Name Traceid\spanid: Two terms for link tracking, followed by exportable: whether it is sent to Zipkin 2, Sleuth+zipkin+http

The size of the Blockingqueue sleuth wrote dead for 1000. When the queue is full, the sleuth just adds a record-handling. 2.1 Application Configuration

Maven Introduction

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId> spring-cloud-dependencies</artifactid>
	<version>Camden.SR6</version>
	<type>pom </type>
	<scope>import</scope>
</dependency>
<dependency>
	< Groupid>org.springframework.cloud</groupid>
	<artifactid>spring-cloud-starter-sleuth</ artifactid>
</dependency>
<dependency>
	<groupid>org.springframework.cloud </groupId>
	<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency >

Configuration file Configuration

spring.sleuth.sampler.percentage=0.1  Sample Rate 
spring.zipkin.baseurl=http://zipkin.xxx.com The URL sent to Zipkinserver
spring.zipkin.enabled=true
2.2 Zipkin

Maven Introduction

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId> spring-cloud-starter-sleuth</artifactid> </dependency> <dependency> <groupId> Org.springframework.cloud</groupid> <artifactId>spring-cloud-starter-zipkin</artifactId> </ dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactid>spri ng-cloud-stream-binder-kafka</artifactid> </dependency> <dependency> <groupId> Org.springframework.cloud</groupid> <artifactid>spring-cloud-sleuth-zipkin-stream</artifactid > </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactid>zipkin -autoconfigure-ui</artifactid> <!--<version>1.40.2</version>--> </dependency>

Spring Boot Program

@SpringBootApplication (exclude = sleuthstreamautoconfiguration.class)
@EnableZipkinServer public
class Sleuthserverapplication
{public
	static void Main (string[] args)
	{
		Springapplication.run ( Sleuthserverapplication.class, args);
	}
}

Storage configuration

Zipkin's storage includes MySQL, ES, and Cassadra. If you do not configure storage, the default is in memory. If in memory, the data is lost when the app is restarted.

MySQL Storage

Spring:
  application:
    name:sleuth-zipkin-http
  DataSource:
    schema:classpath:/mysql.sql
    URL: Jdbc:mysql://192.168.3.3:2222/zipkin
    driverClassName:com.mysql.jdbc.Driver
    username:app
    Password:% jdbc-1.password%
    # Switch This in to create the schema on startup:
    initialize:true
    Continueonerror:true
  sleuth:
    enabled:false

# Default is mem (in-memory)
Zipkin:
	storage:
	   type:mysql

The MySQL script is already available in the Zipkin package, and only needs to be executed.

ES storage

Zipkin:
  storage:
    type:elasticsearch
    elasticsearch:
      cluster: ${es_cluster:elasticsearch}
      Hosts: ${es_hosts:localhost:9300}
      index: ${es_index:zipkin}
      index-shards: ${es_index_shards:5}
      Index-replicas: ${es_index_replicas:1}
3, Sletuh+streaming+zipkin

This way, tracing information is sent to Zipkin via spring cloud streaming. Spring Cloud streaming currently has only Kafka and RABBITMQ binders. Take Kafka as an example:

Collector is the class name of the source code. The collector reads data from the message middleware and stores it in the DB and Es. 3.1. Application Configuration

Maven Introduction

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId> Spring-cloud-dependencies</artifactid> <version>Camden.SR6</version> <type>pom</type > <scope>import</scope> </dependency> <dependency> <groupId> Org.springframework.cloud</groupid> <artifactId>spring-cloud-sleuth-stream</artifactId> </ dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId> spring-cloud-starter-sleuth</artifactid> </dependency> <dependency> <groupId>
Org.springframework.cloud</groupid> <artifactId>spring-cloud-stream-binder-kafka</artifactId> </dependency> 
3.2, Zipkin

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.