微服务springcloud—使用Hystrix Dashboard可视化监控数据
使用Hystrix Dashboard可视化监控数据
前面讨论了Hystrix的监控,但访问/actuator/hystrix.stream端点获得的数据都是以文字形式展示的。很难通过这些数据,一眼看出系统的运行状态。
可使用Hystrix Dashboard,从让监控数据图形化、可视化。
1.创建一个Maven项目,ArtifactId是microservice-hystrix-dashboard,并添加以下依赖。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
2.编写启动类,在其动力上添加@EnableHystrixDashboard。
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {
@Bean(name="hystrixRegistrationBean")
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
2.0以上版本的spring要加getServlet方法,具体参考链接:
https://blog.****.net/ddxd0406/article/details/79643059
https://blog.****.net/daihanguang123/article/details/80768221
3.配置文件application.yml
server:
port: 8030
spring:
application:
name: hystrix
#开启断路器功能
feign:
hystrix:
enabled: true
management:
endpoints:
web:
exposure:
include: hystrix.stream
这样,一个简单的Hystrix Dashboard就完成了,有配置可知,我们并没有把Hystrix Dashboard注册到Eureka Server上。
4.测试
1.访问http://localhost:8030/hystrix,可看到Hystrix Dashboard的主页
2.在上一节测试的基础上,在URL一栏上输入http://localhost:8010/actuator/hystrix.stream,随意设置一个Title,并点击Monitor Stream按钮后
简单可见,并没有把Hystrix Dashboard注册到Eureka Server上。再生产环境中,也可以把Hystrix Dashboard注册到Eureka Server上,更方便地管理Hystrix Dashboard。
本文大部分内容转载自周立的《Spring Cloud与Docker微服务架构实战》