使用Spring Cloud Sleuth+Zipkin,是目前为止Spring Cloud微服务链路跟踪的成熟解决方案,对比国内鹰眼、Cat没有技术压力,且文档齐全,轻松实现微服务链路跟踪分析。

首先安装zipkin,使用Docker方式一键安装,

docker run -d -p 9411:9411 openzipkin/zipkin

安装启动后打开http://localhost:9411根地址,即可查看zipkin分析界面。

 

之后开始微服务上的安装,需要在zuul的api网关和service模块进行如下配置:

1.在pom中添加zipkin包(会自动添加sleuth依赖)

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>

2.在统一配置.yml中添加如下设置

spring:
  # zipkin服务跟踪
  zipkin:
    base-url: http://localhost:9411
    # 采样直接发布到web服务器
    sender:
      type: web
  # zipkin采样比
  sleuth:
    sampler:
      # 默认0.1, 旧版本为percentage,2.0.X版本改为probability
      probability: 1

其中,spring.zipkin.base-url为zipkin部署地址根目录,截取到端口号

spring.sleuth.sampler.probability为统计服务百分比,默认0.1即监控10%的接口访问。

添加完配置后重启,sleuth会自动将监控信息发送到zipkin服务器,之后便可以通过web界面查看到相关接口访问情况,示例如下:

Spring Cloud 链路跟踪
这里有个坑:如果服务中调用了消息中间件,如Kafka、RabbitMQ,采样会默认发送到中间件而不是zipkin Web服务器,可以设置微服务端spring.zipkin.sender.type=web,否则需要设置zipkin端连接到对应的消息中间件

参考文档:

sleuth https://github.com/spring-cloud/spring-cloud-sleuth

zipkin https://github.com/openzipkin/docker-zipkin

相关文章:

  • 2018-02-02
  • 2019-06-19
  • 2019-07-11
  • 2019-03-22
  • 2019-05-30
  • 2019-06-29
  • 2021-08-15
  • 2021-09-30
猜你喜欢
  • 2018-07-20
  • 2018-07-23
  • 2018-07-19
  • 2018-07-13
  • 2018-05-11
  • 2020-04-27
  • 2020-04-28
相关资源
相似解决方案