1.服务调用方如订单中心引入熔断器组件后,在一定的时间窗口(默认5s)调用用户中心服务出错或超时达到达到一定比例,熔断器会被开启,这时的请求都会进入降级处理方法(quick fail)从而保护被调用的服务,避免雪崩效应,时间窗口结束再次请求如果成功熔断器会被关闭。
2.熔断器的状态可以使用hystrix-dashboard来监控,大概原理是:订单中心依赖actuator,hystrix组件暴露一个/actuator/hystrix.stream端点,直接http访问即可,但返回数据可读性差,就需要借助hystrix-dashboard可视化展示,类似springboot admin。hystrix-dashboard是独立的结点,只需要引入依赖(springboot版本2.1.1),入口类开启@EnableHystrixDashboard。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
3.被监控的一方需要引入hystrix组件,并引入actuator暴露出一个监控端点/actuator/hystrix.stream
4.浏览器访问:http://localhost:9097/hystrix ,进入主页面后输入被监控的URL。注意高版本springboot,URL不要少了/actuator,同springboot admin,另外如果被监控的服务配置了独立的management.server.port,URL的端口就是该独立端口。
5.仪表盘:在订单中心修改Tomcat线程数为10,jmeter压测请求20个,监控画面如下,可以看到1个请求成功,9个被拒绝,10个超时。(注:用户中心的接口做的随机5s内sleep,订单中心断路器设置超时时间1s)
6.需要监控多个服务这个方式有点乏力,需要借助Turbine,未完待续