SpringCloud Hystrix Dashboard-使用熔断器仪表盘进行监控

在Ribbon 和 Feign 项目增加 Hystrix 仪表盘功能

在 pom.xml 中增加依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

在 springboot 入口中使用 @EnableHystrixDashboard 注解开启仪表盘监控功能

@SpringBootApplication
@EnableFeignClients //启用feign客户端
@EnableDiscoveryClient //注册到eureka
@EnableHystrixDashboard //开启仪表盘
public class WebAdminFeignApplication {
    public static void main(String[] args) {
        SpringApplication.run(WebAdminFeignApplication.class,args);
    }
}

创建 hystrix 仪表盘的 Servlet 配置

Spring Boot 2.x 版本开启 Hystrix Dashboard 与 Spring Boot 1.x 的方式略有不同,还需要增加一个 HystrixMetricsStreamServlet 的配置,代码如下:

@Configuration //定义配置类
public class HystrixDashboardConfiguration {
    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);//启动顺序
        registrationBean.addUrlMappings("/hystrix.stream");//监控界面访问路径(默认周期为2秒)
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}

测试访问Hystrix Dashboard

浏览器端输入 http://localhost:8888/hystrix 界面如下:

熔断器仪表盘可视化界面

熔断器仪表盘相关参数

猜你喜欢

转载自blog.csdn.net/wxd772113786/article/details/103754357
今日推荐