新版本Hystrix服务监控
将springcloud由D版本升级到F版本,是一个大版本的跃升,由 1.X升级到了2.X,所以改动量还是挺大的
依赖
1 2 3 4
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency>
|
启动类配置
1 2 3 4 5 6 7 8
| @SpringBootApplication @EnableHystrixDashboard public class HystrixDashBoardApp {
public static void main(String[] args) { SpringApplication.run(HystrixDashBoardApp.class,args); } }
|
所需监控的服务配置
启动类需要标注@EnableCircuitBreaker
对于所需要监控的服务还需要声明一个servletBean去和HystrixMetricsStreamServlet进行地址映射,否则无法在面板中监测到该服务
1 2 3 4 5 6 7 8 9
| @Bean public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet(){ HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; }
|