sleuth + zipkin 链路追踪示例

文章介绍了Zipkin作为一个分布式追踪系统,用于收集和查找服务架构中的延迟数据。SpringCloudSleuth是与Zipkin集成的工具。文中提供了下载Zipkin服务器的链接,以及运行步骤。接着展示了如何在SpringCloud项目中引入Sleuth依赖,设置采样率,并在提供者和消费者服务中使用。最后,通过访问Zipkin的Web界面查看详细的链路追踪信息。
摘要由CSDN通过智能技术生成

ZipKin

简介

中文文档: https://www.bookstack.cn/read/dyingbleed-zipkin/326d459d6b9268be.md

文档2: ttps://www.springcloud.cc/spring-cloud-greenwich.html#_spring_cloud_sleuth

Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in service architectures. Features include both the collection and lookup of this data.

Zipkin是一个分布式跟踪系统。 它帮助收集解决服务架构中的延迟问题所需的定时数据。 功能包括数据的收集和查找。

下载地址

https://repo1.maven.org/maven2/io/zipkin/zipkin-server/

运行

上一步下载对应的jar包,输入一下命令运行。

java -jar zipkin-server-2.14.1-exec.jar

打开http://localhost:9411/能看到页面即跑成功

注:如果不做持久化数据在内存中保存,具体如何持久化参考官方文档

Sleuth

依赖

<!--包含了sleuth+zipkin-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

提供者 cloud-provider-payment8001

@GetMapping("/payment/zipkin")
public String paymentZipkin()
{
    return "hi ,i'am paymentzipkin server fall back,welcome to my channel,O(∩_∩)O哈哈~";
}
# 添加的配置文件
spring:
  zipkin:
    base-url: http://localhost:9411
  sleuth:
    sampler:
    #采样率值介于 0 到 1 之间,1 则表示全部采集
    probability: 1

消费者 cloud-consumer-order80

@GetMapping("/consumer/payment/zipkin")
public String paymentZipkin()
{
    String result = restTemplate.getForObject("http://localhost:8001"+"/payment/zipkin/", String.class);
    return result;
}
# 添加的配置文件
spring:
  zipkin:
    base-url: http://localhost:9411
  sleuth:
    sampler:
      probability: 1

总结

再次访问:http://localhost:9411/即可以看到详细的链路追踪信息

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值