上一篇文章講述瞭如何利用Hystrix Dashboard去監控斷路器的Hystrix command。當咱們有不少個服務的時候,這就須要聚合因此服務的Hystrix Dashboard的數據了。這就須要用到Spring Cloud的另外一個組件了,即Hystrix Turbine。web
1、Hystrix Turbine簡介
看單個的Hystrix Dashboard的數據並無什麼多大的價值,要想看這個系統的Hystrix Dashboard數據就須要用到Hystrix Turbine。瞭解springcloud架構能夠加求求:三五三六二四七二五九,Hystrix Turbine將每一個服務Hystrix Dashboard數據進行了整合。Hystrix Turbine的使用很是簡單,只須要引入相應的依賴和加上註解和配置就能夠了。spring
2、準備工做
本文使用的工程爲上一篇文章的工程,在此基礎上進行改造。由於咱們須要多個服務的Dashboard,因此須要再建一個服務,取名爲service-lucy,它的基本配置同service-hi,具體見源碼,在這裏就不詳細說明。瀏覽器
3、建立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註解,即開啓了註冊服務。app
@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:cors
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
配置文件註解寫的很清楚。分佈式
4、Turbine演示
依次開啓eureka-server、service-hi、service-lucy、service-turbine工程。ide
打開瀏覽器輸入:http://localhost:8764/turbine.stream,界面以下:
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-Mprwy3z2-1569837780939)(https://img-blog.csdn.net/20170416135735474?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9yZXpw/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)]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 進入頁面: