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;
}
}

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端暴露/actuator/hystrix.stream,/actuator/info,/actuator/health这3个endpoint,配置文件中加入:

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