zoukankan      html  css  js  c++  java
  • Hystrix仪表盘——Hystrix dashboard

    hystrix会监控所有托管在hystrix的远程调用,hystrix会实时、累加地记录所有关于HystrixCommand的执行信息,包括每秒执行多少请求,多少成功了、多少失败了,还有统计出的失败率等等。

    Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控。而在spring cloud中,只有引入spring-cloud-starter-hystrix这一启动依赖,就会默认引入hystrix-metrics-event-stream依赖。

    Spring Cloud Hystrix Dashboard只是spring cloud基于Hystrix Dashboard,将实时监控数据通过页面呈现出来。Spring Cloud Hystrix Dashboard的底层原理是间隔一定时间去“Ping”目标服务,返回的结果是最新的监控数据,最后将数据显示出来。

    上文的目标服务,必须具备两个条件。第一,服务本身有对Hystrix做监控统计(spring-cloud-starter-hystrix启动依赖);第二,暴露hystrix.stream端口(spring-boot-starter-actuator启动依赖)。

    Spring Cloud Hystrix 仪表盘依赖:

           <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            </dependency>

    接着修改启动类

    package com.centit.consumer;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    import org.springframework.cloud.netflix.hystrix.EnableHystrix;
    import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
    import org.springframework.cloud.openfeign.EnableFeignClients;
    
    @SpringBootApplication
    @EnableDiscoveryClient
    @EnableFeignClients
    @EnableHystrix
    @EnableHystrixDashboard
    public class ConsumerServerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ConsumerServerApplication.class, args);
        }
    
    }
     

    可以看到,只是在启动类上加了@EnableHystrixDashboard注解,该注解是让该项目成为一个Hystrix仪表盘。

    最后,添加bootstrap.yml启动配置文件。(当然也可以省略,只是会在8080端口启动)如下:

    server:
      port: 10083
      max-http-header-size: 20480
    spring:
      application:
        name: consumer
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:10080/eureka/
    
    feign:
      hystrix:
        enabled: true #Feign Hystrix断路器
        command:
          default:
            execution:
              timeout:
                enabled: true #是否开启超时(默认开启)
              isolation:
                thread:
                  timeoutInMilliseconds: 5000 #超时时间(默认1000毫秒)
    
    management:
      endpoints:
        web:
          exposure:
            include: hystrix.stream

    所有准备工作完成之后,启动hystrix-dashboard服务。然后在浏览器访问http://localhost:10083/hystrix,若上面的步骤没有出错,会加载出类似如下的页面:

     

    上图中出现3个输入框。作用如下:

    1. 目标服务暴露的hystrix.stream端口
    2. “Ping”的间隔时间
    3. 目标服务的别名,可以随便取

    最后还有一个“Monitor Stream”按钮,在3个输入框输入无误后,点击该按钮,开始“监控”目标服务。

    上图监控的是本地端口号是10083的服务,数据刷新间隔为2s,服务别名为hello,最后点击“Monitor Stream”按钮。

    注意:必须确保目标服务已经启动。

    点击“Monitor Stream”按钮后,会出现几种情况:

    1. 正常,但暂未执行过hystrix命令,会出现两个Loading...


       
    2. 正常,随便调用一个被hystrix管理的远程调用接口后,页面会刷新出类似如下的页面。

    3. 异常,目标服务没有引入spring-boot-starter-actuator启动依赖。

     

     

  • 相关阅读:
    2019ICPC徐州 H.Yuuki and a problem
    wprintf 输出中文
    bit数组
    Vs2010 Atl工程手工添加连接点
    dll非模态窗口不响应按钮消息
    VC中给控件添加ToolTip
    在Dialog中添加工具条
    在Dialog中添加状态栏
    Vc添加快捷键
    在VC中调用COM组件的方法
  • 原文地址:https://www.cnblogs.com/hooly/p/12553891.html
Copyright © 2011-2022 走看看