一.Health Indicator健康指数监控
当使用Hystrix时,项目可以通过“/actuator/health”服务查看相关项目的健康指数。
1.在pom文件中加:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.在配置文件中加:
#设置查看指标
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: "*"
3.启动服务:ms-eureka-center(8761)、ms-eureka-provider(9701)、ms-hystrix-consumer(8005)
4.访问:能正常访问,且通过“/health”访问hystrix的状态为up


5.将提供服务者停用ms-eureka-provider,多次连续http://localhost:8005/hystrix-consumer/1 访问此请求(F5多次刷新),来触发失败率达到阈值,再次访问:看到请求出发了hystrix机制,hystrix的状态为"CIRCUIT_OPEN”,即“电路开放”的意思。


二.Metrics Stream指标流
1.pom文件:做metrics stream 指标测试,这3个依赖,缺一不可,一定要有,切记切记。
<!-- hystrix 插件 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- dashboard -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<!-- actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
3.启动服务:ms-eureka-center(8761)、ms-eureka-provider(9701)、ms-hystrix-consumer(8005)
4.访问:能正常访问

只要刷新一下:http://localhost:8005//hystrix-consumer/1 这个请求,http://localhost:8005/hystrix.stream 这个页面就不停变化


本文介绍如何利用Spring Boot Actuator和Hystrix进行健康指数监控及指标流测试,通过具体步骤展示了如何配置并监测服务状态,包括电路开放机制及实时监控流的实现。
167万+

被折叠的 条评论
为什么被折叠?



