Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin

前言:随着微服务系统的增长,服务之间的调用关系变得会很是复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得很是重要了。spring cloud sleuth实现了对分布式服务的监控解决方案。html

前情回顾请参考:java

Spring Cloud 微服务一:Consul注册中心git

Spring Cloud 微服务二:API网关spring cloud zuulgithub

Spring Cloud 微服务三: API网关Spring cloud gatewayweb

Spring Cloud 微服务四:熔断器Spring cloud hystrixspring

Spring Cloud 微服务五:Spring cloud gateway限流docker

 

  • 概览
  • Spring cloud sleuth实现了分布式系统的链路监控,用户能够经过可视化、交互式页面查看服务调用状况,并可以自动更关心服务调用状态
  • sleuth集成zipkin
    • 搭建zipkin服务,能够经过docker或者jar包的方式启动,具体可参考:https://github.com/openzipkin.本章主要使用spring的方式启动。首先新建一个module sleuth-server,在pom中引入如下依赖,版本我使用的与springboot 2.0.8.RELEASE相对应的2.11.7版本,该版本已经在父工程中定义。
      <artifactId>sleuth-server</artifactId>
      
          <dependencies>
              <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-zipkin</artifactId>
              </dependency>
              <dependency>
                  <groupId>io.zipkin.java</groupId>
                  <artifactId>zipkin-server</artifactId>
              </dependency>
              <dependency>
                  <groupId>io.zipkin.java</groupId>
                  <artifactId>zipkin-autoconfigure-ui</artifactId>
              </dependency>
          </dependencies>

       

    • 在启动类添加@EnableZipkinServer注解,表示该工程是一个服务器
      @SpringBootApplication @EnableZipkinServer public class SleuthServerApplication { public static void main(String[] args) { SpringApplication.run(SleuthServerApplication.class, args); } }

       

    • 配置application.yml,加入zipkin配置
      server: port: 9411 debug: true spring: application: name: sleuth-server management: metrics: web: server: auto-time-requests: false

       

    • 启动sleuth-server,访问http://localhost:9411进入主界面
    • 接下来配置user-consumer,在该工程的pom文件中添加zipkin依赖
      <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-zipkin</artifactId>
      </dependency>

       

    • application.yml中添加sleuth以及zipkin配置
       zipkin: base-url: http://localhost:9411/ sleuth: sampler: probability: 1.0

       

    • 一样配置user-service
    • 启动user-service,user-consumer,访问服务,会在zipin页面上查询到。
相关文章
相关标签/搜索