hystrix dashboard Unable to connect to Command Metric Stream 的解决办法

测试了一个 hystrix dashboard 项目,可以检测其他 springboot 服务的状态。将这个项目连接到我的另一个 springCloud 项目里,却报错:  Unable to connect to Command Metric Stream

在网上搜索发现一种解决方法说:如果使用的是 springBoot 2.x 等比较新的版本,需要在 hystrix 的消费端增加一个 ServletRegistrationBean,用来配置监控路径。检查了一下自己 springCloud 项目,发现用的是 springBoot 2.0.3。然后在被监控项目的启动类里增加 ServletRegistrationBean 这个 bean,之后 hystrix dashboard 就能检测到其他 springboot 服务了。

@EnableCircuitBreaker
@SpringBootApplication
@EnableDiscoveryClient
public class BookConsumer8077Application {
	// 这个配置是为了实现服务监控,与断路器无关,
	// 因为 springboot 2.x 的默认路径不是 "/hystrix.stream",
	// 所以需要在项目里配置这个 ServletRegistrationBean
	@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;
	}

	//
	public static void main( String[] ar ) {
		SpringApplication.run( BookConsumer8077Application.class, ar );
	}

}

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值