前言

🏃🏃🏃

本次分享 SpringCloud - Hystrix-Dashboard Hystrix仪表盘

简介


Hystrix-dashboard 是一款针对 Hystrix 进行实时监控的可视化工具,主要用来实时监控Hystrix的各项指标信息。通过Hystrix Dashboard反馈的实时信息,可以帮助我们快速发现系统中存在的问题。

快速开始

生产者-provider

  1. Maven依赖

    <!--feign-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
  2. application.yml配置

    # 开启feign的熔断保护
    feign:
        hystrix:
            enabled: true 
  3. 编码

    1. feignClient

      @FeignClient(value = ServerConstants.SERVICE_NAME, fallback = TestFallback.class)
      public interface ITestProviderService extends ITestControllerAPI {
      
          @Override
          @RequestMapping(value = "/test/inner/test", method = RequestMethod.GET)
          String test();
      
      }
    2. fallback

      @Component
      public class TestFallback implements ITestProviderService {
          @Override
          public String test() {
              return "test ----- fallback!";
          }
      }
    3. feignClient 实现类

      @RestController
      @RequestMapping(value = "/test/inner")
      public class TestProviderController implements ITestControllerAPI {
          @Override
          @GetMapping(value = "test")
          public String test() {
              return "test ----- ok!";
          }
      }

消费者-consumer

  1. Maven依赖

    <!-- hystrix -->
     <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
     </dependency>
     <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
  2. application.yml配置

    # 开启feign的熔断保护
    feign:
        hystrix:
            enabled: true
  3. 编码

    1. 调用 feignClient

      @RestController
      @RequestMapping(value = "/demo")
      public class DemoController {
          
          @Autowired
          private ITestProviderService testProviderService;
          
          @GetMapping(value = "test")
          public String test() {
              String result = testProviderService.test();
              return result;
          }
      
      }

启动验证

  1. 启动 生产者-provider
  2. 启动 消费者-consumer

  3. 访问 Hystrix-Dashboard

    浏览器访问 http://127.0.0.1:1123/hystrix

    Hystirix-Dashboard.png

    输入框中输入 http://127.0.0.1:1123/hystrix.stream

    正常状态.png

  4. 关闭 生产者-provider

  5. 观察 Hystrix-Dashboard

    • 断路器熔断状态 - open

      图片.png

结束语

  • 以上就是 Hystrix-Dashboard 的示例。
  • Hystrix-Dashboard 指标参数说明

    image


✔ END

© 🇹 🉐 🆙🆙🆙


t_什么都没有
4 声望0 粉丝

什么都没有。


引用和评论

0 条评论