Unable to connect to Command Metric Stream.使用Hystrix-dashboard监控不到状态数据问题(springBoot2.x以上版本)

Unable to connect to Command Metric Stream.使用Hystrix-dashboard监控不到状态数据问题(springBoot2.x以上版本)

Unable to connect to Command Metric Stream.使用Hystrix-dashboard监控不到状态数据问题(springBoot2.x以上版本)_第1张图片
springBoot2.x以上的配置发生了变化,需要添加一个配置类,才能监控到状态数据。

1、要想使用Hystrix-dashboard,需要导入依赖的启动器

 <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix-dashboard -->
        <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、添加一个配置类,必须的,否则无法监控

@Configuration
public class ConfigBean {

    @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
        HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> bean = new ServletRegistrationBean<>(servlet);
        bean.addUrlMappings("/hystrix.stream");
        bean.setName("HystrixMetricsStreamServlet");
        return bean;
    }
}

3、修改启动类

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker   //开启熔断器,断路器,默认不开启
@EnableHystrixDashboard
@EnableHystrix
public class SpringcloudEurekaConumerRibbonHystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudEurekaConumerRibbonHystrixApplication.class, args);
    }
}

4、启动项目,访问http://localhost:9010/hystrix(测试项目在本地,所以ip为localhost)
Unable to connect to Command Metric Stream.使用Hystrix-dashboard监控不到状态数据问题(springBoot2.x以上版本)_第2张图片
Unable to connect to Command Metric Stream.使用Hystrix-dashboard监控不到状态数据问题(springBoot2.x以上版本)_第3张图片

你可能感兴趣的:(个人)