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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值