Spring Cloud第六篇 | Hystrix仪表盘监控Hystrix Dashboard
发布日期:2021-05-09 01:42:14 浏览次数:16 分类:博客文章

本文共 2209 字,大约阅读时间需要 7 分钟。

本文是Spring Cloud专栏的第六篇文章,了解前五篇文章内容有助于更好的理解本文:

一、Hystrix仪表盘监控介绍

    Hystrix仪表盘( Hystrix Dashboard),就像汽车的仪表盘实时显示汽车的各 项数据一样, Hystrix仪表盘主要用来监控 Hystrix的实时运行状态,通过它我们可以看到 HystriX的各项指标信息,从而快速发现系统中存在的问题进而解决 要使用 Hystriⅸ仪表盘功能,我们首先需要有一个 Hystrix Dashboard,这个功能我们可以在原来的消费者应用上添加,让原来的消费者应用具备Hysr仪表 盘功能,但一般地微服务架构思想是推崇服务的拆分, Hystrix Dashboard也是一个服务,所以通常会单独创建一个新的工程专门用做 Hystrix Dashboard 服务,Hystrix Dashboard所处的作用如图

二、Hystrix仪表盘监控应用

1、新建一个模块命名为(springcloud-hystrix-dashboard)

2、添加依赖hystrix的Dashboard依赖

org.springframework.cloud
spring-cloud-starter-netflix-hystrix-dashboard

此时依赖可能下载不下来,可以添加阿里云仓库

alimaven
aliyun maven
http://maven.aliyun.com/nexus/content/groups/public/
true
false

3、在启动类上添加注解@EnableHystrixDashboard

4、端口配置为3721,到此我们的hystrix监控服务就搭建完毕了,启动访问http://localhost:3721/hystrix

    Hystrix仪表盘工程已经创建好了,我们需要有一个服务,让这个服务提供一个路径为/actuator/hystrix.stream接口,然后就可以使用Hystrix仪表盘来对该服务进行监控了

5、改造消费者(springcloud-service-consumer)

我们改造消费者服务,让其能提供/actuator/hystrix.stream接口,步骤如下:

    5-1、消费者项目需要有Hystrix的依赖,在之前案例中使用服务熔断的时候已经加过了

    5-2、需要有一个springboot的服务监控依赖,可以直接添加到父模块依赖中

org.springframework.boot
spring-boot-starter-actuator

    5-3、配置文件需要配置springboot监控的端点访问权限

#用来暴露endpoints的,由于endpoints中会包含很多敏感信息,#除了health和info两个支持直接访问外,其他的默认不能直接访问,#所以我们让他们都能访问(*),或者指定springboot的监控端点访问权限,#*表示所有的端点都允许访问,如果只写hystrix.stream,他会把默认的info,health端点关闭management:  endpoints:    web:      exposure:        include: ["info","health","hystrix.stream"]

从控制台日志上可以看到

2019-08-07 15:58:31.187  INFO 7396 --- [ost-startStop-1] o.s.b.a.e.web.ServletEndpointRegistrar   : Registered '/actuator/hystrix.stream' to hystrix.stream-actuator-endpoint

6、第一次访问,要先访问其他带用熔断器的接口,访问入口:http://localhost:9090/actuator/hystrix.stream

    注意:这里有一个细节需要注意,要访问/hystrix.stream接口,首先访问消费者(springcloud-service-consumer)工程中任意的一个带有熔断器的接口,否则直接访问/hystrix.stream接口时,会输出一连串ping:    ping: ....

7、把http://localhost:9090/actuator/hystrix.stream填写到Hystrix Dashboard仪表盘上,直接在网上找了一个详细描述图,如下图

 

详细参考案例源码:

 

 

上一篇:Spring Cloud第八篇 | Hystrix集群监控Turbine
下一篇:Spring Cloud第五篇 | 服务熔断Hystrix

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年04月17日 05时33分38秒