前言

  1. 本文采用Spring cloud本文为2.1.8RELEASEversion=Greenwich.SR3

本文基于前两篇文章eureka-server、eureka-client、eureka-ribbon和eureka-feign的实现。

参考

概念

Hystrix Dashboard时Hystrix提供的一个可以查看hystrix监控数据的控制面板。Hystrix提供了近实时的数据监控,Hystrix会实时、累加的记录所有关于HystrixCommand的执行信息,包括每秒执行多少请求,多少成功和多少失败等。

创建Hystrix Dashboard工程

1.1 创建sping boot工程:hysteric-dashboard

1.2 添加pom.xml相关依赖

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-actuator</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-web</artifactId>
  8. </dependency>
  9. <dependency>
  10. <groupId>org.springframework.cloud</groupId>
  11. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.springframework.cloud</groupId>
  15. <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
  16. </dependency>

1.3 application添加配置信息

  1. spring:
  2. application:
  3. name: hystrix-dashboard
  4. server:
  5. port: 8500
  6. eureka:
  7. instance:
  8. hostname: localhost
  9. lease-renewal-interval-in-seconds: 5
  10. lease-expiration-duration-in-seconds: 10
  11. client:
  12. service-url:
  13. defaultZone: http://eureka1.server.com:8701/eureka/,http://eureka2.server.com:8702/eureka/,http://eureka3.server.com:8703/eureka/

1.4 启动类HystrixDashboardApplication增加注解

  1. package spring.cloud.demo.hystrixdashboard;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  5. import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
  6. @EnableHystrixDashboard
  7. @EnableDiscoveryClient
  8. @SpringBootApplication
  9. public class HystrixDashboardApplication {
  10. public static void main(String[] args) {
  11. SpringApplication.run(HystrixDashboardApplication.class, args);
  12. }
  13. }

@EnableHystrixDashboard:启动Hystrix Dashboard断路器看板相关配置

1.5 启动hystrix-dashboard服务

打开浏览器,输入http://localhost:8500/hystrix显示结果如下:

url输入框:代表要监控的服务消费者

Single Hystrix App: https://hystrix-app:port/actuator/hystrix.stream:要监控路径url格式

1.6 监控ribbon服务

1.6.1 eureka-ribbon增加Hystrix的Configuration

  1. package spring.cloud.demo.eurekaribbon.config;
  2. import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
  3. import org.springframework.boot.web.servlet.ServletRegistrationBean;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6. /**
  7. * @auther: maomao
  8. * @DateT: 2019-09-17
  9. */
  10. @Configuration
  11. public class HystrixConfig {
  12. @Bean
  13. public ServletRegistrationBean getServlet() {
  14. HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
  15. ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
  16. registrationBean.setLoadOnStartup(1);
  17. registrationBean.addUrlMappings("/hystrix.stream");
  18. registrationBean.setName("HystrixMetricsStreamServlet");
  19. return registrationBean;
  20. }
  21. }

启动eureka-client和eureka-ribbon服务。然后在hystrix dashboard控制面板url框中输入:

点击Monitor Stream会显示:

  • Unable to connect to Command Metric Stream问题原因:因为我们开启监控的断路器流Hystrix Stream路径http://localhost:8901/hystrix.stream不是spring boot的默认路径,也不是hystrix的默认路径,所有要增加Hystrixconfig来制定断路器的指标流Servlet。

  • 首次成功启动页面也有可能会显示loading,这代表还没有访问我们要监控的服务,这是我们可以多次请求要访问的服务就可以看到指标数据

按照同样的方式我可以设置eureka-feign的配置来进行监看。

总结

本文简单的搭建了Hystrix Dashborad数据监控平台。

Hystrix现在已经是停止开发,处于维护阶段,在Github上Hystrix已经说明,建议我们使用Resilience4J。后续会更新关于Resilience4J的简单实用。

代码地址

gitHub地址


《Srping Cloud 2.X小白教程》目录


转载请注明出处,

  • 联系方式:4272231@163.com

spring cloud 2.x版本 Hystrix Dashboard断路器教程的更多相关文章

  1. spring cloud 2.x版本 Ribbon服务发现教程(内含集成Hystrix熔断机制)

    本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 前言 本文基于前两篇文章eureka-server和eureka-client的实现. 参考 ...

  2. spring cloud 2.x版本 Feign服务发现教程(内含集成Hystrix熔断机制)

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server和eureka-client的实现. 参考 ...

  3. spring cloud 2.x版本 Eureka Client服务提供者教程

    本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 1 创建eureka client 1.1 新建Srping boot工程:eureka-c ...

  4. spring cloud 2.x版本 Zuul路由网关教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  5. spring cloud 2.x版本 Gateway动态路由教程

    摘要 本文采用的Spring cloud为2.1.8RELEASE,version=Greenwich.SR3 本文基于前面的几篇Spring cloud Gateway文章的实现. 参考 Gatew ...

  6. spring cloud 2.x版本 Gateway路由网关教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  7. spring cloud 2.x版本 Config配置中心教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前面的文章eureka-server的实现. 参考 eureka-server ...

  8. spring cloud 2.x版本 Gateway自定义过滤器教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  9. spring cloud(五)熔断监控Hystrix Dashboard和Turbine

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

随机推荐

  1. Docker运行dotnetcore

                    windows下安装docker 参考: https://www.jianshu.com/p/502b4ac536ef https://docs.docker.com/ ...

  2. VMware安装Linux提示此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态

    问题: 原因: 这是由于没有开启虚拟技术导致的. 解决: 进入电脑BIOS设置,将"Inter Virtual Technology"设置为"Enabled", ...

  3. mysql初始化/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

    [root@test153 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql - ...

  4. Oracle ASM无法识别扩展分区的磁盘设备

    在linux 环境下,我们一般通过udev或者asmlib来绑定磁盘分区作为ASM的候选存储单元.在使用udev的情况下,一般只要我们可以看到被绑定的磁盘的设备,并且这些设备的属主和权限没有问题,AS ...

  5. VM虚拟机安装无法将值写入注册表.....请确认你是否有足够的权限访问该注册表项,或者与技术支持人员联系。

    解决方法: 关掉360安全卫士等软件再安装

  6. 给OPi Zero Plus添加USB启动功能

    为使OPi Zero Plus支持U盘启动,需要在板载的SPI Flash当中刷入uboot.在这个过程当中绕了很多弯路,特此记录 最终操作步骤见文末 网上的教程仅使用sudo modprobe sp ...

  7. alter对话框处理:

    from selenium import webdriverd = webdriver.Firefox()d.get('file://C:\\我的代码\\selenium自动化测试\\alter.ht ...

  8. a minimum of subsistence

    A hundred years ago it was assumed and scientifically "proved" by economists that the laws ...

  9. Unity ugui屏幕适配与世界坐标到ugui屏幕坐标的转换

    我们知道,如今的移动端设备分辨率五花八门,而开发过程中往往只取一种分辨率作为设计参考,例如采用1920*1080分辨率作为参考分辨率. 选定了一种参考分辨率后,美术设计人员就会固定以这样的分辨率来设计 ...

  10. 记一次Ubuntu19无法安装docker源

    按照各大网站以及个人习惯我会使用下面这种方法添加Docker源: root@ubuntu:~# sudo add-apt-repository "deb [arch=amd64] https ...