共计 1501 个字符,预计需要花费 4 分钟才能阅读完成。
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
public class HystrixSpringcloudApplication {public static void main(String[] args) {SpringApplication.run(HystrixSpringcloudApplication.class, args); | |
} | |
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, 即可进入监控页面查看监控数据。
正文完
星哥玩云-微信公众号
