Hystrix的监控
除了实现容错,Hystrix还提供了近乎实时的监控,HystrixCommand在执行时,会生成执行结果和运行指标,比如每秒执行请求数,成功数等,这些监控数据对分析应用系统的状态有用。
在ribbon-consumer的pom.xml 添加依赖实现具备监控能力。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
依次启动项目,做一点测试
访问: http://localhost:8010/hystrix.stream ,可看到浏览器一直处于请求状态,但页面空白。这是因为项目中注解了@HystrixCommand的方法还没执行。因为没有数据。
访问:http://localhost:8010//hello?name=feign 后,再次访问 http://localhost:8010/hystrix.stream。就可以看到数据了
使用Hystrix Dashboard可视化监控数据
前面套路了Hystrix的监控,但是访问获得的数据是以文字展示的,很难通过这些数据,一眼看出系统当前的运行状态。
下面来创建一个Hystrix Dashboard项目
pom.xml文件添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
修改启动类,添加注解 @EnableHystrixDashboard
@SpringBootApplication
@EnableHystrixDashboard //开启仪表盘功能
public class YmkHystrixStreamApplication {
public static void main(String[] args) {
SpringApplication.run(YmkHystrixStreamApplication.class, args);
}
}
修改application.yml配置
server:
port: 8030
这样一个简单的Hystrix Dashboard就完成了,就配置可知,我们并没有把Hystrix Dashborad注册到Eureka Server.
依次启动项目,访问 :http://localhost:8030/hystrix/
在url栏目 输入 http://localhost:8010/hystrix.stream
这样就详细的展示了各种指标
源码下载 : https://download.csdn.net/download/u013083284/10758391