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

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM