配置Hystrix Dashboard 时遇到的Unable to connect to Command Metric Stream.问题

本文介绍了在Spring Cloud中配置Hystrix Dashboard时遇到的问题及解决办法,包括配置Hystrix Metrics Stream Servlet和设置允许的代理主机名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在springCloud配置Hystrix Dashboard的时候我出现了Unable to connect to Command Metric Stream.问题。

image-20211101134213626

查看报错发现如下信息

image-20211101134143009

2021-11-01 13:39:43.859  WARN 17012 --- [nio-9001-exec-8] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8001/hystrix.stream : 404 : HTTP/1.1 404 
2021-11-01 13:39:43.896  INFO 17012 --- [nio-9001-exec-4] ashboardConfiguration$ProxyStreamServlet : 

Proxy opening connection to: http://localhost:8001/hystrix.stream

查找研究后发现原来是springcloud升级后的坑,ServletRegistrationBean因为springBoot的默认路径不是"/hystrix.stream",所以直接打开http://localhost:8001/hystrix.stream也是报错的

image-20211101134723714

那么只要在自己的项目里配置这个servlet就可以了,代码如下,放在SpringBoot的启动类上

@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://localhost:8001/hystrix.stream ,果然正确的访问到了数据

image-20211101135141768

然而我再次尝试打开Hystrix Dashboard的时候我又出现了Unable to connect to Command Metric Stream.

image-20211101134213626

再次查看报错信息

image-20211101135406039

2021-11-01 13:52:31.705  WARN 16816 --- [nio-9001-exec-1] ashboardConfiguration$ProxyStreamServlet : Origin parameter: http://localhost:8001/hystrix.stream is not in the allowed list of proxy host names.  If it should be allowed add it to hystrix.dashboard.proxyStreamAllowList.
2021-11-01 13:52:31.705  WARN 16816 --- [io-9001-exec-10] ashboardConfiguration$ProxyStreamServlet : Origin parameter: http://localhost:8001/hystrix.stream is not in the allowed list of proxy host names.  If it should be allowed add it to hystrix.dashboard.proxyStreamAllowList.

这次很清晰,就是说http://localhost:8001/hystrix.stream 不在允许的代理主机列表中,最后甚至给了我们解决方案

If it should be allowed add it to hystrix.dashboard.proxyStreamAllowList.

既然如此,我们就加吧,在dashboard的工程yml文件下加入如下配置即可

hystrix:
  dashboard:
    proxy-stream-allow-list: "localhost"

再次尝试,成功!

image-20211101140002621作者(Author):魔王Dany
链接(URL):https://mowangblog.top/mowang/hystrix-dashboard
来源(Source):魔王の博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值