In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on the integration of zipkin components into the service tracking component zipkin,Spring Cloud Sleuth.
I. brief introduction
Add sleuth to the classpath of a Spring Boot application (see below
For Maven and Gradle examples), and you will see the correlation data
Being collected in logs, as long as you are logging requests.
-extracted from the official website
The main function of Spring Cloud Sleuth is to provide tracking solutions in distributed systems, and compatible support for zipkin, you only need to introduce the corresponding dependencies in the pom file.
Second, service tracking analysis
For those who divide services by business in micro-service architecture, you can ask for more information about springcloud architecture: 3536247259, an interface exposed through REST calls may require the coordination of many services to complete this interface function. If there is a problem or network timeout of any service on the link, it will cause the interface call to fail. With the continuous expansion of the business, the mutual invocation between services will become more and more complex.
With more and more services, the analysis of the call chain will become more and more complex. The invocation relationship between them may be as follows:
III. Terminology
Span: basic unit of work, for example, sending a RPC in a newly created span is equivalent to sending a response request to RPC,span with a 64-bit ID unique identity, trace is represented by another 64-bit ID, span also has other data information, such as summary, timestamp events, critical value comments (tags), span's ID, and progress ID (usually IP address) span is constantly starting and stopping, while recording time information When you create a span, you have to stop it at some point in the future.
Trace: a tree structure made up of a series of spans. For example, if you are running a distributed big data project, you may need to create a trace.
Annotation: used to record the existence of an event in a timely manner, and some core annotations to define the beginning and end of a request
Cs-Client Sent-the client initiates a request, and this annotion describes the beginning of the span
Sr-Server Received-the server gets the request and is ready to start processing it. If you subtract its sr from the cs timestamp, you can get the network delay.
The ss-Server Sent-comment indicates the completion of the request processing (when the request is returned to the client). If the ss minus the sr timestamp, the request processing time required by the server can be obtained.
Cr-Client Received-indicates the end of the span, and the client successfully receives the reply from the server. If cr minus the cs timestamp, you can get all the time it takes for the client to get the reply from the server.
Graphically use Zipkin annotations for Span and Trace in one system:
Graphically use Zipkin annotations for Span and Trace in one system:
IV. Construction project
After explaining the basic knowledge, let's practice. The case of this paper mainly consists of three projects: a server-zipkin, which mainly uses the functions of ZipkinServer to collect and display data; a service-hi, which exposes hi interface; and a service-miya, which exposes miya interface. The two service can be called each other. And only when called, server-zipkin collects data, which is why it is called service tracking.
4.1Building server-zipkin
When spring Cloud is version F, you no longer need to build your own Zipkin Server, you just need to download jar at the download address:
Https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server/
You can also download it here:
Link: https://pan.baidu.com/s/1w614Z8gJXHtqLUB6dKWOpQ password: 26pf
After downloading the jar package, you need to run jar, as follows:
Java-jar zipkin-server-2.10.1-exec.jar
Visit the browser localhost:9494
4.2 create service-hi
The introduction of spring-cloud-starter-zipkin in its pom starts with the following code:
4.0.0 com.forezp service-zipkin 0.0.1-SNAPSHOT jar service-hi Demo project for Spring Boot com.forezp sc-f-chapter9 0.0.1-SNAPSHOT org.springframework.boot Spring-boot-starter-web org.springframework.cloud spring-cloud-starter-zipkin org.springframework. Boot spring-boot-maven-plugin
The address of the zipkin server is specified in its configuration file application.yml, and the header is specified by configuring "spring.zipkin.base-url":
Server.port=8988spring.zipkin.base-url= http://localhost:9411spring.application.name=service-hi
This is done by introducing spring-cloud-starter-zipkin dependencies and setting up spring.zipkin.base-url.
External exposure interface:
Package com.forezp;import brave.sampler.Sampler;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.Bean;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.client.RestTemplate;import java.util.logging.Level;import java.util.logging.Logger @ SpringBootApplication@RestControllerpublic class ServiceHiApplication {public static void main (String [] args) {SpringApplication.run (ServiceHiApplication.class, args);} private static final Logger LOG = Logger.getLogger (ServiceHiApplication.class.getName ()); @ Autowired private RestTemplate restTemplate; @ Bean public RestTemplate getRestTemplate () {return new RestTemplate () } @ RequestMapping ("/ hi") public String callHome () {LOG.log (Level.INFO, "calling trace service-hi"); return restTemplate.getForObject ("http://localhost:8989/miya", String.class) } @ RequestMapping ("/ info") public String info () {LOG.log (Level.INFO, "calling trace service-hi"); return "IBM service-hi";} @ Bean public Sampler defaultSampler () {return Sampler.ALWAYS_SAMPLE;}}
4.3Create service-miya
Create process pain service-hi, introduce the same dependency, and configure spring.zipkin.base-url.
External exposure interface:
Package com.forezp;import brave.sampler.Sampler;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.Bean;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.client.RestTemplate;import java.util.logging.Level;import java.util.logging.Logger @ SpringBootApplication@RestControllerpublic class ServiceMiyaApplication {public static void main (String [] args) {SpringApplication.run (ServiceMiyaApplication.class, args);} private static final Logger LOG = Logger.getLogger (ServiceMiyaApplication.class.getName ()); @ RequestMapping ("/ hi") public String home () {LOG.log (Level.INFO, "hi is being called") Return "hi i'm miya!";} @ RequestMapping ("/ miya") public String info () {LOG.log (Level.INFO, "info is being called"); return restTemplate.getForObject ("http://localhost:8988/info",String.class);} @ Autowired private RestTemplate restTemplate" @ Bean public RestTemplate getRestTemplate () {return new RestTemplate ();} @ Bean public Sampler defaultSampler () {return Sampler.ALWAYS_SAMPLE;}}
4.4 start the project and demonstrate tracking
Start the above project in turn, open the browser to visit: http://localhost:9411/, and the following interface will appear:
Visit: http://localhost:8989/miya, the browser appears:
Isimm service-hi
Open the http://localhost:9411/ interface and click Dependencies to discover the dependencies of the service:
Click find traces to see the data of specific services calling each other:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.