解决Hystrix Dashboard出现Unable to connect to Command Metric Stream错误

我用的springboot是2.3.2版本,springcloud为H版SR7最新版

在网上查看很多解决方法都说到,在被监控的项目中,注册ServletRegistrationBean到容器中,如下:

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableCircuitBreaker
public class CloudProviderHystrixPayment8011Application {
    
    

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

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

这样配置后,发现可以输入项目地址+/hystrix.stream直接访问,但是dashboard依旧无法连接上。

在这里插入图片描述
这时候打开dashboard页面,依然连接不上。
在这里插入图片描述
在这里插入图片描述
这时候我去dashboard的项目控制台中看到,说需要添加到hystrix.dashboard.proxyStreamAllowList属性中。

在这里插入图片描述
于是去dashboard的项目yml配置文件中进行配置,添加所有进入到允许列表,然后重启项目。

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

可以看到,成功地显示了监控页面

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41120971/article/details/108091626
今日推荐