组团学

实现数据的可视化监控

阅读 (939337)

1、用Hystrix Dashboard实现数据的可视化监控

除容错处理外,Hystrix还提供了实时的监控,它会实时、累加地记录所有关于HystrixCommand的执行信息,包括每秒执行了多少请求、请求有多少次成功多少次失败等。

HystrixDashboard是一款针对Hystrix进行实时监控的工具。HystrixDashboard可以可视地查看实时监控数据,可以直观地显示出各Hystrix Command的请求响应时间、请求成功率等数据。

1.1、添加依赖和配置

<!--Hystrix的依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> <version>1.2.6.RELEASE</version> </dependency> <!--Actuator依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--Hystrix依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> <version>2.0.1.RELEASE</version> </dependency>

1.2、配置启动Servlet

@EnableFeignClients @SpringBootApplication @EnableDiscoveryClient @EnableHystrixDashboard @EnableCircuitBreaker public class HystrixSpringcloudApplication { public static void main(String[] args) { SpringApplication.run(HystrixSpringcloudApplication.class, args); } @Bean public ServletRegistrationBean getServlet(){ HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/actuator/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } }

1.3、查看监控数据

1、启动项目,然后访问http://localhost:50007/hystrix。

2、在监控路径输入框中输入http://localhost:50007/actuator/hystrix.stream,即可进入监控页面查看监控数据。

1589134812369.png

需要 登录 才可以提问哦