SpringCloud极简入门(八)Hystrix Dashboard

一.什么是Hystrix Dashboard

从上一章节中我们知道,为了防止服务实例因为故障出现整个应用崩塌的情况而出现了熔断器模型。而 Hystrix Dashboard(仪表盘)则是用来监控Hystrix的熔断器状况的一个组件,它提供了数据监控,和友好的图形化展示界面,能让使用者很好的监控和分析熔断器的状态。

二.使用Hystrix Bashboard

1.基于项目Consumer进行改造,添加 Actuator(监控)依赖 和 Hystrix-Dashboard 依赖
```
<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>
>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
依次填写:http://localhost:3333/hystrix.stream ,2000 ,demo1 点击 Monitor 进入各项数据指标页面
image.png
image.png

 

猜你喜欢

转载自blog.csdn.net/wolfcode_cn/article/details/81279354