springcloud(五):熔斷監控Hystrix Dashboard

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章