SpringCloud--Hystrix Dashboard界面一直loading的解决

 


出现的问题

  在模拟Hystrix仪表盘时,仪表盘一直处于loading状态,没有监控数据

探明原因及解决步骤

我的SpringCloud版本是Hoxton.SR6

1、确保hystrix.stream可以正常访问

  首先判断是否可以正常访问http://localhost:9000/actuator/hystrix.stream

  如果不能访问,需要做一下几点:

  (1)配置监控

  pom文件引入依赖

复制代码
        <!--actuator 依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--eureka 客户端依赖-->

        <!-- hystrix-dashboard 依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.2.7.RELEASE</version>
        </dependency>
复制代码

  (2)启动类添加@EnableHystrixDashboard注解和@EnableHystrix注解,同时配置ServletRegistrationBean的访问路径

复制代码
@SpringCloudApplication
@EnableHystrixDashboard
@EnableHystrix
public class ConsumerHystrixDashbord9000Application {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerHystrixDashbord9000Application.class, args);
    }

    @Bean
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }

}
复制代码

2、确保hystrix.stream可以加载到数据

  如果上述内容配置完毕,访问http://localhost:9000/actuator/hystrix.stream一直提示ping,则说明还没有访问接口,服务还没有拿到负载均衡的数据,因此需要访问接口

    

 访问接口(如果项目不是热部署,则需要重启项目)

    

 此时再次访问http://localhost:9000/actuator/hystrix.stream,可以发现已经有数据

    

3、其他情况(版本中JQuery报错)

  重新查看Hystrix仪表盘,发现仍然处于loading状态

  F12进入调试模式后,发现JQuery报错:Uncaught: TypeError: e.indexOf is not a function

    

  原因:Hoxton.SR6依赖的jquery版本为3.4.1。而在高版本jquery中$(window).load(function()写法已经被$(window).on("load",function()替代

  解决:修改jar包中jQuery中monitor.ftlh文件的load写法

  (1)maven仓库中找到Dashboard依赖的jar包

  注意:是spring-cloud-netflix-hystrix-dashboard目录下,不是spring-cloud-starter-netflix-hystrix-dashboard,虽然我们项目中引入的是spring-cloud-starter-netflix-hystrix-dashboard,但是可以看下依赖关系,最后还是使用的spring-cloud-netflix-hystrix-dashboard

  点击启动类上的@EnableHystrixDashboard注解,就可以看到具体引用的是哪个包了

    

   在本地maven仓库中找到该包,打开spring-cloud-netflix-hystrix-dashboard-2.2.3.RELEASE.jar\templates\hystrix目录,修改monitor.ftlh

    

  修改内容就是将两处$(window).load(function()代码改为$(window).on("load",function()

    

   改好后,重新启动项目,重新访问负载均衡接口让其有数据,然后访问http://localhost:9000/actuator/hystrix.stream,即可正常访问

    

 

posted @   李聪龙  阅读(1059)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示