講述瞭如何利用Hystrix Dashboard去監控斷路器的Hystrix command。當咱們有不少個服務的時候,這就須要聚合因此服務的Hystrix Dashboard的數據了。這就須要用到Spring Cloud的另外一個組件了,即Hystrix Turbine。html
看單個的Hystrix Dashboard的數據並無什麼多大的價值,要想看這個系統的Hystrix Dashboard數據就須要用到Hystrix Turbine。Hystrix Turbine將每一個服務Hystrix Dashboard數據進行了整合。Hystrix Turbine的使用很是簡單,只須要引入相應的依賴和加上註解和配置就能夠了。git
本文使用的工程爲上一篇文章的工程,在此基礎上進行改造。由於咱們須要多個服務的Dashboard,因此須要再建一個服務,取名爲service-lucy,它的基本配置同service-hi,具體見源碼,在這裏就不詳細說明。github
引入相應的依賴:web
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
|
在其入口類ServiceTurbineApplication加上註解@EnableTurbine,開啓turbine,@EnableTurbine註解包含了@EnableDiscoveryClient註解,即開啓了註冊服務。spring
1
2
3
4
5
6
7
8
9
|
@SpringBootApplication
@EnableTurbine
public
class
ServiceTurbineApplication {
public
static
void
main(String[] args) {
new
SpringApplicationBuilder(ServiceTurbineApplication.
class
).web(
true
).run(args);
}
}
|
配置文件application.yml:瀏覽器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
spring:
application.name: service-turbine
server:
port:
8769
security.basic.enabled:
false
turbine:
aggregator:
clusterConfig:
default
# 指定聚合哪些集羣,多個使用
","
分割,默認爲
default
。可以使用http:
//.../turbine.stream?cluster={clusterConfig之一}訪問
appConfig: service-hi,service-lucy ### 配置Eureka中的serviceId列表,代表監控哪些服務
clusterNameExpression:
new
String(
"default"
)
#
1
. clusterNameExpression指定集羣名稱,默認表達式appName;此時:turbine.aggregator.clusterConfig須要配置想要監控的應用名稱
#
2
. 當clusterNameExpression:
default
時,turbine.aggregator.clusterConfig能夠不寫,由於默認就是
default
#
3
. 當clusterNameExpression: metadata[
'cluster'
]時,假設想要監控的應用配置了eureka.instance.metadata-map.cluster: ABC,則須要配置,同時turbine.aggregator.clusterConfig: ABC
eureka:
client:
serviceUrl:
defaultZone: http:
//localhost:8761/eureka/
|
配置文件註解寫的很清楚。架構
依次開啓eureka-server、service-hi、service-lucy、service-turbine工程。app
打開瀏覽器輸入:http://localhost:8769/turbine.stream,界面以下:分佈式
依次請求:spring-boot
1
2
3
|
http:
//localhost:8762/hi?name=forezp
http:
//localhost:8763/hi?name=forezp
|
架構代碼以下:
Spring Cloud大型企業分佈式微服務雲架構源碼請加企鵝求求:一七九一七四三三八零