Spring-cloud学习笔记--- Hystrix的Dashboard监控仪表盘

Spring-cloud学习笔记— Hystrix的Dashboard监控仪表盘

1. Hystrix的Dashboard监控仪表盘作用

  1. 如果我们想看到Hystrix相关数据,⽐如有多少请求、多少成功、多少失败、多少降级等,其实是基于SpringBoot健康监控的
  2. 引入SpringBoot健康监控后,访问/actuator/hystrix.stream接⼝可以获取到监控的⽂字信息,但是不直观,所以Hystrix官⽅还提供了基于图形化的DashBoard(仪表板)监控平台。
  3. Hystrix仪表板可以显示每个断路器(被@HystrixCommand注解的⽅法)的状态。
  4. Hystrix健康监控
    在这里插入图片描述

2. 创建Hystrix的DashBoard(仪表板)服务

注意: Hystrix官⽅提供的基于图形化的DashBoard(仪表板)健康监控平台也是一个单独的服务,所以也要先引入jar包,之后添加注解开启监控平台
  1. 引入依赖
    <dependencies>
            <!--hystrix-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            </dependency>
            <!--hystrix 仪表盘-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>
        </dependencies>
    
  2. 启动类添加@EnableHystrixDashboard激活仪表盘
    @SpringBootApplication
    
    // 开启hystrix dashboard
    @EnableHystrixDashboard 
    public class HystrixDashboardApplication9000 {
    public static void main(String[] args) {
    SpringApplication.run(HystrixDashboardApplication.class, args);
    } }
    
  3. 配置yml文件
    server:
      port: 9000
    Spring:
      application:
        name: lagou-cloud-hystrix-dashboard
    eureka:
      client:
        # eureka server的路径
        serviceUrl:
          # 把 eureka 集群中的所有 url 都填写了进来,也可以只写一台,因为各个 eureka server 可以同步注册表
          defaultZone: http://lagoucloudeurekaservera:8761/eureka/,http://lagoucloudeurekaserverb:8762/eureka/
      instance:
        #使用ip注册,否则会使用主机名注册了(此处考虑到对老版本的兼容,新版本经过实验都是ip)
        prefer-ip-address: true
        #自定义实例显示格式,加上版本号,便于多版本管理,注意是ip-address,早期版本是ipAddress
        instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}:@project.version@
    
  4. 在被监测的微服务中注册监控servlet(⾃动投递微服务,监控数据就是来⾃于这个微服务)
    /**
         * 在被监控的微服务中注册一个serlvet,后期我们就是通过访问这个servlet来获取该服务的Hystrix监控数据的
         * 前提:被监控的微服务需要引入springboot的actuator功能
         * @return
         */
        @Bean
        public ServletRegistrationBean getServlet(){
            HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
            ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
            registrationBean.setLoadOnStartup(1);
            registrationBean.addUrlMappings("/actuator/hystrix.stream");
            registrationBean.setName("HystrixMetricsStreamServlet");
            return registrationBean;
        }
    
被监控微服务发布之后,可以直接访问监控servlet(ip+端口号/actuator/hystrix.stream),但是得到的数据并不直观,后期可以结合仪表盘更友好的展示

在这里插入图片描述

3. 访问Dashboard仪表盘

  1. 访问测试 :http://localhost:9000/hystrix
    在这里插入图片描述
  2. 输⼊监控的微服务端点地址,展示监控的详细数据,⽐如监控服务消费者http://localhost:8090/actuator/hystrix.stream
    在这里插入图片描述
  3. 百分⽐:10s内错误请求百分⽐
  4. 实⼼圆
    1. ⼤⼩:代表请求流量的⼤⼩,流量越⼤球越⼤
    2. 颜⾊:代表请求处理的健康状态,从绿⾊到红⾊递减,绿⾊代表健康,红⾊就代表很不健康
    3. 曲线波动图:记录了2分钟内该⽅法上流量的变化波动图,判断流量上升或者下降的趋势
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值