springcloud(五):熔斷監控Hystrix Dashboard

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

Hystrix Dashboard
咱們在熔斷示例項目spring-cloud-consumer-hystrix的基礎上更改,從新命名爲:spring-cloud-consumer-hystrix-dashboard。架構

一、添加依賴app

<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>

這三個包必須添加spring-boot

二、啓動類
啓動類添加啓用Hystrix Dashboard和熔斷器工具

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

三、測試
啓動工程後訪問 http://localhost:9001/hystrix,將會看到以下界面:測試

圖中會有一些提示:ui

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,進入頁面。url

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

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

ping: 
 
data: {"type":...}
 
data: {"type":...}

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

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

其實就是http://localhost:9001/hystrix.stream返回結果的圖形化顯示,Hystrix Dashboard Wiki上詳細說明了圖上每一個指標的含義,以下圖:

到此單個應用的熔斷監控已經完成。

技術架構圖以下:

 

相關文章
相關標籤/搜索