做網(wǎng)站練手優(yōu)化大師電腦版
Sping Cloud Hystrix
文章目錄
- Sping Cloud Hystrix
- 一、Hystrix 服務(wù)降級(jí)
- 二、Hystrix使用示例
- 三、OpenFeign Hystrix
- 四、Hystrix參數(shù)
- HystrixCommand.Setter核心參數(shù)
- Command Properties
- Fallback降級(jí)配置
- Circuit Breaker 熔斷器配置
- Metrix 健康統(tǒng)計(jì)配置
- Request Context 相關(guān)參數(shù)
- Collapser Properties 命令合并配置
- ThreadPool線程池配置
- 五、監(jiān)控Hystrix-DashBoard
- 部署步驟:
- 監(jiān)控平臺(tái):Hystrix-DashBoard
- 被監(jiān)控服務(wù)配置:
Spring Cloud Hystrix 是一款優(yōu)秀的服務(wù)容錯(cuò)與保護(hù)組件,也是 Spring Cloud 中最重要的組件之一。
Spring Cloud Hystrix 是基于 Netflix 公司的開(kāi)源組件 Hystrix 實(shí)現(xiàn)的,它提供了熔斷器功能,能夠有效地阻止分布式微服務(wù)系統(tǒng)中出現(xiàn)聯(lián)動(dòng)故障,以提高微服務(wù)系統(tǒng)的彈性。Spring Cloud Hystrix 具有服務(wù)降級(jí)、服務(wù)熔斷、線程隔離、請(qǐng)求緩存、請(qǐng)求合并以及實(shí)時(shí)故障監(jiān)控等強(qiáng)大功能。
在微服務(wù)系統(tǒng)中,Hystrix 能夠幫助我們實(shí)現(xiàn)以下目標(biāo):
- 保護(hù)線程資源:防止單個(gè)服務(wù)的故障耗盡系統(tǒng)中的所有線程資源。
- 快速失敗機(jī)制:當(dāng)某個(gè)服務(wù)發(fā)生了故障,不讓服務(wù)調(diào)用方一直等待,而是直接返回請(qǐng)求失敗。
- 提供降級(jí)(FallBack)方案:在請(qǐng)求失敗后,提供一個(gè)設(shè)計(jì)好的降級(jí)方案,通常是一個(gè)兜底方法,當(dāng)請(qǐng)求失敗后即調(diào)用該方法。
- 防止故障擴(kuò)散:使用熔斷機(jī)制,防止故障擴(kuò)散到其他服務(wù)。
- 監(jiān)控功能:提供熔斷器故障監(jiān)控組件 Hystrix Dashboard,隨時(shí)監(jiān)控熔斷器的狀態(tài)。
一、Hystrix 服務(wù)降級(jí)
Hystrix 提供了服務(wù)降級(jí)功能,能夠保證當(dāng)前服務(wù)不受其他服務(wù)故障的影響,提高服務(wù)的健壯性。
服務(wù)降級(jí)的使用場(chǎng)景有以下 2 種:
- 在服務(wù)器壓力劇增時(shí),根據(jù)實(shí)際業(yè)務(wù)情況及流量,對(duì)一些不重要、不緊急的服務(wù)進(jìn)行有策略地不處理或簡(jiǎn)單處理,從而釋放服務(wù)器資源以保證核心服務(wù)正常運(yùn)作。
- 當(dāng)某些服務(wù)不可用時(shí),為了避免長(zhǎng)時(shí)間等待造成服務(wù)卡頓或雪崩效應(yīng),而主動(dòng)執(zhí)行備用的降級(jí)邏輯立刻返回一個(gè)友好的提示,以保障主體業(yè)務(wù)不受影響。
Hystrix的降級(jí)策略:
Hystrix提供了如下三種降級(jí)策略:
-
熔斷降級(jí): 默認(rèn)在10秒內(nèi),發(fā)送20次請(qǐng)求,失敗率達(dá)到50%,就會(huì)觸發(fā)熔斷降級(jí)。
-
超時(shí)降級(jí): 默認(rèn)請(qǐng)求的響應(yīng)時(shí)間超過(guò)1秒,就會(huì)觸發(fā)超時(shí)降級(jí)。
-
資源隔離降級(jí)
? - 信號(hào)量隔離 調(diào)用線程與hystrixCommand線程是同一個(gè)線程。同步方式。資源消耗小。不支持超時(shí)。
? - 線程池隔離 調(diào)用線程與hystrixCommand線程不是同一個(gè)線程。異步方式。支持超時(shí)??梢詾槊總€(gè)服務(wù)單獨(dú)分配線程池。大量線程的上下文切換帶來(lái)的開(kāi)銷比較大。
二、Hystrix使用示例
改造現(xiàn)有服務(wù)
1.pom文件引入spring-boot-starter-netflix-hystrix
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId><version>2.0.2.RELEASE</version>
</dependency>
2.在controller中需要增加熔斷功能的接口添加注解@HystrixCommand, 詳細(xì)參數(shù)見(jiàn) Hystrix參數(shù)
@RestController
@RequestMapping("hystrix")
public class HystrixController {@Autowiredprivate HystrixService hystrixService;// 熔斷降級(jí)@GetMapping("{num}")@HystrixCommand(fallbackMethod="circuitBreakerFallback", commandProperties = {@HystrixProperty(name=HystrixPropertiesManager.CIRCUIT_BREAKER_ENABLED, value = "true"),// 是否開(kāi)啟熔斷器@HystrixProperty(name=HystrixPropertiesManager.CIRCUIT_BREAKER_REQUEST_VOLUME_THRESHOLD,value = "20"), // 統(tǒng)計(jì)時(shí)間窗內(nèi)請(qǐng)求次數(shù)@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_ERROR_THRESHOLD_PERCENTAGE, value = "50"),// 在統(tǒng)計(jì)時(shí)間窗內(nèi),失敗率達(dá)到50%進(jìn)入熔斷狀態(tài)@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_SLEEP_WINDOW_IN_MILLISECONDS, value = "5000"), // 休眠時(shí)間窗口@HystrixProperty(name = HystrixPropertiesManager.METRICS_ROLLING_STATS_TIME_IN_MILLISECONDS, value = "10000") // 統(tǒng)計(jì)時(shí)間窗})public String testCircuitBreaker(@PathVariable Integer num, @RequestParam String name) {if (num % 2 == 0) {return "請(qǐng)求成功";} else {throw RunTimeException("");}}// fallback方法的參數(shù)個(gè)數(shù)、參數(shù)類型、返回值類型要與原方法對(duì)應(yīng),fallback方法的參數(shù)多加個(gè)Throwablepublic String circuitBreakerFallback(Integer num, String name) {return "請(qǐng)求失敗,請(qǐng)稍后重試";}// 超時(shí)降級(jí)@GetMapping@HystrixCommand(fallbackMethod = "timeoutFallback", commandProperties = {@HystrixProperty(name = HystrixPropertiesManager.EXECUTION_TIMEOUT_ENABLED, value = "true"),// 是否開(kāi)啟超時(shí)降級(jí)@HystrixProperty(name = HystrixPropertiesManager.EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS, value = "10000"),// 請(qǐng)求的超時(shí)時(shí)間,默認(rèn)10000@HystrixProperty(name = HystrixPropertiesManager.EXECUTION_ISOLATION_THREAD_INTERRUPT_ON_TIMEOUT, value = "true")// 當(dāng)請(qǐng)求超時(shí)時(shí),是否中斷線程,默認(rèn)true})public String testTimeout(@RequestParam String name) throws InterruptedException{Thread.sleep(200)return "success";}public String timeoutFallback(String name) {return "請(qǐng)求超時(shí),請(qǐng)稍后重試";}// 資源隔離(線程池)觸發(fā)降級(jí)@GetMapping("isolation/threadpool")@HystrixCommand(fallbackMethod = "isolationFallback",commandProperties = {@HystrixProperty(name = HystrixPropertiesManager.EXECUTION_ISOLATION_STRATEGY, value = "THREAD")},threadPoolProperties = {@HystrixProperty(name = HystrixPropertiesManager.CORE_SIZE, value = "10"),@HystrixProperty(name = HystrixPropertiesManager.MAX_QUEUE_SIZE, value = "-1"),@HystrixProperty(name = HystrixPropertiesManager.QUEUE_SIZE_REJECTION_THRESHOLD, value = "2"),@HystrixProperty(name = HystrixPropertiesManager.KEEP_ALIVE_TIME_MINUTES, value = "1"),})public String testThreadPoolIsolation(@RequestParam String name) throws InterruptedException {Thread.sleep(200)return "success";}public String isolationFallback(String name) {return "資源隔離拒絕,請(qǐng)稍后重試";}// 信號(hào)量資源隔離@GetMapping("isolation/semaphore")@HystrixCommand(fallbackMethod = "isolationFallback",commandProperties = {@HystrixProperty(name = HystrixPropertiesManager.EXECUTION_ISOLATION_STRATEGY, value = "SEMAPHORE"),@HystrixProperty(name = HystrixPropertiesManager.EXECUTION_ISOLATION_SEMAPHORE_MAX_CONCURRENT_REQUESTS, value = "2")})public String testSemaphoreIsolation(@RequestParam String name) throws InterruptedException {Thread.sleep(200)return "success";}public String isolationFallback(String name) {return "資源隔離拒絕,請(qǐng)稍后重試";}}
3.全局參數(shù)application.yml @HystrixCommand注解的配置優(yōu)先于Hystrix全局配置
hystrix:command:default:circuitBreaker:enabled: truerequestVolumeThreshold: 20errorThresholdPercentage: 50sleepWindowInMilliseconds: 5000execution:timeout:enabled: trueisolation:thread:timeoutInMilliseconds: 2000interruptOnTimeout: truesemaphore:maxConcurrentRequests: 10strategy: THREADmetrics:rollingStats:timeInMilliseconds: 10000threadpool:default:coreSize: 10maximumSize: 19allowMaximumSizeToDivergeFromCoreSize: falsekeepAliveTimeMinutes: 1maxQueueSize: -1queueSizeRejectionThreshold: 5
4.在啟動(dòng)類添加注解 @EnableCircuitBreaker 注解或者 @EnableHystrix 注解
@SpringBootApplication
@EnableCircuitBreaker
public class HystrixSpringApplication {public static void main(String[] args) {SpringApplication.run(HystrixSpringApplication.class, args);}
}
三、OpenFeign Hystrix
在服務(wù)提供方定義 feign client 接口 以及 fallback或者fallbackFactory,在服務(wù)消費(fèi)方定義具體的降級(jí)策略。
1.引入依賴
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>2.0.2.RELEASE</version>
</dependency>
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclinet</artifactId><version>9.7.0</version>
</dependency>
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-hystrix</artifactId><version>9.7.0</version>
</dependency>
2.定義Feign調(diào)用接口,其中fallbackFactory中為試下的fallback方法
// fallbackFactory 實(shí)現(xiàn)
@FeignClient(value = "hystrixProject", url="http://localhost:8085", fallbackFactory = HystrixServerFallbackFactory.class)
public interface HystrixServer {@GetMapping("/test")String test();
}// fallback 實(shí)現(xiàn)
@FeignClient(value = "hystrixProject", url="http://localhost:8085", fallback = HystrixServerFallback.class)
public interface HystrixServer {@GetMapping("/test")String test();
}
3.定義HystrixServerFallbackFactory.class
import feign.hystrix.FallbackFactory;@Component
public class HystrixServerFallbackFactory implements FallbackFactory<HystrixServer> {@Overridepublic HystrixServer create(Throwable throwable) {return new HystrixServer() {@Overridepublic String test() {return "服務(wù)降級(jí)";}}}
}
4.定義HystrixServerFallback.class
@Component
public class HystrixServerFallback implements HystrixServer {public String test() {return "服務(wù)降級(jí)";}
}
5.全局配置,application.yml
老版本配置:對(duì)應(yīng)于本文的版本
feign:hystrix:enabled: true
新版本配置:
feign:circuitbreaker:enabled: true //開(kāi)啟服務(wù)降級(jí)
6.啟動(dòng)類增加注解
@SpringBootApplication
@EnableFeignClients
public class HystrixDashboardApplication {public static void main(String[] args) {SpringApplication.run(HystrixDashboardApplication.class, args);}
}
四、Hystrix參數(shù)
HystrixCommand.Setter核心參數(shù)
- HystrixCommandGroupKey:區(qū)分一組服務(wù),一般以接口為粒度。
- HystrixCommandKey:區(qū)分一個(gè)方法,一般以方法為粒度。
- HystrixThreadPoolKey:一個(gè)HystrixThreadPoolKey下的所有方法共用一個(gè)線程池。
- HystrixCommandProperties:基本配置
Command Properties
- hystrix.command.default.execution.isolation.strategy 隔離策略,默認(rèn)是Thread,可選Thread|Semaphore。thread用于線程池的隔離,一般適用于同步請(qǐng)求。semaphore是信號(hào)量模式,適用于異步請(qǐng)求
- hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 命令執(zhí)行超時(shí)時(shí)間,默認(rèn)1000ms
- hystrix.command.default.execution.timeout.enabled 執(zhí)行是否啟用超時(shí),默認(rèn)啟用true
- hystrix.command.default.execution.isolation.thread.interruptOnTimeout 發(fā)生超時(shí)是是否中斷,默認(rèn)true
- hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests 最大并發(fā)請(qǐng)求數(shù),默認(rèn)10,該參數(shù)當(dāng)使用ExecutionIsolationStrategy.SEMAPHORE策略時(shí)才有效。如果達(dá)到最大并發(fā)請(qǐng)求數(shù),請(qǐng)求會(huì)被拒絕。理論上選擇semaphore size的原則和選擇thread size一致,但選用semaphore時(shí)每次執(zhí)行的單元要比較小且執(zhí)行速度快(ms級(jí)別),否則的話應(yīng)該用thread。
- hystrix.command.default.execution.isolation.thread.interruptOnCancel
Fallback降級(jí)配置
這些參數(shù)可以應(yīng)用于Hystrix的THREAD和SEMAPHORE策略
- hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests 如果并發(fā)數(shù)達(dá)到該設(shè)置值,請(qǐng)求會(huì)被拒絕和拋出異常并且fallback不會(huì)被調(diào)用。默認(rèn)10.
- hystrix.command.default.fallback.enabled 當(dāng)執(zhí)行失敗(run方法拋異常)或者請(qǐng)求被拒絕(資源不足),是否會(huì)嘗試調(diào)用hystrixCommand.getFallback() 。默認(rèn)true
Circuit Breaker 熔斷器配置
- hystrix.command.default.circuitBreaker.enabled 用來(lái)跟蹤circuit的健康性,如果未達(dá)標(biāo)則讓request短路。默認(rèn)true.
- hystrix.command.default.circuitBreaker.requestVolumeThreshold 一個(gè)rolling window內(nèi)最小的請(qǐng)求數(shù)。如果設(shè)為20,那么當(dāng)一個(gè)rolling window的時(shí)間內(nèi)(比如說(shuō)1個(gè)rolling window是10秒)收到19個(gè)請(qǐng)求,即使19個(gè)請(qǐng)求都失敗,也不會(huì)觸發(fā)circuit break。默認(rèn)20.
- hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds 觸發(fā)短路的時(shí)間值,當(dāng)該值設(shè)為5000時(shí),則當(dāng)觸發(fā)circuit break后的5000毫秒內(nèi)都會(huì)拒絕request,也就是5000毫秒后才會(huì)關(guān)閉circuit。默認(rèn)5000.
- hystrix.command.default.circuitBreaker.errorThresholdPercentage 錯(cuò)誤比率閥值,如果錯(cuò)誤率>=該值,circuit會(huì)被打開(kāi),并短路所有請(qǐng)求觸發(fā)fallback。默認(rèn)50,一般服務(wù)錯(cuò)誤率達(dá)到10%時(shí),服務(wù)已經(jīng)不可用了,所以一般建議設(shè)置到10以下。
- hystrix.command.default.circuitBreaker.forceOpen 強(qiáng)制打開(kāi)熔斷器,如果打開(kāi)這個(gè)開(kāi)關(guān),那么拒絕所有request,默認(rèn)false.
- hystrix.command.default.circuitBreaker.forceClosed 強(qiáng)制關(guān)閉熔斷器 如果這個(gè)開(kāi)關(guān)打開(kāi),circuit將一直關(guān)閉且忽略circuitBreaker.errorThresholdPercentage
Metrix 健康統(tǒng)計(jì)配置
- hystrix.command.default.metrics.rollingStats.timeInMilliseconds 設(shè)置統(tǒng)計(jì)的時(shí)間窗口值的,毫秒值,circuit break 的打開(kāi)會(huì)根據(jù)1個(gè)rolling window的統(tǒng)計(jì)來(lái)計(jì)算。若rolling window被設(shè)為10000毫秒,則rolling window會(huì)被分成n個(gè)buckets,每個(gè)bucket包含success,failure,timeout,rejection的次數(shù)的統(tǒng)計(jì)信息。默認(rèn)10000.
- hystrix.command.default.metrics.rollingStats.numBuckets 設(shè)置一個(gè)rolling window被劃分的數(shù)量,若numBuckets=10,rolling window=10000,那么一個(gè)bucket的時(shí)間即1秒。必須符合rolling window % numberBuckets == 0。默認(rèn)10.
- hystrix.command.default.metrics.rollingPercentile.enabled 執(zhí)行時(shí)是否enable指標(biāo)的計(jì)算和跟蹤,默認(rèn)true
- hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds 設(shè)置rolling percentile window的時(shí)間,默認(rèn)60000
- hystrix.command.default.metrics.rollingPercentile.numBuckets 設(shè)置rolling percentile window的numberBuckets。邏輯同上。默認(rèn)6
- hystrix.command.default.metrics.rollingPercentile.bucketSize 如果bucket size=100,window=10s,若這10s里有500次執(zhí)行,只有最后100次執(zhí)行會(huì)被統(tǒng)計(jì)到bucket里去。增加該值會(huì)增加內(nèi)存開(kāi)銷以及排序的開(kāi)銷。默認(rèn)100.
- hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds 記錄health 快照(用來(lái)統(tǒng)計(jì)成功和錯(cuò)誤綠)的間隔,默認(rèn)500ms
Request Context 相關(guān)參數(shù)
- hystrix.command.default.requestCache.enabled 默認(rèn)true,需要重載getCacheKey(),返回null時(shí)不緩存
- hystrix.command.default.requestLog.enabled 記錄日志到HystrixRequestLog,默認(rèn)true
Collapser Properties 命令合并配置
- hystrix.collapser.default.maxRequestsInBatch 單次批處理的最大請(qǐng)求數(shù),達(dá)到該數(shù)量觸發(fā)批處理,默認(rèn)Integer.MAX_VALUE
- hystrix.collapser.default.timerDelayInMilliseconds 觸發(fā)批處理的延遲,也可以為創(chuàng)建批處理的時(shí)間+該值,默認(rèn)10
- hystrix.collapser.default.requestCache.enabled 是否對(duì)HystrixCollapser.execute() and HystrixCollapser.queue()的cache,默認(rèn)true
ThreadPool線程池配置
-
hystrix.threadpool.default.coreSize 并發(fā)執(zhí)行的核心線程數(shù),默認(rèn)10。不能設(shè)置為0,初始化setter的時(shí)候會(huì)出現(xiàn)異常。
-
hystrix.threadpool.default.maximumSize 并發(fā)執(zhí)行的最大線程數(shù),默認(rèn)10。 This property sets the maximum thread-pool size. This is the maximum amount of concurrency that can be supported without starting to reject
HystrixCommand
s. Please note that this setting only takes effect if you also setallowMaximumSizeToDivergeFromCoreSize
. Prior to 1.5.9, core and maximum sizes were always equal. -
hystrix.threadpool.default.maxQueueSize BlockingQueue的最大隊(duì)列數(shù),當(dāng)設(shè)為-1,會(huì)使用SynchronousQueue,值為正時(shí)使用LinkedBlcokingQueue。Note: This property only applies at initialization time since queue implementations cannot be resized or changed without re-initializing the thread executor which is not supported.
-
hystrix.threadpool.default.queueSizeRejectionThreshold 隊(duì)列截?cái)嚅撝怠<词筸axQueueSize沒(méi)有達(dá)到,達(dá)到queueSizeRejectionThreshold該值后,請(qǐng)求也會(huì)被拒絕。如果maxQueueSize == -1,該字段將不起作用。
-
hystrix.threadpool.default.keepAliveTimeMinutes 線程空閑存活時(shí)間。如果corePoolSize和maxPoolSize設(shè)成一樣(默認(rèn)實(shí)現(xiàn))該設(shè)置無(wú)效。
-
hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds 線程池統(tǒng)計(jì)指標(biāo)的時(shí)間,默認(rèn)10000。
-
hystrix.threadpool.default.metrics.rollingStats.numBuckets 將rolling window劃分為n個(gè)buckets,默認(rèn)10。
建議設(shè)置值:
timeoutInMilliseconds:依賴外部接口時(shí),推薦配置比rpc超時(shí)時(shí)間稍短,否則可能無(wú)法發(fā)揮作用。
maxConcurrentRequests:估算值:(單機(jī)QPS*響應(yīng)時(shí)間)2/1000,2為預(yù)留一倍值,可以自行調(diào)整。
coreSize:估算值:(單機(jī)qps響應(yīng)時(shí)間)*1.5/1000,1.5為預(yù)留0.5倍buffer,該值可以適當(dāng)減少,因?yàn)榫€程池會(huì)有排隊(duì)隊(duì)列。
maxQueueSize:僅在allowMaximumSizeToDivergeFromCoreSize(是否開(kāi)啟動(dòng)態(tài)線程數(shù))為true時(shí)才生效。建議設(shè)置core的兩倍大小。
五、監(jiān)控Hystrix-DashBoard
部署步驟:
監(jiān)控平臺(tái):Hystrix-DashBoard
1.新建Hystrix-DashBoard項(xiàng)目,引入pom依賴
<dependencies><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></dependencies>
2.application.yml文件配置
server:port: 8082
spring:application:name: hystrix-dashboardhystrix:dashboard:proxy-stream-allow-list: "*"
3.在啟動(dòng)類上添加@EnableHystrixDashboard注解開(kāi)啟Dashboard
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {public static void main(String[] args) {SpringApplication.run(HystrixDashboardApplication.class, args);}
}
4.啟動(dòng)服務(wù)訪問(wèn)地址 “http://localhost:7020/hystrix”,可以看到Hystrix Dashboard入口
調(diào)用的格式頁(yè)面中已給出,第一個(gè)文本框中是需要監(jiān)控的服務(wù)或者集群的地址,這里暫時(shí)不需要監(jiān)控集群,所以我們輸入監(jiān)控的服務(wù)地址即可,即輸入“http://localhost:7010/actuator/hystrix.stream”;
“Delay”文本框中是輪詢調(diào)用服務(wù)監(jiān)控信息的延遲時(shí)間,默認(rèn)是2000ms(2s);
“Title”文本框中是監(jiān)控頁(yè)面的標(biāo)題,這里我們輸入“hystrix服務(wù)調(diào)用商品服務(wù)”,然后單擊“Monitor Stream”就可以進(jìn)入Hystrix Dashboard頁(yè)面,如圖所示。
被監(jiān)控服務(wù)配置:
因?yàn)镠ystrix是通過(guò)監(jiān)控服務(wù)調(diào)用監(jiān)控信息的,并且需要訪問(wèn)被監(jiān)控服務(wù)的“/hystrix.stream”接口,而這個(gè)接口也是Actuator監(jiān)控的一個(gè)端點(diǎn),所以需要在服務(wù)調(diào)用者的pom.xml文件中添加Actuator依賴,并開(kāi)放監(jiān)控的端點(diǎn)信息。
1.被監(jiān)控服務(wù)pom文件增加依賴
<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId><version>RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>
</dependencies>
2.application.yml增加配置信息
# 暴漏監(jiān)控信息
management:endpoints:web:exposure:include: "*"