hystrix dashboard Unable to connect to Command Metric Stream解决办法
大家好我是酷酷的韩~ 下面是遇到的在springcloud熔断器监测中出现以上错误的解决办法。
1.首先查看依赖是否配置全
<!--熔断器-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!--熔断可视化组件-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.检查启动类是否有如下注解
@EnableCircuitBreaker //断路器
@EnableHystrixDashboard //断路器可视化
3.如果都没问题那么检查下springboot 版本如果是2.0则需要添加 ServletRegistrationBean 因为springboot的默认路径不是 “/hystrix.stream”,只要在自己的项目里配置上下面的servlet就可以了。
@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;
}
4.启动熔断器可视化界面
输入地址http:ip:port/hystrix ,如下界面:
男儿不展风云志,空负天生八尺躯。------酷酷的韩