zoukankan      html  css  js  c++  java
  • Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin

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

    前情回顾请参考:

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

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

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

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

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

    • 概览
    • 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页面上查询到。
  • 相关阅读:
    Balanced Binary Tree
    Minimum Depth of Binary Tree
    Path Sum
    Flatten Binary Tree to Linked List
    Distinct Subsequences
    Chp3: Stacks and Queue
    Chp2: Linked List
    Populating Next Right Pointers in Each Node
    Valid Palindrome
    Binary Tree Maximum Path Sum
  • 原文地址:https://www.cnblogs.com/csts/p/10288289.html
Copyright © 2011-2022 走看看