溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

springcloud熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析

發(fā)布時間:2021-09-08 09:52:55 來源:億速云 閱讀:116 作者:小新 欄目:編程語言

小編給大家分享一下springcloud熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

Hystrix-dashboard是一款針對Hystrix進行實時監(jiān)控的工具,通過Hystrix Dashboard我們可以在直觀地看到各Hystrix Command的請求響應時間, 請求成功率等數(shù)據(jù)。但是只使用Hystrix Dashboard的話, 你只能看到單個應用內的服務信息, 這明顯不夠. 我們需要一個工具能讓我們匯總系統(tǒng)內多個服務的數(shù)據(jù)并顯示到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熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析

圖中會有一些提示:

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,單個應用的監(jiān)控使用最后一個,我們暫時只演示單個應用的所以在輸入框中輸入:
http://localhost:9001/hystrix.stream ,輸入之后點擊 monitor,進入頁面。

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

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

ping:

data: {"type":"HystrixCommand","name":"HelloRemote#hello(String)","group":"spring-cloud-producer","currentTime":1494915453986,"isCircuitBreakerOpen":false,"errorPercentage":100,"errorCount":1,"requestCount":1,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackMissing":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":1,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":1,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,"propertyValue_executionTimeoutInMilliseconds":1000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"spring-cloud-producer"}

data: {"type":"HystrixThreadPool","name":"spring-cloud-producer","currentTime":1494915453986,"currentActiveCount":0,"currentCompletedTaskCount":1,"currentCorePoolSize":10,"currentLargestPoolSize":1,"currentMaximumPoolSize":10,"currentPoolSize":1,"currentQueueSize":0,"currentTaskCount":1,"rollingCountThreadsExecuted":0,"rollingMaxActiveThreads":0,"rollingCountCommandRejections":0,"propertyValue_queueSizeRejectionThreshold":5,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"reportingHosts":1}

說明已經(jīng)返回了監(jiān)控的各項結果

到監(jiān)控頁面就會顯示如下圖:

springcloud熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析

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

springcloud熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析

到此單個應用的熔斷監(jiān)控已經(jīng)完成。

Turbine

在復雜的分布式系統(tǒng)中,相同服務的節(jié)點經(jīng)常需要部署上百甚至上千個,很多時候,運維人員希望能夠把相同服務的節(jié)點狀態(tài)以一個整體集群的形式展現(xiàn)出來,這樣可以更好的把握整個系統(tǒng)的狀態(tài)。 為此,Netflix提供了一個開源項目(Turbine)來提供把多個hystrix.stream的內容聚合為一個數(shù)據(jù)源供Dashboard展示。

1、添加依賴

<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.cloud</groupId>
 <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
 </dependency>
</dependencies>

2、配置文件

spring.application.name=hystrix-dashboard-turbine
server.port=8001
turbine.appConfig=node01,node02
turbine.aggregator.clusterConfig= default
turbine.clusterNameExpression= new String("default")

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
  • turbine.appConfig :配置Eureka中的serviceId列表,表明監(jiān)控哪些服務

  • turbine.aggregator.clusterConfig :指定聚合哪些集群,多個使用”,”分割,默認為default??墒褂?code>http://.../turbine.stream?cluster={clusterConfig之一}訪問

  • turbine.clusterNameExpression : 1. clusterNameExpression指定集群名稱,默認表達式appName;此時:turbine.aggregator.clusterConfig需要配置想要監(jiān)控的應用名稱;2. 當clusterNameExpression: default時,turbine.aggregator.clusterConfig可以不寫,因為默認就是default;3. 當clusterNameExpression: metadata[‘cluster']時,假設想要監(jiān)控的應用配置了eureka.instance.metadata-map.cluster: ABC,則需要配置,同時turbine.aggregator.clusterConfig: ABC

3、啟動類

啟動類添加@EnableTurbine,激活對Turbine的支持

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class DashboardApplication {

 public static void main(String[] args) {
 SpringApplication.run(DashboardApplication.class, args);
 }

}

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

4、測試

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

spring-cloud-consumer-node1項目改動如下:
application.properties文件內容

spring.application.name=node01
server.port=9001
feign.hystrix.enabled=true

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

spring-cloud-consumer-node2項目改動如下:
application.properties文件內容

spring.application.name=node02
server.port=9002
feign.hystrix.enabled=true

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

HelloRemote類修改:

@FeignClient(name= "spring-cloud-producer2", fallback = HelloRemoteHystrix.class)
public interface HelloRemote {

 @RequestMapping(value = "/hello")
 public String hello2(@RequestParam(value = "name") String name);

}

對應的HelloRemoteHystrixConsumerController類跟隨修改,具體查看代碼

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

打開eureka后臺可以看到注冊了三個服務:

springcloud熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析

訪問 http://localhost:8001/turbine.stream

返回:

: ping
data: {"reportingHostsLast10Seconds":1,"name":"meta","type":"meta","timestamp":1494921985839}

并且會不斷刷新以獲取實時的監(jiān)控數(shù)據(jù),說明和單個的監(jiān)控類似,返回監(jiān)控項目的信息。進行圖形化監(jiān)控查看,輸入:http://localhost:8001/hystrix,返回酷酷的小熊界面,輸入: http://localhost:8001/turbine.stream,然后點擊 Monitor Stream ,可以看到出現(xiàn)了倆個監(jiān)控列表

springcloud熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析

以上是“springcloud熔斷監(jiān)控Hystrix Dashboard和Turbine的示例分析”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI