我用的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: "*"
可以看到,成功地显示了监控页面