第四篇讲述了如何利用Hystrix Dashboard去监控熔断器的Hystrix command。当我们有很多个服务的时候, 需要聚合所有服务的Hystrix Dashboard 数据。此时 就需要用到Spring Cloud的另一个组件了,即Hystrix Turbine。本篇既是第四篇SpringCloud (第四篇)整合熔断器Hystrix及熔断器监控Dashboard 的延伸。
一、Hystrix Turbine 简介
在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。
一、 Hystrix Turbine 使用
在使用 Hystrix Turbine 功能时,需要子模块cloud_eureka_01,cloud_eureka_hystrix_02的配合,因为需要多个Hystrix Dashboard的配合,可再新建一个服务 ,取名为: cloud_eureka_hystrix_01,其配置基本和cloud_eureka_hystrix_02 相同。 也可启动子模块 cloud_eureka_client_01 (服务提供者)进行配合(非必须)。
因此需要新建的服务有:
cloud_eureka_hystrix_01
cloud_18_hystrix_turbine
两个子模块。
1. 新建cloud_eureka_hystrix_01子模块
其基本结构和cloud_eureka_hystrix_02 模块相同,只需修改端口号,配置文件等,此处不再演示。
2.新建 cloud_18_hystrix_turbine子模块
1. 修改 父子模块的依赖
<!--在父模块中引入子模块-->
<modules>
<module>cloud_17_sleuth_client</module>
<module>cloud_18_hystrix_turbine</module>
</modules>
<!--在子模块中引入父模块依赖-->
<parent>
<groupId>com.yaogx</groupId>
<artifactId>SpringCloudParent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
2. 添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
3.添加配置文件
server:
port: 9110
spring:
application:
name: service-turbine
eureka:
client:
serviceUrl:
defaultZone: http://localhost:9090/eureka/
management:
endpoints:
web:
exposure:
include: "*"
cors:
allowed-origins: "*"
allowed-methods: "*"
turbine:
# 添加 Hystrix Dashboard 服务的 配置文件中的应用名
app-config:service-hystrix ,service-hystrix_01
aggregator:
clusterConfig: default
clusterNameExpression: new String("default")
combine-host: true
instanceUrlSuffix:
default: actuator/hystrix.stream
4. 在启动类上添加注释
@EnableTurbine
@SpringBootApplication
public class CloudTurbineApplication {
public static void main(String[] args) {
SpringApplication.run(CloudTurbineApplication.class, args);
}
}
3. 启动测试
依次启动:cloud_eureka_01,cloud_eureka_hystrix_01,cloud_eureka_hystrix_02 ,cloud_18_hystrix_turbine 子模块。
1. 在浏览器地址栏输入:http://127.0.0.1:9090/

2. 在浏览器地址栏输入 : http://127.0.0.1:9092/hello/albert

注:这里有一个细节需要小伙伴们注意:要访问/hystrix.stream接口,得先访问cloud_eureka_hystrix_01工程中的任意一个其他接口,否则如果直接访问/hystrix.stream接口的话,会打印出一连串的ping: ping: …。
3.在浏览器地址栏输入 : http://127.0.0.1:9110/turbine.stream

4.在浏览器地址栏输入 : http://127.0.0.1:9092/hystrix

5. 操作 Hystrix Dashboard 页面
在 Hystrix Dashboard 中输入监控流http://localhost:8764/turbine.stream 。

点击 monitor stream 进入页面:


参考博客:https://blog.csdn.net/forezp/article/details/70148833
至此SpringCloud的 一些常用组件已整合完成,其他组件后续更新。。。
如有不正确之处,请指出,谢谢!