1. 程式人生 > >spring cloud(Greenwich.M2) hystrix dashboard 報/actuator/hystrix.stream 404 Not Found的問題

spring cloud(Greenwich.M2) hystrix dashboard 報/actuator/hystrix.stream 404 Not Found的問題

con 界面 mapping netflix setname url connect ext path

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的問題