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

上一篇文章講述瞭如何利用Hystrix Dashboard去監控斷路器的Hystrix command。當咱們有不少個服務的時候,這就須要聚合因此服務的Hystrix Dashboard的數據了。這就須要用到Spring Cloud的另外一個組件了,即Hystrix Turbine。html

1、Hystrix Turbine簡介

看單個的Hystrix Dashboard的數據並無什麼多大的價值,要想看這個系統的Hystrix Dashboard數據就須要用到Hystrix Turbine。Hystrix Turbine將每一個服務Hystrix Dashboard數據進行了整合。Hystrix Turbine的使用很是簡單,只須要引入相應的依賴和加上註解和配置就能夠了。git

2、準備工做

本文使用的工程爲上一篇文章的工程,在此基礎上進行改造。由於咱們須要多個服務的Dashboard,因此須要再建一個服務,取名爲service-lucy,它的基本配置同service-hi,具體見源碼,在這裏就不詳細說明。github

3、建立service-turbine

引入相應的依賴:web

 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註解,即開啓了註冊服務。spring

 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     

配置文件註解寫的很清楚。微信

4、Turbine演示

依次開啓eureka-server、service-hi、service-lucy、service-turbine工程。app

打開瀏覽器輸入:http://localhost:8764/turbine.stream,界面以下:cors

這裏寫圖片描述

依次請求:spring-boot

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

5、參考文獻

hystrix_dashboard

turbine

業餘草微信公衆號

感謝您的關注!可加QQ1羣:135430763,QQ2羣:454796847,QQ3羣:187424846。QQ羣進羣密碼:xttblog,想加微信羣的朋友,能夠微信搜索:xmtxtt,備註:「xttblog」,添加助理微信拉你進羣。備註錯誤不會贊成好友申請。再次感謝您的關注!後續有精彩內容會第一時間發給您!原創文章投稿請發送至532009913@qq.com郵箱。商務合做可添加助理微信進行溝通!

相關文章
相關標籤/搜索