Spring Cloud:Hystrix监控

结合Hystrix Dashboard实现Hystrix指标数据的可视化面板

一、监控数据

1.pom.xml中加入

<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-hystrixartifactId>
dependency>
<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-hystrix-dashboardartifactId>
dependency>
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-actuatorartifactId>
dependency>

2.应用主类加入:@EnableHystrixDashboard注解

3.访问监控项目的ip:port/hystrix

输入被监控项目的ip:port/hystrix.stream

点击Monitor Stream

Spring Cloud:Hystrix监控_第1张图片

显示如下:

Spring Cloud:Hystrix监控_第2张图片

如果一直出现loading的请求,且从url路径上访问:http://localhost:2101/hystrix.stream 可以ping通,那么先访问以下项目后再刷新监控即可

二、监控数据聚合

pom.xml文件加入:

<dependency>
    <groupId>org.springframework.cloudgroupId>
    <artifactId>spring-cloud-starter-turbineartifactId>
dependency>
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-actuatorartifactId>
dependency>

2.应用主类加入:@EnableTurbine注解

3.配置文件中加入

turbine.app-config=eureka-consumer-ribbon-hystrix #监控信息的服务名
turbine.cluster-name-expression="default"
turbine.combine-host-port=true

4.同样操作,访问:http://localhost:8989/turbine.stream

报错如下,这是由于监控路径和被监控路径不一致的缘故

这里写图片描述

解决方法:将配置文件监控路径一直

management.endpoints:
  enabled-by-default: true   #是否启用或者关闭所有的端点
  web.exposure.include: '*'   #执行器端点都可以在无需验证的情况下访问

整理的时候总有bug,海鹏兄帮忙调试,后来才发现是自己对于Hystrix监控本身的理解不到位,Hystrix监控是对于不同服务间的调用,如果你的请求没有涉及到服务间调用,那么自然就一直loading了,所以是什么要理解啊。

你可能感兴趣的:(●项目之旅)