Hystrix断路器集群监控Turbine

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

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

引入Tuebine依赖

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-turbine</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-hystrix-dashboard</artifactId>
        </dependency>

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

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class DashboardTurbineApplication {
    public static void main(String[] args) {
        SpringApplication.run(DashboardTurbineApplication.class, args);
    }
}

最后是Turbine的配置

spring.application.name=hystrix-dashboard-turbine
server.port=8000
turbine.appConfig=consumer01,consumer02
turbine.aggregator.clusterConfig= default
turbine.clusterNameExpression= new String("default")
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的运行情况, 在出现问题的时候能够及时定位到问题所在的服务。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,009评论 19 139
  • 请先阅读之前的内容: Spring Cloud 学习笔记 - No.1 服务注册发现 Spring Cloud 学...
    专职跑龙套阅读 1,873评论 0 6
  • 软件是有生命的,你做出来的架构决定了这个软件它这一生是坎坷还是幸福。 本文不是讲解如何使用Spring Cloud...
    Bobby0322阅读 22,733评论 3 166
  • 他们俩怎么还不结婚 哈哈哈哈哈哈哈哈哈哈哈想画h 原图在这 帅出血
    lwwwwhh阅读 299评论 0 3
  • 横波媚眼泄春光, 带露红唇醉酒妆。 素手难能描艳骨, 丹青何解画皮囊。 从来美貌三分态, 自古风流两段香。 可笑闺...
    莫愁Jessie阅读 183评论 0 3