3.Spring Cloud-熔断监控 Hystrix Dashboard

2019年09月10日 17:42 · 阅读(925) ·

[目录]

参考

springcloud(五):熔断监控Hystrix Dashboard和Turbine

Spring Cloud 入门教程5、服务容错监控:Hystrix Dashboard

spring cloud hystrix监控无法显示的问题

hystrix dashboard Unable to connect to Command Metric Stream解决办法

开发环境

名称 版本
操作系统 Windows 10 X64
JDK JDK1.8(jdk-8u151-windows-x64)
IntelliJ IDEA IntelliJ IDEA 2018.3
Maven Maven 3.6.0

代码说明

本博客的代码基于 2.Spring Cloud-熔断器 Hystrix 的基础上添加代码

源码下载

见附件

理论知识

Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。但是只使用Hystrix Dashboard的话, 你只能看到单个应用内的服务信息, 这明显不够. 我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上, 这个工具就是Turbine.

1.pom.xml 添加依赖

相关的依赖项目中之前已经存在,分别是

(1)test-invoice-web/pom.xml

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <!--spring boot 1.X:spring-cloud-starter-hystrix-->
  4. <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <!--spring boot 1.X:spring-cloud-starter-hystrix-dashboard-->
  9. <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
  10. </dependency>

(2)test-invoice-clound/pom.xml

  1. <!--Spring Boot 执行器组件-->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-actuator</artifactId>
  5. </dependency>

2.启动类添加注解(test-invoice-web)

  1. package com.test.invoice;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
  5. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  6. import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
  7. import org.springframework.cloud.openfeign.EnableFeignClients;
  8. /**
  9. * 启动类
  10. *
  11. * @author:
  12. * @version:
  13. * @date: 2019-08-12 14:43
  14. */
  15. //禁用 security 验证
  16. @SpringBootApplication(exclude = org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class)
  17. @EnableFeignClients //使用feign客户端,https://blog.csdn.net/andy_zhang2007/article/details/86680622
  18. @EnableEurekaClient //启用服务注册与发现
  19. //modify by v_hwhao 20190828 加入熔断监控Hystrix Dashboard和Turbine
  20. @EnableHystrixDashboard //启用 Hystrix Dashboard
  21. @EnableCircuitBreaker //开启熔断器功能
  22. public class WebApplication { //extends SpringBootServletInitializer
  23. public static void main(String[] args){
  24. SpringApplication.run(WebApplication.class,args);
  25. }
  26. }

3.启动项目,访问 http://localhost:8080/enta/api/hystrix/

启动项目 test-invoice-eureka
启动项目 test-invoice-service
启动项目 test-invoice-web

如果不知道怎么启动多个项目,可参考

启动多个项目

项目启动成功后,访问 http://localhost:8080/enta/api/hystrix/

看到如下界面

图中的提示

  1. Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream
  2. Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
  3. Single Hystrix App: http://hystrix-app:port/hystrix.stream
  1. 默认集群使用第一个urlhttp://turbine-hostname:port/turbine.stream
  2. 指定集群使用第二个url: http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
  3. 单个应用的监控使用最后一个: http://hystrix-app:port/hystrix.stream

4.填写信息,开始监控

  1. http://localhost:8080/enta/api/hystrix.stream
  2. Delay:100
  3. Title:service-feign-web

(1)IE 浏览器

点击 Monitor Stream

使用 Postman 访问接口 http://localhost:8080/enta/api/Inv/Api/Test/Get

参数

  1. {"id":"","name":"测试数据-菲克-1","version":""}

一直都显示 Loading...

Loading… 问题解决

spring cloud hystrix监控无法显示的问题

我想写十万个CNM。。。。
最近自己在学spring cloud刚好学到hystrix以及hystrix dashboard就自己写了例子,结果那个图一直显示loading,网上找了好多资料不行,又去spring官网看资料,感觉自己写的没什么问题可死活就是不出了,搞了两个晚上我都已经绝望了
可是,我用Google浏览器试了一下结果出来了,出来了,出来了
我之前一直是用edge,原来是浏览器的问题,可是我网上查了那么多问题没有一个人说浏览器,而且官网也没说,我也是醉了
所以在此提醒有个问题的朋友,不要在像我一样走这么多弯路
一定要用Google浏览器
一定要用Google浏览器
一定要用Google浏览器

(2)Chrom 浏览器

切换到 Chrom 浏览器,点击 Monitor Stream

Unable to connect to Command Metric Stream.问题解决

参考

hystrix dashboard Unable to connect to Command Metric Stream解决办法

test-invoice-web 项目新增配置类 HystrixConfig

  1. package com.test.invoice.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. * 熔断器配置
  8. *
  9. * @author:
  10. * @version:
  11. * @date: 2019-08-29 19:54
  12. */
  13. @Configuration
  14. public class HystrixConfig {
  15. @Bean
  16. public ServletRegistrationBean getServlet() {
  17. HystrixMetricsStreamServlet hys = new HystrixMetricsStreamServlet();
  18. ServletRegistrationBean source = new ServletRegistrationBean(hys);
  19. source.setLoadOnStartup(1);
  20. source.addUrlMappings("/hystrix.stream");
  21. source.setName("HystrixMetricsStreamServlet");
  22. return source;
  23. }
  24. }

重启项目 test-invoice-web,刷新页面

页面刷新后,变成了

5.使用 Postman 调用接口

使用 Postman 访问接口 http://localhost:8080/enta/api/Inv/Api/Test/Get

参数

  1. {"id":"","name":"测试数据-菲克-1","version":""}

6.刷新页面

刷新,页面变成了

到此单个应用的熔断监控已经完成。

7.图例


相关附件 3.Spring Cloud-熔断监控 Hystrix Dashboard | 大小:0.14M | 下载