spring cloud(Greenwich.M2) hystrix dashboard 报/actuator/hystrix.stream 404 Not Found的问题

Posted geek power

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring cloud(Greenwich.M2) hystrix dashboard 报/actuator/hystrix.stream 404 Not Found的问题相关的知识,希望对你有一定的参考价值。

consumer端不引用spring-boot-starter-actuator的情况

Consumer端会报Unable to connect to Command Metric Stream。新建HystrixConfiguration类加入以下代码:

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HystrixConfiguration {
    @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet(){
        HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> servletRegistrationBean = new ServletRegistrationBean();
        servletRegistrationBean.setServlet(hystrixMetricsStreamServlet);
        servletRegistrationBean.addUrlMappings("/hystrix.stream");
        servletRegistrationBean.setName("HystrixMetricsStreamServlet");
        return servletRegistrationBean;
    }
}

consumer端开放端点,配置文件中加入:

management.endpoints.web.exposure.include=hystrix.stream,health,info

 默认值为health,info

 

hystrix-dashboord输入的地址为http://consumerhost:port/hystrix.stream 

 

turbine站点配置文件加入:

turbine.appConfig=xxx1,xxx2,x3
turbine.instanceUrlSuffix=/hystrix.stream

xxx1为consumer端配置的应用程序名(如spring.application.name=xxx1),通过eareka-server自动找到对应的consumer接口http://consumerhost:port/hystrix.stream去抓取信息显示到turbine聚合界面上。

由于spring-boot-starter-actuator的默认context-path为actuator,若turbine.instanceUrlSuffix不做设置,默认路径为/actuator/hystrix.stream,与我们在consumer中设置的路径/hystrix.stream不匹配,所以出现/actuator/hystrix.stream 404 Not Found。

 

聚合hystrix-dashboord输入的地址为http://consumerhost:port/turbine.stream

 

 

consumer端引用spring-boot-starter-actuator的情况(推荐)

consumer端开放端点,配置文件中加入:

management.endpoints.web.exposure.include=hystrix.stream,health,info

 默认值为health,info

 

hystrix-dashboord输入的地址为http://consumerhost:port/actuator/hystrix.stream 

 

turbine站点配置文件加入:

turbine.appConfig=xxx1,xxx2,xxx3
turbine.instanceUrlSuffix=/actuator/hystrix.stream

/actuator/hystrix.stream为默认地址也可以不写。

 聚合hystrix-dashboord输入的地址为http://consumerhost:port/turbine.stream

 

以上是关于spring cloud(Greenwich.M2) hystrix dashboard 报/actuator/hystrix.stream 404 Not Found的问题的主要内容,如果未能解决你的问题,请参考以下文章

spring cloud集成nacos

spring-cloud-config-server

Spring Cloud实战Spring Cloud GateWay服务网关

spring-cloud-config——Quick Start

Spring Cloud入门 - Spring Cloud保护机制

spring cloud 与 spring boot 和 spring cloud alibab 版本号对应