1. 概述
为了更好的监控Hystrix的性能,Spring Cloud提供Hystrix dashboard和Turbin来达到这个目的。
Hystrix dashboard可以实时监控Hystrix的运行情况。但是Hystrix dashboard只能对单台进行监控。但是在实际系统中,通常不止一个服务,为了方便监控,我们需要将多个Hystrix dashboard的数据汇总在一个dashboard中展示出来, 这个工具就是Turbine。
本文演示Hystrix dashboard和Turbine的用法
2. Hystrix dashboard
Hystrix dashboard可以实时监控Hystrix的运行情况。但是Hystrix dashboard只能对单台进行监控。
2.1. 相关工程
相关的工程说明
- cloud-registration-center:注册中心
- cloud-service-hystrix: 作为服务方的工程
- cloud-consumer-hystrix:通过Hystrix调用cloud-service-hystrix的接口
本节使用的工程和Spring cloud系列十一 @Feign集成的Hystrix进行个性化配置及集成原理相同
其中cloud-registration-center和cloud-service-hystrix完全相同,请参考上一篇文章
2.2. 配置Hystrix日志监控
以下的配置都在工程cloud-consumer-hystrix中。
为了在服务中添加Hystrix dashboard的支持,我们对cloud-consumer-hystrix进行改造(这个工程中在Spring cloud系列十一 @Feign集成的Hystrix进行个性化配置及集成原理中已经讲过,本节略),这里只列出变更的内容:
在pom.xml中增加Hystrix dashboard的依赖jar
<!-- hystrix dashboard -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- 如果提示 Unable to connect to Command Metric Stream. 则需要引入以下包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在启动类上增加@EnableCircuitBreaker注解,必须需要加上这个注解
@SpringBootApplication
@EnableFeignClients
@