七、微服务容错处理之Hystrix的监控

Hystrix的监控

  1. 为客户端添加spring-boot-starter-actuator依赖;

  2. 访问http://127.0.0.1:8010/hystrix.stream,就会不断刷新如下监控数据:

1
2
3
4
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可视化监控数据

  1. 启动客户端,配置文件如下:
1
2
3
4
5
6
7
8
9
10
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
server:
port: 8010
spring:
application:
name: microservice-consumer-movie1
profiles: movie1
  1. 新建服务消费者,在pom文件中添加依赖:
1
2
3
4
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
  1. 配置文件:
1
2
server:
port: 8030
  1. 启动类添加@EnableHystrixDashboard注解;

  2. 启动,访问dashboard服务http://127.0.0.1:8030/hystrix,填入http://127.0.0.1:8010/hystrix.stream,Title 随意填:
    image
    image

使用Turbine聚合监控数据

Turbine简介

Trubine是一个聚合Hystrix监控数据的工具,它可以将所有相关/hystrix.stream端点的数据聚合到一个组合/turbine.stream中,从而让集群的监控更加方便。
turbine架构图

使用Turbine监控多个微服务
  1. 启动两个客户端;

eureka

  1. 新建Turbine客户端,在pom文件中添加依赖:
1
2
3
4
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-turbine</artifactId>
</dependency>
  1. 配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
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'"
  1. 启动类添加@EnableTurbine注解;

  2. 访问dashboard服务http://127.0.0.1:8030/hystrix,输入Turbine聚合http://127.0.0.1:8031/turbine.stream:
    turbine


该文章摘自《Spring Cloud 与 Docker 微服务架构实战(第二版)》

以上

LeoQin wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
0%