• 业余草 SpringCloud教程 | 第十二篇: 断路器聚合监控(Hystrix Turbine)(Finchley版本)


    上一篇文章讲述了如何利用Hystrix Dashboard去监控断路器的Hystrix command。当我们有很多个服务的时候,这就需要聚合所以服务的Hystrix Dashboard的数据了。这就需要用到Spring Cloud的另一个组件了,即Hystrix Turbine。

    一、Hystrix Turbine简介

    看单个的Hystrix Dashboard的数据并没有什么多大的价值,要想看这个系统的Hystrix Dashboard数据就需要用到Hystrix Turbine。Hystrix Turbine将每个服务Hystrix Dashboard数据进行了整合。Hystrix Turbine的使用非常简单,只需要引入相应的依赖和加上注解和配置就可以了。

    二、准备工作

    本文使用的工程为上一篇文章的工程,在此基础上进行改造。因为我们需要多个服务的Dashboard,所以需要再建一个服务,取名为service-lucy,它的基本配置同service-hi,具体见源码,在这里就不详细说明。

    三、创建service-turbine

    引入相应的依赖:

     1  <dependencies>
     2         <dependency>
     3             <groupId>org.springframework.cloud</groupId>
     4             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
     5         </dependency>
     6         <dependency>
     7             <groupId>org.springframework.boot</groupId>
     8             <artifactId>spring-boot-starter-web</artifactId>
     9         </dependency>
    10         <dependency>
    11             <groupId>org.springframework.boot</groupId>
    12             <artifactId>spring-boot-starter-actuator</artifactId>
    13         </dependency>
    14         <dependency>
    15             <groupId>org.springframework.cloud</groupId>
    16             <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    17         </dependency>
    18         <dependency>
    19             <groupId>org.springframework.cloud</groupId>
    20             <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    21         </dependency>
    22         <dependency>
    23             <groupId>org.springframework.cloud</groupId>
    24             <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
    25         </dependency>
    26  
    27     </dependencies>

    在其入口类ServiceTurbineApplication加上注解@EnableTurbine,开启turbine,@EnableTurbine注解包含了@EnableDiscoveryClient注解,即开启了注册服务。

     1  
     2 @SpringBootApplication
     3 @EnableEurekaClient
     4 @EnableDiscoveryClient
     5 @RestController
     6 @EnableHystrix
     7 @EnableHystrixDashboard
     8 @EnableCircuitBreaker
     9 @EnableTurbine
    10 public class ServiceTurbineApplication {
    11  
    12     /**
    13      * http://localhost:8764/turbine.stream
    14      */
    15  
    16     public static void main(String[] args) {
    17         SpringApplication.run( ServiceTurbineApplication.class, args );
    18     }
    19 }

    配置文件application.yml:

     1 server:
     2   port: 8764
     3  
     4 spring:
     5   application:
     6     name: service-turbine
     7  
     8 eureka:
     9   client:
    10     serviceUrl:
    11       defaultZone: http://localhost:8761/eureka/
    12 management:
    13   endpoints:
    14     web:
    15       exposure:
    16         include: "*"
    17       cors:
    18         allowed-origins: "*"
    19         allowed-methods: "*"
    20  
    21 turbine:
    22   app-config: service-hi,service-lucy
    23   aggregator:
    24     clusterConfig: default
    25   clusterNameExpression: new String("default")
    26   combine-host: true
    27   instanceUrlSuffix:
    28     default: actuator/hystrix.stream     

    配置文件注解写的很清楚。

    四、Turbine演示

    依次开启eureka-server、service-hi、service-lucy、service-turbine工程。

    打开浏览器输入:http://localhost:8764/turbine.stream,界面如下:

    这里写图片描述

    依次请求:

    http://localhost:8762/hi?name=forezp

    http://localhost:8763/hi?name=forezp

    打开:http://localhost:8763/hystrix,输入监控流http://localhost:8764/turbine.stream

    这里写图片描述

    点击monitor stream 进入页面:

    这里写图片描述

    可以看到这个页面聚合了2个service的hystrix dashbord数据。

    源码下载: 
    https://github.com/forezp/SpringCloudLearning/tree/master/sc-f-chapter13

    五、参考文献

    hystrix_dashboard

    turbine

    业余草微信公众号

    感谢您的关注!可加QQ1群:135430763,QQ2群:454796847,QQ3群:187424846。QQ群进群密码:xttblog,想加微信群的朋友,可以微信搜索:xmtxtt,备注:“xttblog”,添加助理微信拉你进群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作可添加助理微信进行沟通!

  • 相关阅读:
    CSS 权威指南 CSS实战手册 第四版(阅读笔记)
    iframe交互(一)父页面自动高度
    连接微服务
    学习SQLYog
    sourceTree的安装以及破解
    sql 根据子级ID获取所有父级
    新手Python入门安装(一)
    C# 真正完美的 汉字转拼音
    供应链相关的书和博客
    网易跟帖为什么火
  • 原文地址:https://www.cnblogs.com/panda2/p/9419557.html
Copyright © 2020-2023  润新知