首页 > 编程语言 > 详细

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

时间:2021-04-25 10:35:18      阅读:124      评论:0      收藏:0      [点我收藏+]

出现的问题

  在模拟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,即可正常访问

    技术分享图片

 

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

原文:https://www.cnblogs.com/liconglong/p/14698763.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!