天天看點

springcloud(五):熔斷監控Hystrix Dashboard和Turbine

hystrix-dashboard是一款針對hystrix進行實時監控的工具,通過hystrix dashboard我們可以在直覺地看到各hystrix command的請求響應時間, 請求成功率等資料。但是隻使用hystrix dashboard的話, 你隻能看到單個應用内的服務資訊, 這明顯不夠. 我們需要一個工具能讓我們彙總系統内多個服務的資料并顯示到hystrix dashboard上, 這個工具就是turbine.

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

這三個包必須添加

啟動類添加啟用hystrix dashboard和熔斷器

springcloud(五):熔斷監控Hystrix Dashboard和Turbine

圖中會有一些提示:

大概意思就是如果檢視預設叢集使用第一個url,檢視指定叢集使用第二個url,單個應用的監控使用最後一個,我們暫時隻示範單個應用的是以在輸入框中輸入:

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

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

springcloud(五):熔斷監控Hystrix Dashboard和Turbine
springcloud(五):熔斷監控Hystrix Dashboard和Turbine

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

在複雜的分布式系統中,相同服務的節點經常需要部署上百甚至上千個,很多時候,運維人員希望能夠把相同服務的節點狀态以一個整體叢集的形式展現出來,這樣可以更好的把握整個系統的狀态。 為此,netflix提供了一個開源項目(turbine)來提供把多個hystrix.stream的内容聚合為一個資料源供dashboard展示。

<code>turbine.appconfig</code> :配置eureka中的serviceid清單,表明監控哪些服務

<code>turbine.aggregator.clusterconfig</code> :指定聚合哪些叢集,多個使用”,”分割,預設為default。可使用<code>http://.../turbine.stream?cluster={clusterconfig之一}</code>通路

<code>turbine.clusternameexpression</code> : 1. clusternameexpression指定叢集名稱,預設表達式appname;此時:<code>turbine.aggregator.clusterconfig</code>需要配置想要監控的應用名稱;2. 當clusternameexpression: default時,<code>turbine.aggregator.clusterconfig</code>可以不寫,因為預設就是default;3. 當clusternameexpression: metadata[‘cluster’]時,假設想要監控的應用配置了<code>eureka.instance.metadata-map.cluster: abc</code>,則需要配置,同時<code>turbine.aggregator.clusterconfig: abc</code>

啟動類添加<code>@enableturbine</code>,激活對turbine的支援

到此turbine(hystrix-dashboard-turbine)配置完成

在示例項目spring-cloud-consumer-hystrix基礎上修改為兩個服務的調用者spring-cloud-consumer-node1和spring-cloud-consumer-node2

spring-cloud-consumer-node1項目改動如下:

application.properties檔案内容

spring-cloud-consumer-node2項目改動如下:

helloremote類修改:

對應的<code>helloremotehystrix</code>和<code>consumercontroller</code>類跟随修改,具體檢視代碼

修改完畢後,依次啟動spring-cloud-eureka、spring-cloud-consumer-node1、spring-cloud-consumer-node1、hystrix-dashboard-turbine(turbine)

打開eureka背景可以看到注冊了三個服務:

springcloud(五):熔斷監控Hystrix Dashboard和Turbine

傳回:

springcloud(五):熔斷監控Hystrix Dashboard和Turbine

<a href="https://github.com/ityouknow/spring-cloud-starter">示例代碼</a>

參考:

<a href="https://www.gitbook.com/book/eacdy/spring-cloud-book/details">使用spring cloud與docker實戰微服務</a>

作者:純潔的微笑

版權歸作者所有,轉載請注明出處