Service Link Tracking
background
Micro-service is famous for its micro-service. In the actual development process, it involves hundreds of thousands of services. The invocation of services caused by network requests is extremely complex.
When requests are unavailable or slow down, the need to find out the fault service point in time has become a major difficulty in micro-service maintenance.
Service link tracking technology emerges as the times require.
ZipKin
Zipkin is an open source distributed tracking system, which is open source by Twitter. It is dedicated to collecting service timing data to solve the delay problem in the micro-service architecture, including data collection, storage, search and display.
Each service reports timing data to zipkin. Zipkin generates dependency graph through Zipkin UI according to the invocation relationship, showing how many tracking requests pass through each service. The system allows developers to collect and analyze data easily through a Web front-end, such as the processing time of each user's request for service, which is convenient. The bottleneck in the monitoring system.
Zipkin provides pluggable data storage: In-Memory, MySql, Cassandra and Elastic search. Next, in order to facilitate direct storage in-Memory mode, Elastic search is recommended for production.
quick get start
Modify the Zuul cluster code: https://github.com/HCJ-shadow/Zuul-Gateway-Cluster-Nginx
Create zipkin-server
pom[zipkin]
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR2</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!-- Eureka Client startup needs dependency web Modular--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
- yaml
eureka: client: serviceUrl: defaultZone: http://eureka2001.com:2001/eureka/,http://eureka2002.com:2002/eureka/,http://eureka2003.com:2003/eureka/ server: port: 9001 spring: application: name: zipkin-server
- Main startup class @EnableZipkinServer
package zkrun.top; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import zipkin2.server.internal.EnableZipkinServer; @EnableEurekaClient @SpringBootApplication @EnableZipkinServer public class App_Zipkin_9001 { public static void main(String[] args) { SpringApplication.run(App_Zipkin_9001.class,args); } }
- Injecting Zipkin monitoring into other services
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
spring: zipkin: base-url: http://localhost:9001
Visit
localhost:9001
Service monitoring
- Create msc-spring boot-admin-10001
- pom
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>zkrun.top</groupId> <artifactId>msc-springboot-admin-10001</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR2</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!-- Eureka Client startup needs dependency web Modular--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.1.5</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
- yaml
server: port: 10001 spring: application: name: admin-server zipkin: base-url: http://localhost:9001 eureka: client: service-url: defaultZone: http://eureka2001.com:2001/eureka/,http://eureka2002.com:2002/eureka/,http://eureka2003.com:2003/eureka/ instance: instance-id: admin-server-10001 prefer-ip-address: true #Access paths can display IP addresses management: endpoint: health: show-details: always endpoints: web: exposure: include: ["health","info"]
- Main class @EnableAdminServer
package zkrun.top; import de.codecentric.boot.admin.server.config.EnableAdminServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableAdminServer @EnableEurekaClient public class App_Admin_10001 { public static void main(String[] args) { SpringApplication.run(App_Admin_10001.class,args); } }
Start Eureka, provider, zuul, zipkin, admin in turn
Visit Eureka
http://localhost:2001/
Visit
http://localhost:10001
Code reference: https://github.com/HCJ-shadow/Zipkin-SpringBoot-Admin