1、原因
在微服务架构体系中,每个服务都需要配置Hystrix DashBoard监控。如果每次只能查看单个实例的监
控数据,就需要不断切换监控地址,这显然很不方便。要想看这个系统的Hystrix Dashboard数据就需
要用到Hystrix Turbine。Turbine是一个聚合Hystrix 监控数据的工具,他可以将所有相关微服务的
Hystrix 监控数据聚合到一起,方便使用。引入Turbine后,整个监控系统架构如下:
2、搭建TurbineServer
创建工程 shop_hystrix_turbine 引入相关坐标
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
3、 配置多个微服务的hystrix监控
在application.yml的配置文件中开启turbine并进行相关配置
server:
port: 8031
spring:
application:
name: hystrix-turbine
eureka:
client:
service-url:
defaultZone: http://localhost:9000/eureka/
instance:
prefer-ip-address: true
turbine:
# 要监控的微服务列表,多个用,分隔
appConfig: service-order
clusterNameExpression: "'default'"
eureka相关配置 : 指定注册中心地址
turbine相关配置:指定需要监控的微服务列表
turbine会自动的从注册中心中获取需要监控的微服务,并聚合所有微服务中的 /hystrix.stream 数据
4、配置启动类
@SpringBootApplication
//trubin配置
@EnableTurbine
@EnableHystrixDashboard
public class TurbinAppliation {
public static void main(String[] args) {
SpringApplication.run(TurbinAppliation.class,args);
}
}
作为一个独立的监控项目,需要配置启动类,开启HystrixDashboard监控平台,并激活Turbine
5、测试
浏览器访问 http://localhost:8031/hystrix 展示HystrixDashboard。并在url位置输入 http://local
host:8031/turbine.stream,动态根据turbine.stream数据展示多个微服务的监控数据