新版本Hystrix服务监控
将springcloud由D版本升级到F版本,是一个大版本的跃升,由 1.X升级到了2.X,所以改动量还是挺大的
依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
启动类配置
@SpringBootApplication
@EnableHystrixDashboard // 开启hystrix监控面板
public class HystrixDashBoardApp {
public static void main(String[] args) {
SpringApplication.run(HystrixDashBoardApp.class,args);
}
}
所需监控的服务配置
启动类需要标注@EnableCircuitBreaker
对于所需要监控的服务还需要声明一个servletBean去和HystrixMetricsStreamServlet进行地址映射,否则无法在面板中监测到该服务
@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;
}
https://zhhll.icu/2021/框架/微服务/springcloud/熔断/Hystrix断路器/4.Hystrix新版本服务监控/
网友评论