整合spring-cloud-Hystrix监控面板
前言
昨天我们分享了Hystrix熔断的相关知识点,但由于时间的关系,还有一些基础内容没有来得及分享,今天我们花一点时间补充下。
今天我们补充的内容主要是关于Hystrix监控面板的,这一块虽然不算核心内容,但是也比较重要。好了,下面我们直接开始吧。
Hystrix控制面板
首先你需要创建一个spring-boot项目,或者用我们之前的项目也可以,然后添加hystrix-dashboard相关依赖。
依赖
依赖文件也比较少,就一个pom依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
但是你需要在断路器服务中添加actuator依赖,默认情况下是没有这个依赖的,这个依赖主要是为了监控spring boot服务的监控状况。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
如果这个包添加成功后,访问服务的/actuator,应该是有数据正常返回的:
项目配置
添加完依赖之后,我们还需要进行一些简单配置,才能启用HystrixDashboard,不过启用的方式很简单,你只需要在项目主入口类加上@EnableHystrixDashboard注解即可,这种配置方式也算是Spring-boot配置的常规操作了。
@SpringBootApplication
@EnableHystrixDashboard
public class SpringCloudHystrixDashboardDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudHystrixDashboardDemoApplication.class, args);
}
}
添加监控服务
http://localhost:9991/hystrix
页面效果如下
然后我们需要在页面上配置我们需要访问的服务,下面我们简单介绍下Hystrix Dashboard的简单用法。
服务地址
https://turbine-hostname:port/turbine.stream
https://turbine-hostname:port/turbine.stream?cluster=[clusterName]
https://hystrix-app:port/actuator/hystrix.stream
http://localhost:9991/actuator/hystrix.stream
刷新时间
页面上的Delay就是请求间隔时间,单位是ms,时间间隔越小,数据越详细,但是被监控的服务请求压力也越大
标题
页面上的Title设置的是我们监控页面显示的标题,这个可以根据自己的情况填写
填写完成后,直接点击底下Monitor Stream按钮就可进入监控页:
扩展
这也表面,如果你觉得hystrix-dashboard面板做的丑的话,你是可以自定义监控页面的,直接调用actuator/hystrix.stream接口即可。
踩坑
这里是可能遇到的问题,也算是我踩坑过程的一些记录,如果遇到问题,可以参考解决。
提示Unable to connect to Command Metric Stream
如果访问之后,你的页面有如下提示:
这时候你需要先看下后端控制台提示信息
404错误
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
后台提示is not in the allowed
你只需要在你的hystrix-dashBoard配置文件中添加如下配置即可:
hystrix.dashboard.proxy-stream-allow-list= localhost
页面一直Loading
如果一直如下显示,这是因为你的服务一直没有被访问,所以没有监控数据
只要你调用一下服务中用到断路器的接口,就会看到监控数据:
总结
好了,hystrix相关的知识点暂时就分享到这里,后面有机会的话,我们再来剖析hystrix的其他相关知识。
-
spring-cloud之服务治理组件Eurekahttps://github.com/Syske/learning-dome-code/tree/dev/spring-cloud-eureka-demo -
spring-cloud服务治理组件Eureka客户端(包括feign和ribbon两种)https://github.com/Syske/learning-dome-code/tree/dev/spring-cloud-client-demo -
spring-cloud整合hystrix断路器https://github.com/Syske/learning-dome-code/tree/dev/Spring-cloud-hystrix-demo -
spring-cloud整合hystrix监控面板https://github.com/Syske/learning-dome-code/tree/dev/spring-cloud-hystrix-dashboard-demo
有兴趣的小伙伴可以关注下这个项目,我所有的学习demo都在,之前推送到的内容相关代码也存在这个仓库下,目前已经有60多个项目,还在持续更新
-
https://github.com/Syske/learning-dome-code -
项目截图
