本文目录:
一、使用Actuator监控
除了实现容错功能,Hystrix还提供了近乎实时的监控。断路器的状态也会暴露在Actuator提供的/health端点中,只需为项目(该项目可见http://blog.youkuaiyun.com/u012482647/article/details/78148447)添加spring-boot-actuator,重启项目,先访问http://localhost:8777/getString 再访问http://localhost:8777/hystrix.stream ,即可看到实时的监控数据。
因我使用火狐浏览器,每次访问就是下载hystrix.stream文件。这个问题还没解决,望各位大神支支招。
二 、使用Hystrix DashBoard监控
Actuator 能看到的是一大堆数据,而使用Hystrix DashBoard(仪表盘),使得监控数据图形化、可视化。Hystrix仪表板可以显示每个断路器(被@HystrixCommand注解的方法)的状态。步骤如下:
1.创建一个基本的spring boot 工程,添加spring-cloud-starter-hystrix-dashboard依赖。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
2.启动类上添加@EnableHystrixDashboard 注解
@EnableHystrixDashboard
@SpringBootApplication
public class SpringCloudHystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudHystrixDashboardApplication.class, args);
}
}
4.配置文件:
spring.application.name=hystrix-Dashboard
server.port=2001
3.启动项目,访问http://localhost:2001/hystrix 这是Hystrix DashBoard监控首页。
在url中输入http://localhost:8777/hystrix.stream ,点击Monitor Stream 出现如图界面,数量指标如图所示:
综上,实现了利用Hystrix DashBoard对单个实例的信息监控。