11 链路跟踪 Sleuth
链路跟踪 Sleuth
搭建链路监控步骤
下载完后,终端jar包的目录里,然后输入:java -jar zipkin-server-2.14.1-exec.jar
运行。
浏览器输入:http://localhost:9411/zipkin/
原理:
简化:
修改cloud-provider-payment8001
- 在pom中 加入
<!--包含了sleuth+zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
- 在yml中添加:
zipkin:
base-url: http://localhost:9411
sleuth:
sampler:
probability: 1 #采样率值介于0到1之间,1则表示全部采集(一般不为1,不然高并发性能会有影响)
- 在PaymentController中添加:
@GetMapping("/payment/zipkin")
public String paymentZipkin(){
return "paymentZipkin...";
}
修改消费者cloud-consumer-order80
- 在pom中添加(和提供者一样)
- 在yml中添加(和提供者一样)
- 在OrderController中添加:
@GetMapping("/consumer/payment/zipkin")
public String paymentZipkin(){
String result = restTemplate.getForObject("http://localhost:8001" + "/payment/zipkin", String.class);
return result;
}
测试
启动7001,8001,80。
浏览器输入:http://localhost/consumer/payment/zipkin
测试
启动7001,8001,80。
浏览器输入:http://localhost/consumer/payment/zipkin