欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

关于Spring Cloud的熔断器监控问题

时间:2022-05-25 09:42:20|栏目:JAVA代码|点击:

Hystrix监控

actuator的监控节点

actuator下有用来监控hystrix的端点/actuator/hystrix.stream

访问:

http://localhost:9202/actuator/hystrix.stream

输出:(注意监控时需要请求@HystrixCommand配置的微服务)

ping: 

data: {"type":"HystrixCommand","name":"feignCardRand","group":"TestController","currentTime":1641272819332,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":1000,"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":1000,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":10,"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":"TestController"}

集成hystrix dashboard

接口数据查看起来不直观,可以运行hystrix dashboard通过界面来查看。

先引入依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

创建启动类

@EnableHystrixDashboard
@SpringBootApplication(scanBasePackages = "com.github.mg0324")
public class StartupApplication {
    public static void main(String[] args) {
        SpringApplication.run(StartupApplication.class,args);
    }
}

添加首页跳转,支持端口直接到hystrix资源路径

@Controller
public class HystrixIndexController {
  @GetMapping("")
  public String index() {
    return "forward:/hystrix";
  }
}

添加配置端口

server:
  port: 8030

hystrix:
  dashboard:
    # 设置允许连接的IP
    proxy-stream-allow-list: "192.168.3.29"

启动服务,并访问 http://127.0.0.0:8030

监控详情解读

在 Hystrix Dashboard 界面里的url处填写要监控的hystrix数据流地址。
如:http://192.168.3.29:9202/actuator/hystrix.stream

如果连接后的界面里什么都没有显示,则需要手动请求后,才能展现数据。可以用 ab 命令做请求压测,加大压力,让熔断器开启,图中会出现红色。

ab命令如下:
ab -n 10000 -c 160 http://127.0.0.1:9201/test/test/feign/cardRand

集成Turbine监控

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

添加依赖。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>

编写启动类。

@EnableTurbine
@SpringBootApplication(scanBasePackages = "com.github.mg0324")
public class StartupApplication {
    public static void main(String[] args) {
        SpringApplication.run(StartupApplication.class,args);
    }
}

添加配置。

server:
  port: 8031
spring:
  application:
    name: card-hystrix-turbine
eureka:
  client:
    service-url:
      defaultZone: http://192.168.3.29:8761/eureka/
  instance:
    prefer-ip-address: true
turbine:
  # 要监控的微服务列表,多个用,分隔
  appConfig: mic-card,mic-test
  clusterNameExpression: "'default'"

启动服务后,得到 http://192.168.3.29:8031/turbine.stream 的聚合节点。填写到hystrix dashboard的url中做监控。

参考

https://www.itmuch.com/spring-cloud/finchley-15/

上一篇:非常全面的IReport的使用教程

栏    目:JAVA代码

下一篇:Java AbstractMethodError原因案例详解

本文标题:关于Spring Cloud的熔断器监控问题

本文地址:http://www.codeinn.net/misctech/202813.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有