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;
    }
}

访问

代码示例

https://github.com/xiaoming302/cloud_project/tree/master/cloud-hystrix-dashboard

猜你喜欢

转载自blog.csdn.net/xiaoluo033/article/details/80952786
今日推荐