springcloud(五):熔斷監控Hystrix Dashboard

明理蘿發表於2018-11-28

Hystrix-dashboard是一款針對Hystrix進行實時監控的工具,通過Hystrix Dashboard我們可以在直觀地看到各Hystrix Command的請求響應時間, 請求成功率等資料。但是隻使用Hystrix Dashboard的話, 你只能看到單個應用內的服務資訊, 這明顯不夠. 我們需要一個工具能讓我們彙總系統內多個服務的資料並顯示到Hystrix Dashboard上, 這個工具就是Turbine.願意瞭解原始碼的朋友直接求求交流分享技術:二一四七七七五六三三

Hystrix Dashboard 我們在熔斷示例專案spring-cloud-consumer-hystrix的基礎上更改,重新命名為:spring-cloud-consumer-hystrix-dashboard。

1、新增依賴

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
複製程式碼

這三個包必須新增

2、啟動類 啟動類新增啟用Hystrix Dashboard和熔斷器

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ConsumerApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(ConsumerApplication.class, args);
	}
}
複製程式碼

3、測試 啟動工程後訪問 http://localhost:9001/hystrix,將會看到如下介面:

springcloud(五):熔斷監控Hystrix Dashboard
圖中會有一些提示:

Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream 
Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
Single Hystrix App: http://hystrix-app:port/hystrix.stream
複製程式碼

大概意思就是如果檢視預設叢集使用第一個url,檢視指定叢集使用第二個url,單個應用的監控使用最後一個,我們暫時只演示單個應用的所以在輸入框中輸入: http://localhost:9001/hystrix.stream ,輸入之後點選 monitor,進入頁面。

如果沒有請求會先顯示Loading ...,訪問http://localhost:9001/hystrix.stream 也會不斷的顯示ping。

請求服務http://localhost:9001/hello/neo,就可以看到監控的效果了,首先訪問http://localhost:9001/hystrix.stream,顯示如下:

ping: 
 
data: {"type":...}
 
data: {"type":...}
複製程式碼

說明已經返回了監控的各項結果

到監控頁面就會顯示如下圖:

springcloud(五):熔斷監控Hystrix Dashboard
其實就是http://localhost:9001/hystrix.stream返回結果的圖形化顯示,Hystrix Dashboard Wiki上詳細說明了圖上每個指標的含義,如下圖:

springcloud(五):熔斷監控Hystrix Dashboard

到此單個應用的熔斷監控已經完成。 資料和原始碼來源

技術架構圖如下:

springcloud(五):熔斷監控Hystrix Dashboard

相關文章