Hystrix
的监控
为客户端添加
spring-boot-starter-actuator
依赖;访问
http://127.0.0.1:8010/hystrix.stream
,就会不断刷新如下监控数据:
ping: data:
{"type":"HystrixCommand","name":"findById","group":"MovieRibbonController","currentTime":1550646505861,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"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":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"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":"MovieRibbonController"}
data:
{"type":"HystrixThreadPool","name":"MovieRibbonController","currentTime":1550646505861,"currentActiveCount":0,"currentCompletedTaskCount":50,"currentCorePoolSize":10,"currentLargestPoolSize":10,"currentMaximumPoolSize":10,"currentPoolSize":10,"currentQueueSize":0,"currentTaskCount":50,"rollingCountThreadsExecuted":0,"rollingMaxActiveThreads":0,"rollingCountCommandRejections":0,"propertyValue_queueSizeRejectionThreshold":5,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"reportingHosts":1}
使用Hystrix Dashboard
可视化监控数据
- 启动客户端,配置文件如下:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
server:
port: 8010
spring:
application:
name: microservice-consumer-movie1
profiles: movie1
- 新建服务消费者,在
pom
文件中添加依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
- 配置文件:
server:
port: 8030
启动类添加
@EnableHystrixDashboard
注解;启动,访问
dashboard
服务http://127.0.0.1:8030/hystrix
,填入http://127.0.0.1:8010/hystrix.stream
,Title 随意填:
使用Turbine
聚合监控数据
Turbine
简介
Trubine
是一个聚合Hystrix
监控数据的工具,它可以将所有相关/hystrix.stream
端点的数据聚合到一个组合/turbine.stream
中,从而让集群的监控更加方便。
使用Turbine
监控多个微服务
- 启动两个客户端;
- 新建
Turbine
客户端,在pom
文件中添加依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-turbine</artifactId>
</dependency>
- 配置文件:
spring:
application:
name: microservice-hystrix-turbine
server:
port: 8031
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
turbine:
appConfig: microservice-consumer-movie,microservice-consumer-movie1
clusterNameExpression: "'default'"
启动类添加
@EnableTurbine
注解;访问
dashboard
服务http://127.0.0.1:8030/hystrix
,输入Turbine
聚合http://127.0.0.1:8031/turbine.stream
: