💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
在使用了Hystrix进行服务熔断降级之后,我们亟待于有一种方式可以查看Spring Cloud 微服务各个节点的哪些方法接口触发了熔断、请求成功数量、请求失败数量,包括断路器状态、服务请求频率等信息。我们获得了这些信息之后才能有效的进行服务的扩容、调整,从而更好地满足微服务系统的高并发以及高可用的要求! ![](https://img.kancloud.cn/d1/ae/d1ae5f9b43dbe8ea5804b106cf08f62b_1012x320.png) Hystrix 项目包含了一个DashBoard子模块可以帮助我们完成相关数据的获取以及展示工作。 ## 一、新建Hystrix DashBoard监控web项目 新建一个Spring Boot项目,该项目集成Hystrix DashBoard之后可以完成服务熔断统计信息的展示。通过maven坐标引入Hystrix DashBoard \* 新版本(笔者Spring CLoud H版)不要使用`spring-cloud-starter-hystrix-dashboard`,使用`spring-cloud-starter-netflix-hystrix-dashboard` \* 不是web项目么?为什么没有`spring-boot-starter-web`?答:`spring-cloud-starter-netflix-hystrix-dashboard`已包含 ~~~ <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ~~~ application.yml,自定义一个不常用的项目启动端口 ~~~ server: port: 8772 ~~~ 在项目启动入口类上面加上`@EnableHystrixDashboard`注解 ![](https://img.kancloud.cn/c8/7e/c87e2a3878841646d166d797b53275c0_721x199.png) 浏览器中访问:[http://localhost:8772/hystrix,](http://localhost:8772/hystrix%EF%BC%8C)若显示如下图所示,则表示Hystrix DashBoard监控服务正常运行,搭建成功。 ![](https://img.kancloud.cn/66/68/66681d71d217a0e28fe7ee7c81fc4242_1072x687.png) ## 二、被监控服务调整 上面一小节的操作,我们只是将Hystrix DashBoard监控服务完成。它将监控我们系统内的所有的微服务,为了保证能正确的从系统内的微服务获取服务熔断降级相关的信息。被监控的服务需要满足一些要求: * 被监控的服务要正确的集成了Hystrix * 所有被监控的微服务都要有actuator来暴露监控信息。 ~~~ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ~~~ * 在actuator监控服务中暴露hystrix.stream监控端点。否则会有下图中的错误提示: ![](https://img.kancloud.cn/3c/de/3cde0c3eeb4877ebfd0bbff7f3028698_769x174.png) ~~~ management: endpoints: web: exposure: include: refresh,health,hystrix.stream ~~~ ## 三、访问监控服务web界面 本节为大家讲的这种Hystrix DashBoard搭建方式,一次只能监控一个服务。 ![](https://img.kancloud.cn/0f/76/0f76df5c75355f76b933e7808f50e184_1045x379.png) 在地址栏输出某个微服务的actuator监控地址:[http://locahost:8401/actuator/hystrix.stream](http://locahost:8401/actuator/hystrix.stream),点击monitor Stream显示该服务的监控信息: ![](https://img.kancloud.cn/c5/af/c5afec5b9f0e1525da189b92a9175c1f_768x470.png) > 注意:查看hystrix监控之前,一定要访问一次API,否则一直Loading。 * **实心圆颜色变化**:颜色的变化代表了实例的健康程度,它的健康程度从 绿色 > 黄色 > 橙色 > 红色 递减; * **实心圆大小变化**:流量越大实心圆就越大, 所以通过该实心圆的展示,就可以在大量实例中快速的发现**故障实例和高压力实例**。 #### 详细图解 ![](https://img.kancloud.cn/09/40/094014029a61f462b249238d40c4fb95_757x482.png)