Hystrix监控
Hystrix还自带了一套监控组件,只要依赖了spring-boot-starter-actuator
即可通过/hystrix.stream
端点来获得监控信息。
冰冷的数据肯定没有实时的图表来的直观,所以Hystrix
也自带Dashboard
。
Hystrix与Turbine聚合监控
为此我们新建了一个应用sbc-hystrix-turbine
来显示hystrix-dashboard
。
目录结构和普通的springboot
应用没有差异,看看主类:
//开启EnableTurbine @EnableTurbine @SpringBootApplication @EnableHystrixDashboard public class SbcHystrixTurbineApplication { public static void main(String[] args) { SpringApplication.run(SbcHystrixTurbineApplication.class, args); } }
- 其中使用
@EnableHystrixDashboard
开启Dashboard
@EnableTurbine
开启Turbine
支持。
以上这些注解需要以下这些依赖:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-turbine</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency>
实际项目中,我们的应用都是多节点部署以达到高可用的目的,单个监控显然不现实,所以需要使用Turbine来进行聚合监控。
关键的application.properties
配置文件:
# 项目配置 spring.application.name=sbc-hystrix-trubine server.context-path=/ server.port=8282 # eureka地址 eureka.client.serviceUrl.defaultZone=http://node1:8888/eureka/ eureka.instance.prefer-ip-address=true # 需要加入的实例 turbine.appConfig=sbc-user,sbc-order turbine.cluster-name-expression="default"
其中turbine.appConfig
配置我们需要监控的应用,这样当多节点部署的时候就非常方便了(同一个应用的多个节点spring.application.name值是相同的
)。
将该应用启动访问http://ip:port/hystrix.stream
:
由于我们的turbine和Dashboard是一个应用所以输入http://localhost:8282/turbine.stream
即可。
详细指标如官方描述:
通过该面板我们就可以及时的了解到应用当前的各个状态,如果再加上一些报警措施就能帮我们及时的响应生产问题。
总结
服务容错的整个还是比较大的,博主也是摸着石头过河,关于本次的Hystrix
只是一个入门版,后面会持续分析它的线程隔离、信号量隔离等原理。
博客:crossoverjie.top。