解决Hystrix Dashboard出现的诸多问题
问题1:访问http://localhost:8764/hystrix.stream
出现Whitelabel error page错误
问题2:在浏览器访问的正确网址是:http://localhost:8764/hystrix:
但是初入监控网址之后出现错误:Unable to connect to Command Metric Stream
问题3:进入http://localhost:8764/hystrix看到的是一直loading状态
以上问题按照下面正确步骤操作都可以解决:
- 在启动类要增加getServlet()的接口,同时要注意addUrlMappings的参数
@SpringBootApplication
@EnableEurekaClient
@EnableHystrix
@EnableHystrixDashboard
public class EmDemoEurekaClientRibbonIiApplication {
public static void main(String[] args) {
SpringApplication.run(EmDemoEurekaClientRibbonIiApplication.class, args);
}
// //Howard 2019-02-21 add for HystrixDashboard
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}
2,附上pom.xml的依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- Howard 2019-02-21 add for hystrix-dashboard -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Howard 2019-02-21 add for 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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
3,step1,访问http://localhost:8764/hystrix.stream看到是一些ping,没有数据,正常。
step2访问htpp://localhost:8764/hystrix,然后在界面填写:http://localhost:8764/hystrix.stream、2000、howard
看到的是loading,这是因为在等待。
step3再访问htpp://localhost:8764/hi?name=howard
step4再刷新上面step1/step2的操作出现的页面,就能正常看到数据了。
参考:
https://blog.csdn.net/dangshushu/article/details/80416042
https://www.cnblogs.com/hejianjun/p/8670693.html
https://www.cnblogs.com/x1mercy/p/9291348.html