上一篇文章講述瞭如何利用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:8763/hystrix,輸入監控流http://localhost:8764/turbine.stream
點擊monitor stream 進入頁面:
可以看到這個頁面聚合了2個service的hystrix dashbord數據。
http://blog.csdn.net/forezp/article/details/81041125
本文出自方誌朋的博客