I. Sleuth
0. Concept
- Trace
- A set of spans that form a call tree structure, forms the trace of the request.
- Span
- It is the basic unit of work, for example a call to a service. They are identified with a span ID and a trace ID to which span is owned. They have start and end, and with it you get track the response time between requests.
- Tag
- Key/value pair that identifies certain information in the span. It doesn‘t contain timestamps, it just identifies.
Annotation: Used to record the existence of an event in time. With Brave instrumentation, we no longer need to set special events for Zipkin to understand who the client and server are, where the request started, and where it ended. For learning purposes, however, we mark these events to highlight what kind of an action took place.
- cs: Client Sent. The client has made a request. This annotation indicates the start of the span.
- sr: Server Received: The server side got the request and started processing it. Subtracting the
cs
timestamp from this timestamp reveals the network latency. - ss: Server Sent. Annotated upon completion of request processing (when the response got sent back to the client). Subtracting the
sr
timestamp from this timestamp reveals the time needed by the server side to process the request. - cr: Client Received. Signifies the end of the span. The client has successfully received the response from the server side. Subtracting the
cs
timestamp from this timestamp reveals the whole time needed by the client to receive the response from the server.
1. pom
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-sleuth</artifactId> </dependency>
2. config
1) sampler
--- spring: sleuth: sampler: probability: 1.0
II. zipkin
0. way
1) http
2) Messaging Brokers
0. zipkin client
1) pom
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
2) config
(1) base url
--- spring: zipkin: base-url: http://localhost:9411
(2) sender
A. RabbitMQ
--- spring: zipkin: sender: type: RABBIT
B. Kafka
--- spring: zipkin: sender: type: KAFKA
C. Web
default
1. zipkin server
upgrade to Spring Boot 2.0 NoClassDefFoundError UndertowEmbeddedServletContainerFactory
1) down
https://mvnrepository.com/artifact/io.zipkin.java/zipkin-server
2) run
III. MQ
1. RabbatMQ
0) pom
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-binder-rabbit</artifactId> </dependency>
1) config
--- spring: rabbitmq: addresses: 192.168.1.115 port: 15672 username: admin password: admin virtual-host: sleuth
2. Kafka
0) pom
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-binder-kafka</artifactId> </dependency>
1) config
spring: kafka: bootstrap-servers: - 192.168.1.186:9092 - 192.168.1.187:9092 - 192.168.1.188:9092
Reference:
1. Trazabilidad Distribuida con Spring Cloud: Sleuth y Zipkin
原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/10052026.html
时间: 2024-09-29 15:44:05