Spring Cloud 应用篇 之 Hystrix Turbine(断路器聚合监控)的基本搭建

在讲解了 Hystrix Dashboard 之后,我们知道了,Hystrix Dashboard 实现的是单节点模式,一次只能监控一个服务,当有很多服务的时候,这样单节点模式去监控,就需要打开多个浏览器窗口,显然这是很麻烦的。这个时候,我们就可以用到 Spring Cloud 的另一个组件 Turbine,它可以聚合多个服务的 Hystrix Dashboard 的数据用以显示。

(一)简介

Turbine 可以聚合多个服务的 Hystrix Dashboard 的数据在一个浏览器窗口中显示,关于 Turbine 的搭建也是非常简单。

(二)搭建环境

1. 创建一个 module(spring-cloud-hystrix-dashboard-turbine)

创建步骤可以参考之前的文章(这个环境也可以在 spring-cloud-hystrix-dashboard 的基础进行改造,为了防止代码产生混乱,就新建一个 module)

2. Hystrix Dashboard 是个独立的服务,可以不注册到 eureka server,但是 Turbine 是聚合多个服务,通过服务实例 id 聚合,所以它要注册到 eureka server 中,获取服务列表,用以聚合监控。pom 文件导入以下依赖:
<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-dashboard</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
3. 启动类,添加注解 @EnableTurbine
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class HystrixDashboardTurbineApplication {

    public static void main(String[] args) {

        SpringApplication.run(HystrixDashboardTurbineApplication.class, args);
    }
}
4. 配置文件:
server:
  port: 8581

spring:
  application:
    name: spring-cloud-hystrix-dashboard-turbine

turbine:
  # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
  app-config: SPRING-DEMO-SERVICE-FEIGN,SPRING-DEMO-SERVICE-RIBBON
  aggregator:
    cluster-config: default
  # 指定集群名称
  cluster-name-expression: "'default'"

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/


management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
      health:
        show-details: ALWAYS
5. 依次启动 eureka server、spring-demo-service、spring-demo-service-feign、spring-demo-service-ribbon、spring-demo-service-ribbon、spring-cloud-hystrix-dashboard-turbine,访问 http://localhost:8581/hystrix,界面和 Hystrix Dashboard 的界面一致


输入 http://localhost:8581/turbine.stream(在此之前为了不出现 Loading... 状态,提前访问被监控的服务接口,调用一次即可),点击 Monitor Stream


可以看到 spring-demo-service-ribbon 和 spring-demo-service-feign 两个服务的 Hystrix Dashboard 的数据已经被聚合到这一个界面中。

源码下载:https://github.com/shmilyah/spring-cloud-componets

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值