對(duì)于分布式應(yīng)用來說驰怎,不可避免地要與系統(tǒng)周邊的服務(wù)打交道,這個(gè)時(shí)候春霍,需要對(duì)外部的服務(wù)調(diào)用進(jìn)行監(jiān)控,這里我們利用hystrix進(jìn)行監(jiān)控叶眉,并將其整合到dropwizard的metrics址儒,方便統(tǒng)一輸出到statsd。
引入hystrix-codahale-metrics-publisher
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-codahale-metrics-publisher</artifactId>
<version>1.5.9</version>
</dependency>
配置
@Bean
HystrixMetricsPublisher hystrixMetricsPublisher() {
HystrixCodaHaleMetricsPublisher publisher = new HystrixCodaHaleMetricsPublisher(metricRegistry);
HystrixPlugins.getInstance().registerMetricsPublisher(publisher);
return publisher;
}
指標(biāo)實(shí)例
{
"HystrixDemoController.hello.countBadRequests": 0,
"HystrixDemoController.hello.countFallbackFailure": 0,
"HystrixDemoController.hello.rollingCountTimeout": 2,
"HystrixDemoController.hello.rollingCountFailure": 0,
"HystrixThreadPool.HystrixDemoController.rollingMaxActiveThreads": 1,
"HystrixDemoController.hello.latencyExecute_percentile_25": 0,
"HystrixDemoController.hello.currentTime": 1491203675091,
"HystrixDemoController.hello.rollingCountResponsesFromCache": 0,
"HystrixThreadPool.HystrixDemoController.completedTaskCount": 26,
"HystrixDemoController.hello.rollingCountFallbackMissing": 0,
"HystrixThreadPool.HystrixDemoController.currentTime": 1491203675091,
"HystrixDemoController.hello.latencyTotal_percentile_25": 0,
"HystrixDemoController.hello.rollingCountFallbackSuccess": 8191,
"HystrixThreadPool.HystrixDemoController.totalTaskCount": 26,
"HystrixDemoController.hello.rollingCountSemaphoreRejected": 0,
"HystrixDemoController.hello.countCollapsedRequests": 0,
"HystrixDemoController.hello.latencyExecute_percentile_995": 0,
"HystrixDemoController.hello.latencyTotal_percentile_50": 0,
"HystrixDemoController.hello.propertyValue_executionIsolationSemaphoreMaxConcurrentRequests": 10,
"HystrixDemoController.hello.propertyValue_circuitBreakerErrorThresholdPercentage": 50,
"HystrixDemoController.hello.latencyTotal_percentile_90": 0,
"HystrixDemoController.hello.countFallbackEmit": 0,
"HystrixDemoController.hello.latencyTotal_percentile_995": 0,
"HystrixDemoController.hello.countTimeout": 2,
"HystrixThreadPool.HystrixDemoController.propertyValue_queueSizeRejectionThreshold": 5,
"HystrixDemoController.hello.countSuccess": 6,
"HystrixDemoController.hello.latencyTotal_percentile_75": 0,
"HystrixThreadPool.HystrixDemoController.propertyValue_maximumSize": 10,
"HystrixDemoController.hello.propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests": 10,
"HystrixDemoController.hello.countEmit": 0,
"HystrixDemoController.hello.executionSemaphorePermitsInUse": 0,
"HystrixDemoController.hello.countFallbackSuccess": 8191,
"HystrixThreadPool.HystrixDemoController.largestPoolSize": 10,
"HystrixDemoController.hello.propertyValue_circuitBreakerSleepWindowInMilliseconds": 5000,
"HystrixDemoController.hello.propertyValue_circuitBreakerRequestVolumeThreshold": 20,
"HystrixDemoController.hello.latencyExecute_percentile_75": 0,
"HystrixDemoController.hello.latencyExecute_percentile_90": 0,
"HystrixDemoController.hello.latencyExecute_percentile_50": 0,
"HystrixDemoController.hello.propertyValue_executionTimeoutInMilliseconds": 100,
"HystrixDemoController.hello.latencyTotal_percentile_5": 0,
"HystrixDemoController.hello.rollingCountFallbackFailure": 0,
"HystrixDemoController.hello.latencyTotal_mean": 0,
"HystrixDemoController.hello.propertyValue_rollingStatisticalWindowInMilliseconds": 10000,
"HystrixThreadPool.HystrixDemoController.propertyValue_keepAliveTimeInMinutes": 1,
"HystrixDemoController.hello.rollingCountFallbackRejection": 198,
"HystrixDemoController.hello.countThreadPoolRejected": 0,
"HystrixDemoController.hello.countFallbackMissing": 0,
"HystrixDemoController.hello.rollingCountBadRequests": 0,
"HystrixDemoController.hello.countResponsesFromCache": 0,
"HystrixDemoController.hello.rollingCountSuccess": 6,
"HystrixThreadPool.HystrixDemoController.queueSize": 0,
"HystrixThreadPool.HystrixDemoController.threadActiveCount": 0,
"HystrixDemoController.hello.countShortCircuited": 8387,
"HystrixDemoController.hello.rollingCountExceptionsThrown": 198,
"HystrixDemoController.hello.rollingCountFallbackEmit": 0,
"HystrixDemoController.hello.rollingCountThreadPoolRejected": 0,
"HystrixDemoController.hello.rollingCountShortCircuited": 8387,
"HystrixThreadPool.HystrixDemoController.propertyValue_corePoolSize": 10,
"HystrixDemoController.hello.latencyExecute_mean": 0,
"HystrixDemoController.hello.countExceptionsThrown": 198,
"HystrixDemoController.hello.propertyValue_executionIsolationThreadTimeoutInMilliseconds": 100,
"HystrixThreadPool.HystrixDemoController.propertyValue_actualMaximumSize": 10,
"HystrixDemoController.hello.latencyExecute_percentile_5": 0,
"HystrixDemoController.hello.latencyTotal_percentile_99": 0,
"HystrixDemoController.hello.errorPercentage": 25,
"HystrixDemoController.hello.countFallbackRejection": 198,
"HystrixThreadPool.HystrixDemoController.rollingCountThreadsExecuted": 6,
"HystrixThreadPool.HystrixDemoController.propertyValue_maxQueueSize": -1,
"HystrixDemoController.hello.latencyExecute_percentile_99": 0,
"HystrixDemoController.hello.rollingCountEmit": 0,
"HystrixDemoController.hello.rollingCountCollapsedRequests": 0,
"HystrixThreadPool.HystrixDemoController.countThreadsExecuted": 7,
"HystrixDemoController.hello.countFailure": 0,
"HystrixThreadPool.HystrixDemoController.rollingCountCommandsRejected": 0,
"HystrixDemoController.hello.countSemaphoreRejected": 0
}
hystrix輸出的指標(biāo)比較多衅疙,這個(gè)需要注意一下后端存儲(chǔ)容量莲趣。
hystrix除了輸出latencyTotal相關(guān)分布的響應(yīng)時(shí)間,還輸出了fallback觸發(fā)的相關(guān)數(shù)據(jù)饱溢,以及熔斷的次數(shù)喧伞,帶rolling前綴的為瞬時(shí)值,不帶的一般為累積量绩郎。這里講一下幾個(gè)指標(biāo):
- countShortCircuited為累積量
- rollingCountShortCircuited為瞬時(shí)值潘鲫,報(bào)警的時(shí)候,以后者為主肋杖,該值主要是上報(bào)間隔期間方法調(diào)用被熔斷的次數(shù)溉仑。
- countFallbackSuccess為fallback成功執(zhí)行的次數(shù),累計(jì)量状植。