Spring Cloud(九)断路器聚合仪表盘(Hystrix Turbine)

一、使用Turbine聚合监控数据

前面使用的/hystrix.stream端点监控单个微服务。然而在使用微服务架构的应用系统一般会包含多个微服务,每个微服务通常都会部署多个实例。如果每次只能查看单个实例的监控数据,就必须在Hystrix Dashboard上切换想要监控的地址,这显然很不方便

1.1 Turbine简介

Turbine是一个聚合Hystrix监控数据的工具,它可将所有相关/hystrix.stream端点的数据聚合到一个组合的/turbine.stream中,从而让集群的监控更加方便。

1.2 Turbine结构图

在这里插入图片描述

二、使用Turbine监控一个集群环境

新建turbine-server服务

2.1 pom添加turbine依赖

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>

2.2 更改启动类

添加EnableTurbine注解

@SpringBootApplication
@EnableEurekaClient
@EnableTurbine
public class TurbineServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(TurbineServerApplication.class, args);
	}
}

2.3 更改配置

server.port=8085
spring.application.name=turbine-server
eureka.client.service-url.defaultZone = http://localhost:8080/eureka/

## 表示要聚合的名称 多个用逗号隔开
turbine.app-config=ribbon-consumer
# turbine(说明:注意必须为大写,因为 eureka 返回的值都是大写的)
turbine.aggregator.clusterConfig=RIBBON-CONSUMER

2.4 结果

依次启动Eureka-server,ribbon-consumer(8083),ribbon-consumer(8084),turbine-server(8085),eureka-client(8081)
访问:http://localhost:8085/turbine.stream?cluster=RIBBON-CONSUMER
在这里插入图片描述
访问:http://localhost:8084/hystrix/或者http://localhost:8085/hystrix/,
输入turbine.stream路径,并指定cluster
在这里插入图片描述

在这里插入图片描述

具体的含义说明可以查看上一章,具体说明

三、使用Turbine监控多个集群环境

3.1 更改turbine-server配置文件

server.port=8085
spring.application.name=turbine-server
eureka.client.service-url.defaultZone = http://localhost:8080/eureka/

## 表示要聚合的名称 多个用逗号隔开
#turbine.app-config=ribbon-consumer
## turbine(说明:注意必须为大写,因为 eureka 返回的值都是大写的)
#turbine.aggregator.clusterConfig=RIBBON-CONSUMER

###监控多个集群环境
turbine.app-config=ribbon-consumer,ribbon-consumer2
turbine.aggregator.cluster-config=Turbine
turbine.cluster-name-expression=metadata['cluster']

3.2 更改ribbon-consumer配置文件

添加如下配置

eureka.instance.metadata-map.cluster=Turbine

3.3 测试

依次启动Eureka-server,ribbon-consumer(ribbon-consumer:8083),ribbon-consumer(ribbon-consumer:8084),ribbon-consumer(ribbon-consumer2:8086);turbine-server(8085),eureka-client(8081)
http://localhost:8085/turbine.stream?cluster=Turbine (注意cluster参数变化)
在这里插入图片描述
在这里插入图片描述

四、使用Turbine监控所有应用

修改:turbine.cluster-name-expression=‘default’
禁用:# turbine.aggregator.clusterConfig=Turbine

turbine.app-config=ribbon-consumer,ribbon-consumer2
turbine.cluster-name-expression='default'

http://localhost:8085/turbine.stream
在这里插入图片描述

在这里插入图片描述

GitHub项目地址:https://github.com/PayneYu/spring-cloud-study

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值