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


Hystrix的监控

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

  2. 访问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可视化监控数据

  1. 启动客户端,配置文件如下:
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
server:
  port: 8010
spring:
  application:
    name: microservice-consumer-movie1
  profiles: movie1
  1. 新建服务消费者,在pom文件中添加依赖:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
  1. 配置文件:
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文件中添加依赖:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-turbine</artifactId>
</dependency>
  1. 配置文件:
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 微服务架构实战(第二版)》

以上


文章作者: Qliang
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Qliang !
评论
 上一篇
八、微服务网关之Zuul 八、微服务网关之Zuul
为什么要用微服务网关如下图,外部客户端可能需要调用多个服务的接口才能完成一个业务需求,如果让客户端直接与微服务通信会产生以下的问题: 客户端会多次请求不同的微服务,增加了客户端的复杂性。 存在跨域请求,在一定场景下处理比较复杂。 认证复杂
2019-01-24
下一篇 
五、微服务容错处理之Hystrix线程隔离策略与传播上下文 五、微服务容错处理之Hystrix线程隔离策略与传播上下文
Hystrix的隔离策略有两种: 线程隔离 信号量隔离 THREAD(线程隔离):使用该方式,HystrixCommand将会在单独的线程上执行,并发请求受线程池中线程数量的限制。Hystrix中默认并且推荐使用线程隔离。 SEMAPHO
2019-01-23
  目录