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

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,將會看到如下界面:

hystrix-dashboard-1.jpg

圖中會有一些提示:

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":"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}

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

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

hystrix-dashboard-2.jpg

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

hystrix-dashboard-3.png

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


Turbine

在復雜的分布式系統中,相同服務的節點經常需要部署上百甚至上千個,很多時候,運維人員希望能夠把相同服務的節點狀態以一個整體集群的形式展現出來,這樣可以更好的把握整個系統的狀態。 為此,Netflix提供了一個開源項目(Turbine)來提供把多個hystrix.stream的內容聚合為一個數據源供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列表,表明監控哪些服務
  • turbine.aggregator.clusterConfig :指定聚合哪些集群,多個使用","分割,默認為default。可使用http://.../turbine.stream?cluster={clusterConfig之一}訪問
  • turbine.clusterNameExpression : 1. clusterNameExpression指定集群名稱,默認表達式appName;此時:turbine.aggregator.clusterConfig需要配置想要監控的應用名稱;2. 當clusterNameExpression: default時,turbine.aggregator.clusterConfig可以不寫,因為默認就是default;3. 當clusterNameExpression: metadata['cluster']時,假設想要監控的應用配置了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=trueeureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

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

spring.application.name=node02
server.port=9002
feign.hystrix.enabled=trueeureka.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后臺可以看到注冊了三個服務:

turbine-01.jpg

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

返回:

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

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

turbine-02.jpg

示例代碼



參考:

使用Spring Cloud與Docker實戰微服務


作者:純潔的微笑
出處:http://www.ityouknow.com/
版權歸作者所有,轉載請注明出處

轉載于:https://www.cnblogs.com/ityouknow/p/6889059.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/258674.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/258674.shtml
英文地址,請注明出處:http://en.pswp.cn/news/258674.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何修改PKG_CONFIG_PATH環境變量

兩種情況&#xff0c;如果你只是想加上某庫的pkg&#xff0c;則選擇下面其一&#xff1a;export PKG_CONFIG_PATH/usr/lib/pkgconfig/ 或者 export PKG_CONFIG_LIBDIR/usr/lib/pkgconfig/ 如果你想覆蓋掉原來的pkg,選擇后者。因為&#xff1a;PKG_CONFIG_LIBDIR的優先級比 PKG_…

python跨包導入包_python引入跨模塊包

人生苦短&#xff0c;我學python。最近學習python&#xff0c;由于包的模塊分的比較多。所以要用到跨模塊引入 且調用中間的方法整體目錄結構如下。需求&#xff1a;在 API模塊 user.py 中 調用 plugin 模塊中 douyin_login 下的方法。貼一下最終解決方案&#xff1a;from plug…

jdk1.8版本已經不包含jdbc.odbc連接

連接access的時候發現報錯&#xff0c;無法加載jdbc.odbc類文件&#xff0c;到Java安裝目錄上jre/lib/rt.jar上找jdbcodbc類也沒有了。 找個jdk1.7安裝就ok啦。轉載于:https://www.cnblogs.com/dohn/p/3707254.html

位運算問題

位運算 位運算是把數字用二進制表示之后&#xff0c;對每一位上0或者1的運算。 理解位運算的第一步是理解二進制。二進制是指數字的每一位都是0或者1.比如十進制的2轉化為二進制之后就是10。在程序員的圈子里有一個流傳了很久的笑話&#xff0c;說世界上有10種人&#xff0c;一…

conda環境管理介紹

我們可以使用conda 來切換不同的環境&#xff0c;主要的用法如下&#xff1a; 1. 創建環境 # 指定python版本為2.7&#xff0c;注意至少需要指定python版本或者要安裝的包 # 后一種情況下&#xff0c;自動安裝最新python版本conda create -n env_name python2.7# 同時安裝必…

unable to execute dex: multiple dex files Cocos2dxAccelerometer

原文轉載&#xff1a;http://discuss.cocos2d-x.org/t/conversion-to-dalvik-format-failed-unable-to-execute-dex-multiple-dex-files-define-lorg-cocos2dx-lib-cocos2dxaccelerometer/6652/4 用cocos2dx2.2.3沒問題&#xff0c;用了3.1.1出現這個問題。確實夠蛋疼。還要有這…

PHP javascript 值互相引用(不用刷新頁面)

PHP javascript 值互相引用的問題 昨天通過EMAIL給一些公司投了簡歷&#xff0c;希望他們能給我一份工作&#xff0c;今天其中一家公司的人給我打電話&#xff0c;大意是要我做一點東西&#xff08;與AJAX有關&#xff09; 給他們看&#xff0c;我聽打電話的人問我的問題&#…

mysql自增_面試官:為什么 MySQL 的自增主鍵不單調也不連續?

