Unable to connect to Command Metric Stream.

springcloud之spring2.0版本hystrix-dashboard Unable to connect to Command Metric Stream解决办法

Unable to connect to Command Metric Stream._第1张图片

依赖

       
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix
        

        
            org.springframework.boot
            spring-boot-starter-actuator
        

        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix-dashboard
        

启动程序注解

@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard

启动信息

http://localhost:8007/actuator/hystrix.stream 是404 ,说明在SpringCloud Finchley.SR1 版本中,该访问路径是默认不开启的

需要手动开启

2019-09-18 00:34:19.382  WARN 29124 --- [nio-8181-exec-2] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8007/actuator/hystrix.stream : 404 : HTTP/1.1 404 
2019-09-18 00:34:19.382  WARN 29124 --- [nio-8181-exec-1] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8007/actuator/hystrix.stream : 404 : HTTP/1.1 404 

解决办法如下:

application.yml添加配

因为监控没有暴露出来,所以没法访问

#暴露全部的监控信息
management:
  endpoints:
    web:
      exposure:
        include: "*"

重启

直接访问 http://10.86.2.44:8007/actuator/hystrix.stream
或者访问监控面板 http://10.86.2.44:8007/hystrix
是loading 状态。
调用feign 服务API,再次查看界面,在 Dashboard 界面即可看到 Hystrix 监控界面:
Unable to connect to Command Metric Stream._第2张图片

启动类中添加

 //springboot2.0以上版本,使用hystrix的dashboard要配置一个servlet
    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }

访问路径就可以更改为:
http://10.86.2.44:8007/actuator/hystrix.stream
或者:
http://10.86.2.44:8007/hystrix.stream

你可能感兴趣的:(springcloud流量监控)