六、SpringCloud断路监控面板Hystrix Dashboard

5 篇文章 0 订阅
5 篇文章 1 订阅

一、简介
Hystrix Dashboard是Hystrix的一个组件,Hystrix Dashboard提供一个断路器的监控面板,可以使我们更好的监控服务和集群的状态,仅仅使用Hystrix Dashboard只能监控到单个断路器的状态,实际开发中还需要结合Turbine使用
二、Hystrix Dashboard的使用
2.1 、在Ribbon+RestTemplate负载均衡中使用Hystrix Dashboard
第一步:在consulclient3中添加依赖

<!--断路器面板-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>

第二步:配置Hystrix Stream 的urlMapping
由于在SpringBoot 2.0版本中已经不能自动配置urlMapping,所以需要手动配置了

@Configuration
public class HystrixConfiguration {
    @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet(){
        HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> servletRegistrationBean = new ServletRegistrationBean();
        servletRegistrationBean.setServlet(hystrixMetricsStreamServlet);
        servletRegistrationBean.addUrlMappings("/hystrix.stream");
        servletRegistrationBean.setName("HystrixMetricsStreamServlet");
        return servletRegistrationBean;
    }
}

第三步、Springboot Application中添加注解,并启动程序

@EnableHystrixDashboard //开启Dashboard

第四步:查看面板
浏览器中打开localhost:9999/hystrix
这里写图片描述
图中提示数据源有三种:
http://turbine-hostname:port/turbine.stream (所有集群)
http://turbine-hostname:port/turbine.stream?cluster=[clusterName](指定名称的集群)
http://hystrix-app:port/hystrix.stream(单个应用)
我们选择第三个,点击Moitor Stream会自动生成监控面板,我们就可以实时监控数据
这里写图片描述
不同的颜色对对应断路器监控的百分比,通过统计10秒内得出的数据

2.1 、在Feign负载均衡中使用Hystrix Dashboard
注意:一定需要配置打开断路器

feign.hystrix.enabled=true

其他步骤和2.1中相同

如果处于loading data状态,是为没有数据,调用服务就可以加载数据了

源码:
https://github.com/NapWells/spring_cloud_learn/tree/master/discover_server_with_consul/springcloudlearn

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值