首页 > 技术文章 > Spring生态系列文章 >

SpringCloud极简入门(八)Hystrix Dashboard

更新时间:2018-07-27 | 阅读量(1,051)

#### 一.什么是Hystrix Dashboard >从上一章节中我们知道,为了防止服务实例因为故障出现整个应用崩塌的情况而出现了熔断器模型。而 Hystrix Dashboard(仪表盘)则是用来监控Hystrix的熔断器状况的一个组件,它提供了数据监控,和友好的图形化展示界面,能让使用者很好的监控和分析熔断器的状态。 #### 二.使用Hystrix Bashboard >1.基于项目Consumer进行改造,添加 Actuator(监控)依赖 和 Hystrix-Dashboard 依赖 ``` org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-starter-netflix-hystrix-dashboard ``` >2.找到主程序类,打上 @EnableHystrixDashboard标签,开启Hystrix Dashboard 功能 ``` @EnableHystrix @EnableHystrixDashboard //开启 Hystrix Dashboard (断路器:Hystrix 仪表盘) @SpringBootApplication @EnableEurekaClient @EnableFeignClients public class ConsumerApplication { ``` >3.在主程序类中配置Bean,注册 /hystrix.stream 仪表盘访问地址对应的Servlet:HystrixMetricsStreamServlet 注意:在SpringBoot 2.0是需要对该Servlet进行注册,如果您用的是2.0以下的版本则可以不做此操作 ``` @Bean public ServletRegistrationBean getServlet() { HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } ``` >4.测试:依次启动项目 EurekaServer ,Producer , Consumer ,访问地址:http://localhost:3333/hystrix 即可看到如下画面: ![image.png](https://upload-images.jianshu.io/upload_images/11046204-58716b4b4df380d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 依次填写:http://localhost:3333/hystrix.stream ,2000 ,demo1 点击 Monitor 进入各项数据指标页面 ![image.png](https://upload-images.jianshu.io/upload_images/11046204-2e4bf7a8f2b984a3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![image.png](https://upload-images.jianshu.io/upload_images/11046204-4bc91e6c9f38de2c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
叩丁狼学员采访 叩丁狼学员采访
叩丁狼头条 叩丁狼头条
叩丁狼在线课程 叩丁狼在线课程