為什么這么設計(Why’s THE Design)是一系列關于計算機領域中程序設計決策的文章&#xff0c;我們在這個系列的每一篇文章中都會提出一個具體的問題并從不同的角度討論這種設計的優缺點、對具體實現造成的影響。如果你有想要了解的問題&#xff0c;可以在文章下面留言。當我們在…

caffe 初學參考鏈接

最近在學習caffe&#xff0c;也搜集了一些資料&#xff0c;主要是一些網上公開的博客資源&#xff0c;現匯總一下&#xff0c;以便后面參考。 caffe 安裝 編譯py-faster-rcnn全過程caffe依賴庫安裝&#xff08;非root&#xff09;編譯py-faster-rcnn的問題匯總及解決方法 ca…

java timer 定時任務

監聽類1 package com.xx.model;2 3 import java.util.Calendar;4 import java.util.Date;5 import java.util.Timer;6 import javax.servlet.ServletContextEvent;7 import javax.servlet.ServletContextListener;8 import org.apache.commons.logging.Log;9 import org.apache…

python 打開txt_在python中從txt文件打開鏈接

我想請求一個rss程序的幫助。我所做的是收集包含我項目相關信息的網站&#xff0c;然后檢查它們是否有rss提要。鏈接存儲在txt文件中(每行一個鏈接)。因此&#xff0c;我有一個txt文件&#xff0c;其中包含了需要檢查rss的基本url。在我找到了這個代碼&#xff0c;這會使我的工…

IOS-awakeFromNib和viewDidLoad

awakeFromNib 當.nib文件被加載的時候&#xff0c;會發送一個awakeFromNib的消息到.nib文件中的每個對象&#xff0c;每個對象都可以定義自己的 awakeFromNib函數來響應這個消息&#xff0c;執行一些必要的操作。也就是說通過nib文件創建view對象是執行awakeFromNib 。 viewDid…

使用過濾統計信息解決基數預估錯誤

基數預估是SQL Server里一顆隱藏的寶石。一般而言&#xff0c;基數預估指的是&#xff0c;在查詢編譯期間&#xff0c;查詢優化器嘗試找出在執行計劃里從各個運算符平均返回的行數。這個估計用來驅動計劃本身生成并選擇正確的計劃運算符——例如像Nested Loop, Merge Join,還是…

faster-rcnn系列學習之準備數據

如下列舉了 將數據集做成VOC2007格式用于Faster-RCNN訓練的相關鏈接。 RCNN系列實驗的PASCAL VOC數據集格式設置 制作VOC2007數據集用于Faster-RCNN訓練 將數據集做成VOC2007格式用于Faster-RCNN訓練 這一篇比較詳細地介紹了如何制造voc2007的所有文件&#xff0c;內含相關軟件…

C# 委托鏈、多路廣播委托

委托鏈、多路廣播委托&#xff1a;也就是把多個委托鏈接在一起,我們把鏈接了多個方法的委托稱為委托鏈或多路廣播委托 例&#xff1a; 1 class HelloWorld2 {3 //定義委托類型4 delegate void DelegationChain();5 static void Main(string[] args)6 …

openssl 生成證書_使用證書和私鑰導出P12格式個人證書!

【OpenSSL】使用證書和私鑰導出P12格式個人證書1, 產生CA證書1.1, 生成ca的私鑰openssl genrsa -out cakey.pem 20481.2, 生成ca的自簽名證書請求openssl req -new -key cakey.pem -subj "/CNExample Root CA" -out cacsr.pem1.3, 自簽名ca的證書openssl x509 -req -…

PHP (20140505)

數據庫表與表之間的連接是用id聯系。 join on&#xff1b;轉載于:https://www.cnblogs.com/sunshine-c/p/3710283.html

py-faster-rcnn代碼roidb.py的解讀

roidb是比較復雜的數據結構&#xff0c;存放了數據集的roi信息。原始的roidb來自數據集&#xff0c;在trian.py的get_training_roidb(imdb)函數進行了水平翻轉擴充數量&#xff0c;然后prepare_roidb(imdb)【定義在roidb.py】為roidb添加了一些說明性的屬性。 在這里暫時記錄下…

python 概率分布_python實現概率分布

伯努利分布from scipy import statsimport numpy as npimport matplotlib.pyplot as pltxnp.arange(0,2,1)xarray([0, 1])# 求對應分布的概率&#xff1a;概率質量函數 (PMF)p0.5# 硬幣朝上的概率dfstats.bernoulli.pmf(x,p)dfarray([0.5, 0.5])#繪圖vlines用于繪制豎直線(vert…

CodeForces 7D Palindrome Degree 字符串hash

題目鏈接&#xff1a;點擊打開鏈接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib…