spring2.0之后 Hystrix-Dashboard 一直出现 Unable to connect to Command Metric Stream解决办法
Hystrix-Dashboard服务
引入相关依赖
<!-- HystrixDashboardMain9001-dashboard 相关依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
配置yml文件
#端口号,自己定义的
server:
port: 9001
#一定要加,不然还是会出现Unable to connect to Command Metric Stream,"*",可以换成其他内容
management:
endpoints:
web:
exposure:
include: '*'
#最好添加,不然可能出现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.
hystrix:
dashboard:
proxy-stream-allow-list: localhost
主启动类
//加上该注解,开启图形化Dashboard
@EnableHystrixDashboard
被监控的微服务
相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
配置yml文件
#端口号
server:
port: 8001
spring:
application:
name: cloud-provider-hystrix-payment
#注册进eureka,你可以用其他服务注册中心(Zookeeper,Consul,Nacos)
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://eureka7001.com:7001/eureka
主启动类
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class PaymentHystrixMain8001 {
public static void main(String[] args) {
SpringApplication.run(PaymentHystrixMain8001.class,args);
}
//spring2.0之后一定要加这个
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
//这个是访问路径可以修改,这个是默认的
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}
文章来源。1
尚硅谷周阳老师springcloud第二季Hystrix-Dashboard以及整合网上好多方法,找出适合我的 ↩︎