關(guān)于Spring?Cloud的熔斷器監(jiān)控問題
Hystrix監(jiān)控
actuator的監(jiān)控節(jié)點
在actuator
下有用來監(jiān)控hystrix
的端點/actuator/hystrix.stream
。
訪問:
輸出:(注意監(jiān)控時需要請求@HystrixCommand
配置的微服務(wù))
ping:
data: {"type":"HystrixCommand","name":"feignCardRand","group":"TestController","currentTime":1641272819332,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":1000,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackMissing":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":1000,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":10,"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":"TestController"}
集成hystrix dashboard
接口數(shù)據(jù)查看起來不直觀,可以運行hystrix dashboard
通過界面來查看。
先引入依賴
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency>
創(chuàng)建啟動類
@EnableHystrixDashboard @SpringBootApplication(scanBasePackages = "com.github.mg0324") public class StartupApplication { public static void main(String[] args) { SpringApplication.run(StartupApplication.class,args); } }
添加首頁跳轉(zhuǎn),支持端口直接到hystrix
資源路徑
@Controller public class HystrixIndexController { @GetMapping("") public String index() { return "forward:/hystrix"; } }
添加配置端口
server: port: 8030 hystrix: dashboard: # 設(shè)置允許連接的IP proxy-stream-allow-list: "192.168.3.29"
啟動服務(wù),并訪問 http://127.0.0.0:8030
監(jiān)控詳情解讀
在 Hystrix Dashboard 界面里的url處填寫要監(jiān)控的hystrix數(shù)據(jù)流地址。
如:http://192.168.3.29:9202/actuator/hystrix.stream
如果連接后的界面里什么都沒有顯示,則需要手動請求后,才能展現(xiàn)數(shù)據(jù)。可以用 ab 命令做請求壓測,加大壓力,讓熔斷器開啟,圖中會出現(xiàn)紅色。
ab命令如下:ab -n 10000 -c 160 http://127.0.0.1:9201/test/test/feign/cardRand
集成Turbine監(jiān)控
Turbine是一個聚合Hystrix監(jiān)控數(shù)據(jù)的工具,它可將所有相關(guān)/hystrix.stream端點的數(shù)據(jù)聚合到一個組合的/turbine.stream中,從而讓集群的監(jiān)控更加方便。
添加依賴。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> </dependency>
編寫啟動類。
@EnableTurbine @SpringBootApplication(scanBasePackages = "com.github.mg0324") public class StartupApplication { public static void main(String[] args) { SpringApplication.run(StartupApplication.class,args); } }
添加配置。
server: port: 8031 spring: application: name: card-hystrix-turbine eureka: client: service-url: defaultZone: http://192.168.3.29:8761/eureka/ instance: prefer-ip-address: true turbine: # 要監(jiān)控的微服務(wù)列表,多個用,分隔 appConfig: mic-card,mic-test clusterNameExpression: "'default'"
啟動服務(wù)后,得到 http://192.168.3.29:8031/turbine.stream 的聚合節(jié)點。填寫到hystrix dashboard的url中做監(jiān)控。
參考
https://www.itmuch.com/spring-cloud/finchley-15/
到此這篇關(guān)于Spring Cloud的熔斷器監(jiān)控的文章就介紹到這了,更多相關(guān)Spring Cloud 熔斷器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Spring Boot如何使用Spring Security進行安全控制
要實現(xiàn)訪問控制的方法多種多樣,可以通過Aop、攔截器實現(xiàn),也可以通過框架實現(xiàn),本文將具體介紹在Spring Boot中如何使用Spring Security進行安全控制。2017-04-04基于Log4j2阻塞業(yè)務(wù)線程引發(fā)的思考
這篇文章主要介紹了基于Log4j2阻塞業(yè)務(wù)線程引發(fā)的思考,基于很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12