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 文件导入以下依赖:

  
  
  1. <dependency>
  2. <groupId>org.springframework.cloud </groupId>
  3. <artifactId>spring-cloud-starter-netflix-turbine </artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.cloud </groupId>
  7. <artifactId>spring-cloud-starter-netflix-hystrix-dashboard </artifactId>
  8. </dependency>
  9. <dependency>
  10. <groupId>org.springframework.boot </groupId>
  11. <artifactId>spring-boot-starter-actuator </artifactId>
  12. </dependency>
3. 启动类,添加注解 @EnableTurbine

  
  
  1. @SpringBootApplication
  2. @EnableHystrixDashboard
  3. @EnableTurbine
  4. public class HystrixDashboardTurbineApplication {
  5. public static void main(String[] args) {
  6. SpringApplication.run(HystrixDashboardTurbineApplication.class, args);
  7. }
  8. }
4. 配置文件:

  
  
  1. server:
  2. port: 8581
  3. spring:
  4. application:
  5. name: spring-cloud-hystrix-dashboard-turbine
  6. turbine:
  7. # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
  8. app-config: SPRING-DEMO-SERVICE-FEIGN,SPRING-DEMO-SERVICE-RIBBON
  9. aggregator:
  10. cluster-config: default
  11. # 指定集群名称
  12. cluster-name-expression: "'default'"
  13. eureka:
  14. client:
  15. service-url:
  16. defaultZone: http: //localhost:8761/eureka/
  17. management:
  18. endpoints:
  19. web:
  20. exposure:
  21. include: '*'
  22. endpoint:
  23. health:
  24. 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
转载自:https://blog.csdn.net/hubo_88/article/details/80623032

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值