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

 更新时间:2022年01月23日 14:22:42   作者:程序猫大刚  
Turbine是一个聚合Hystrix监控数据的工具,它可将所有相关/hystrix.stream端点的数据聚合到一个组合的/turbine.stream中,从而让集群的监控更加方便,接下来通过本文给大家介绍Spring Cloud的熔断器监控,感兴趣的朋友一起看看吧

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/

到此这篇关于Spring Cloud的熔断器监控的文章就介绍到这了,更多相关Spring Cloud 熔断器内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Spring Boot如何使用Spring Security进行安全控制

    Spring Boot如何使用Spring Security进行安全控制

    要实现访问控制的方法多种多样,可以通过Aop、拦截器实现,也可以通过框架实现,本文将具体介绍在Spring Boot中如何使用Spring Security进行安全控制。
    2017-04-04
  • Java进阶必备之多线程编程

    Java进阶必备之多线程编程

    今天带大家来学习java多线程编程,文中有非常详细的代码示例及介绍,对正在学习java多线程的小伙伴们很有帮助,需要的朋友可以参考下
    2021-05-05
  • 基于Log4j2阻塞业务线程引发的思考

    基于Log4j2阻塞业务线程引发的思考

    这篇文章主要介绍了基于Log4j2阻塞业务线程引发的思考,基于很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-12-12
  • Kafka Java Producer代码实例详解

    Kafka Java Producer代码实例详解

    这篇文章主要介绍了Kafka Java Producer代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-06-06
  • java日期相关类实例详解

    java日期相关类实例详解

    这篇文章主要介绍了java日期相关类实例详解,小编觉得还是挺不错的,这里分享给大家,供需要的朋友参考。
    2017-10-10
  • SVN 安装教程之服务器和客户端

    SVN 安装教程之服务器和客户端

    这篇文章主要介绍了SVN 安装教程之服务器和客户端的相关资料,这里对安装步骤进行了详细介绍,需要的朋友可以参考下
    2016-11-11
  • SpringBoot项目启动时如何读取配置以及初始化资源

    SpringBoot项目启动时如何读取配置以及初始化资源

    这篇文章主要给大家介绍了关于SpringBoot项目启动时如何读取配置以及初始化资源的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者使用SpringBoot具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2020-06-06
  • java使用Filter实现自动登录的方法

    java使用Filter实现自动登录的方法

    这篇文章主要为大家详细介绍了java使用Filter实现自动登录的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-04-04
  • Java常用工具类汇总 附示例代码

    Java常用工具类汇总 附示例代码

    这篇文章主要介绍了Java常用工具类,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着我来一起学习学习吧,希望能给你带来帮助
    2021-06-06
  • java 保留两位小数的几种方法

    java 保留两位小数的几种方法

    这篇文章主要介绍了JAVA中小数点后保留两位的几种方法,并有小实例,希望能帮助有所需要的同学
    2016-07-07

最新评论