spring cloud 2.0 入门系列一 (5)断路器仪表盘-Hystrix Dashboard

SpringCloud Hystrix Dashboard

Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。

服务说明

上一篇讲了Hystrix,虽然有了服务器保护等功能,但我们并不能直观的查看到各服务器的状态,特别在微服务环境下,对各项指标的监控就显得尤为重要;Spring集成netflix的组件Hystrix Dashboard来展示Hystrix的工作状态。
更详细的介绍请查阅博客:https://www.cnblogs.com/ityouknow/p/6889059.html

应用说明

使用框架

  • SpringBoot 2.0.3
  • SpringCloud Finchley.RELEASE

###环境搭建
新建项目作为Hystrix Dashboard服务器

pom依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- 系统注册与监测服务 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<!-- hystrix仪表盘 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

启动文件

在启动类上添加注释**@EnableHystrixDashboard**

配置文件

server:
  port: 8763

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

spring:
  application:
    name: cloud-hystrix-dashboard

客户端修改

在上一篇文章中写了如何集成Hystrix,在1.X的版本中上述配置已经完成了,但在2.x版本中会有错误,我们需要在使用Hystrix应用上添加配置,保证Hystrix Dashboard能正确读取Hystrix数据。

增加Configuration配置
@Configuration
public class HystrixConfig {

    @Bean
    public HystrixMetricsStreamServlet hystrixMetricsStreamServlet(){
        return new HystrixMetricsStreamServlet();
    }

    @Bean
    public ServletRegistrationBean registration(HystrixMetricsStreamServlet servlet){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.setServlet(servlet);
        //是否启用该registrationBean
        registrationBean.setEnabled(true);
        registrationBean.addUrlMappings("/hystrix.stream");
        return registrationBean;
    }
}

访问

  • 启动应用,输入地址:http://localhost:8763/hystrix
  • 在页面中输入地址:http://localhost:8081/hystrix.stream
  • 点击monitor stream
  • 调用一次Hystrix接口就可以在页面看到效果了

代码示例

https://gitee.com/xiaoxming/cloud_project/tree/master/cloud-hystrix-dashboard

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值