监控方配置
主函数入口使用注解
@EnableHystrixDashboard
主函数所在类增加配置
/**
*
* 此配置是为了服务监控而配置,与服务器容错本身无关,SpringCloud升级之后的坑
* ServletRegistrationBean因为SpringBoot的默认路径不是 “/hystrix.stream”
* 只要在自己的项目配置上如下的servlet就可以了
*
* @return
*/
@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;
}
YML
server:
port: 9001
# 默认连接eureka,不配置会报错
eureka:
client:
register-with-eureka: false
fetch-registry: false
POM
<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-web</artifactId>
</dependency>
<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>