Spring Cloud Circuit Breaker Dashboard 是基于Spring Boot开发的一个仪表板应用,它用于监控基于断路器模式的微服务在一段时间内的健康状况和指标。最初,这个仪表板与Netflix Hystrix的实现紧密整合,用于展示Hystrix断路器的实时监控数据。
Netflix Hystrix Dashboard 显示了如下内容:
- 断路器的健康状况(开启/关闭)
- 请求流量
- 成功、失败及超时请求的比例
- 请求平均处理时间
- 断路器被触发的次数
为了使用Hystrix Dashboard, 您需要在您的Spring Boot项目中引入Hystrix Dashboard 的起步依赖,并且创建一个Spring MVC控制器来启动并显示仪表板,这可以通过添加以下依赖到pom.xml
文件:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
启动Hystrix Dashboard通常涉及添加@EnableHystrixDashboard
注解到主应用类或者配置类:
@SpringBootApplication
@EnableHystrixDashboard
public class YourApplication {
public static void main(String[] args) {
SpringApplication.run(YourApplication.class, args);
}
}
在Spring Cloud微服务应用程序中,通常还需要暴露Hystrix指标流,这可以通过整合Actuator并在配置文件中启用Hystrix指标流:
management:
endpoints:
web:
exposure:
include: hystrix.stream
启动应用程序后,您可以通过访问http://your-app-url/hystrix
来查看Hystrix Dashboard,并在输入框中输入您想要监控的服务的Hystrix指标流URL,例如http://your-target-service/hystrix.stream
。
随着Netflix Hystrix宣布停止开发,Spring Cloud介绍了spring-cloud-starter-circuitbreaker-resilience4j
,这是与新的断路器库Resilience4j进行整合的起步依赖,用于替代Hystrix的实现。但请注意,Resilience4j没有提供与Hystrix Dashboard类似的内置监控仪表板。
要监控Resilience4j的指标,需要使用Micrometer与外部监控系统(如Prometheus)集成,并可以与Grafana等工具结合使用,提供了创建自定义图表和仪表板的能力。
注:Spring Cloud 2020.0.0版本及之后的版本不再包括Hystrix和Hystrix Dashboard的支持。对于现在新开发的系统,建议使用Resilience4j或Spring Cloud Circuit Breaker库,并结合其他监控工具来可视化断路器的指标。