天天看點

業餘草 SpringCloud教程 | 第十二篇: 斷路器聚合監控(Hystrix Turbine)(Finchley版本)

版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 https://blog.csdn.net/xmt1139057136/article/details/81414045

上一篇文章講述了如何利用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

引入相應的依賴:

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

    </dependencies>

           

在其入口類ServiceTurbineApplication加上注解@EnableTurbine,開啟turbine,@EnableTurbine注解包含了@EnableDiscoveryClient注解,即開啟了注冊服務。

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@RestController
@EnableHystrix
@EnableHystrixDashboard
@EnableCircuitBreaker
@EnableTurbine
public class ServiceTurbineApplication {

    /**
     * http://localhost:8764/turbine.stream
     */

    public static void main(String[] args) {
        SpringApplication.run( ServiceTurbineApplication.class, args );
    }
}

           

配置檔案application.yml:

server:
  port: 8764

spring:
  application:
    name: service-turbine

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
management:
  endpoints:
    web:
      exposure:
        include: "*"
      cors:
        allowed-origins: "*"
        allowed-methods: "*"

turbine:
  app-config: service-hi,service-lucy
  aggregator:
    clusterConfig: default
  clusterNameExpression: new String("default")
  combine-host: true
  instanceUrlSuffix:
    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

,輸入監控流

點選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

”,添加助理微信拉你進群。備注錯誤不會同意好友申請。再次感謝您的關注!後續有精彩内容會第一時間發給您!原創文章投稿請發送至[email protected]郵箱。商務合作可添加助理微信進行溝通!

繼續閱讀