Hystrix-Dashboard报错踩坑

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


  1. 尚硅谷周阳老师springcloud第二季Hystrix-Dashboard以及整合网上好多方法,找出适合我的 ↩︎

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值