hystrix dashbord 后台报错 Error proxying request的解决方案

hystrix dashbord 后台报错堆栈信息:

2020-01-19 18:35:47.023 ERROR 18836 --- [nio-8093-exec-4] ashboardConfiguration$ProxyStreamServlet : Error proxying request: http://localhost:8023/actuator/hystrix.stream

java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_121]
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_121]
	at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_121]
	at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_121]
	at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:161) ~[httpcore-4.4.12.jar:4.4.12]
	at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:82) ~[httpcore-4.4.12.jar:4.4.12]

这里需要注意的是在SpringBoot2.x版本Spring团队对原有的规则进行了修改:原来直接通过/hystrix.stream,在SpringBoot2.x版本需要加上/actuator,即/actuator/hystrix.stream。并且在原有的基础还需要添加一个servlet,直接在启动类加上以下代码即可:

    @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;
    }

直接通过浏览器访问/hystrix.stream
hystrix dashbord 后台报错 Error proxying request的解决方案_第1张图片可以获取到数据。

通过DashBoread访问
hystrix dashbord 后台报错 Error proxying request的解决方案_第2张图片访问失败,这是Windows系统的原因,我们把项目部署到Linux/Mac上就可以解决以上问题!

你可能感兴趣的:(SpringCloud)