Hystrix断路器集群监控Turbine

柔情只为你懂 2022-05-16 11:37 306阅读 0赞

Netflix Hystrix 可以为应用程序中的命令状态提供实时指标。这些数据通过一个名为Hystrix Dashboard的非常酷的界面以图形形式展现出来。但是它只能提供单个服务的信息,如果需要调用几十个微服务,我们希望看到的是这些微服务的性能,而不是一个微服务一个微服务的去查看。所以我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上,使用Turbine可以做到这一点。

将Turbine集成到基于Spring-Cloud的应用中非常简单,只需要像以前一样拉入Turbine的依赖,定义好要集群哪些公开信息以及如何汇总有关特定集群的信息。

引入Tuebine依赖

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-turbine</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.cloud</groupId>
  7. <artifactId>spring-cloud-netflix-turbine</artifactId>
  8. </dependency>
  9. <dependency>
  10. <groupId>org.springframework.boot</groupId>
  11. <artifactId>spring-boot-starter-actuator</artifactId>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.springframework.cloud</groupId>
  15. <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
  16. </dependency>

在基于Spring Boot的应用程序中启用Turbine支持

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

最后是Turbine的配置

  1. spring.application.name=hystrix-dashboard-turbine
  2. server.port=8000
  3. turbine.appConfig=consumer01,consumer02
  4. turbine.aggregator.clusterConfig= default
  5. turbine.clusterNameExpression= new String("default")
  6. eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8888/eureka}
  • turbine.appConfig :配置Eureka中的serviceId列表,表明监控哪些服务
  • turbine.aggregator.clusterConfig :配置集群的名字,也就是cluster。在Hystrix
    Dashboard中,使用http://turbine-hostname:port/turbine.stream?cluster=[clusterName]来查看这个集群对应的服务的HystrixCommand信息。默认为default。
  • turbine.clusterNameExpression : 是一个Spring表达式语言,用于获取集群的名称。默认是appName。

    在本例中监控了2个微服务:consumer01,consumer02。
    两个微服务的配置如下

    spring.application.name=consumer01
    server.port=8080

    feign.hystrix.enabled=true
    eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8888/eureka}

    spring.application.name=consumer02
    server.port=8082
    feign.hystrix.enabled=true

    eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8888/eureka}

依次启动Eureka服务注册中心,微服务和Turbine后,访问localhost:8000/hystrix.也就是turbine对应的hystrix。Hystrix Stream输入http://localhost:8000/turbine.stream。分别访问两个业务服务,就可以在dashboard中看到他们的Hystrix Command信息了。
这里写图片描述

通过Hystrix Dashboard和Turbine, 我们能够很方便地监控每个Hystrix的运行情况, 在出现问题的时候能够及时定位到问题所在的服务。

发表评论

表情:
评论列表 (有 0 条评论,306人围观)

还没有评论,来说两句吧...

相关阅读