Springcloud基础知识(7)- Spring Cloud Hystrix (二) | Hystrix 全局/解耦降级、服务熔断、故障监控
作者:互联网
1. Hystrix 全局降级
在 “Springcloud基础知识(6)- Spring Cloud Hystrix (一) | 服务降级” 里的 SpringcloudDemo03 项目,ServiceProviderHystrix 子模块实现了服务端服务降级, ConsumerFeign 子模块实现了客户端服务降级。
服务端和客户端的服务降级,都是给每个业务方法配置一个降级方法,如果需要针对所有业务方法都配置降级方法,代码将非常冗余。
为了解决代码冗余问题,Hystrix 提供了全局降级(Fallback)方法。
本文将在 ConsumerFeign 子模块基础上,修改代码和配置,演示实现全局降级。
1) 修改 src/main/java/com/example/controller/ConsumerController.java 文件
1 package com.example.controller; 2 3 import java.util.List; 4 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.web.bind.annotation.PathVariable; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.RestController; 9 import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 10 import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties; 11 12 import com.example.entity.Employee; 13 import com.example.service.EmployeeFeignService; 14 import com.example.service.EmployeeHystrixService; 15 16 @RestController 17 @RequestMapping(value = "/consumer") 18 @DefaultProperties(defaultFallback = "defaultFallbackHandler") // 配置全局降级(Fallback)方法 19 public class ConsumerController { 20 @Autowired 21 private EmployeeFeignService employeeFeignService; 22 @Autowired 23 private EmployeeHystrixService employeeHystrixService; 24 25 @RequestMapping(value = "/employee/get/{id}") 26 public Employee get(@PathVariable("id") Integer id) { 27 return employeeFeignService.get(id); 28 } 29 30 @RequestMapping(value = "/employee/list") 31 public List<Employee> list() { 32 return employeeFeignService.list(); 33 } 34 35 @RequestMapping(value = "/employee/hystrix/ok/{id}") 36 //@HystrixCommand(fallbackMethod = "timeoutHandler") 37 @HystrixCommand // 不带参数,会自动匹配默认全局降级(Fallback)方法 38 public String employeeInfo_Ok(@PathVariable("id") Integer id) { 39 return employeeHystrixService.employeeInfo_Ok(id); 40 } 41 42 @RequestMapping(value = "/employee/hystrix/timeout/{id}") 43 @HystrixCommand 44 public String employeeInfo_Timeout(@PathVariable("id") Integer id) { 45 return employeeHystrixService.employeeInfo_Timeout(id); 46 } 47 48 // employeeInfo_Ok() 的 fallback 方法 49 public String timeoutHandler(@PathVariable("id") Integer id) { 50 return "Client: system in busy, please try later!"; 51 } 52 53 // 定义全局降级(Fallback)方法,不带参数 54 public String defaultFallbackHandler() { 55 return "Client - default: system in busy, please try later!"; 56 } 57 }
使用全局降级(Fallback)方法的注意点:
(1) 全局降级(Fallback)方法必须与其对应的业务方法在同一个类中,否则无法生效;
(2) 全局降级(Fallback)方法不带参数;
(3) 全局降级(Fallback)方法的优先级较低,业务方法没有指定其降级方法时,才会触发全局 FallBack 方法。
2) 运行
依次启动 server-7001、server-7002、server-7003,启动的间隔 5 ~ 10 秒,都启动后等待 10 秒左右。
启动 server-8004,访问 http://localhost:8004/employee/hystrix/ok/1,4 秒后显示结果如下:
EmployeeServiceImpl -> employeeInfo_Ok(): thread = hystrix-EmployeeServiceImpl-1, id = 1, timeoutValue = 4, port: 8004
启动 ConsumerFeign 模块,访问 http://localhost/consumer/employee/hystrix/ok/1,3 秒后显示结果如下:
Client - default: system in busy, please try later!
2. Hystrix 解耦降级逻辑
不管是业务方法指定的降级方法还是全局降级方法,它们都必须和业务方法在同一个类中才能生效,业务逻辑与降级逻辑耦合度极高。
本文将在 ConsumerFeign 子模块基础上,修改代码和配置,演示对业务逻辑与降级逻辑进行解耦。
1) 创建 src/main/java/com/example/service/EmployeeHystrixFallbackService.java 文件
1 package com.example.service; 2 3 import org.springframework.stereotype.Component; 4 5 @Component 6 public class EmployeeHystrixFallbackService implements EmployeeHystrixService { 7 8 @Override 9 public String employeeInfo_Ok(Integer id) { 10 return "Client - standalone (OK): system in busy, please try later!"; 11 } 12 13 @Override 14 public String employeeInfo_Timeout(Integer id) { 15 return "Client - standalone (Timeout): system in busy, please try later!"; 16 } 17 18 }
2) 修改 src/main/java/com/example/service/EmployeeHystrixService.java 文件
1 package com.example.service; 2 3 import org.springframework.stereotype.Service; 4 import org.springframework.cloud.openfeign.FeignClient; 5 import org.springframework.web.bind.annotation.PathVariable; 6 import org.springframework.web.bind.annotation.RequestMapping; 7 8 @Service 9 @FeignClient(value = "EMPLOYEE-SERVICE-PROVIDER-HYSTRIX", fallback = EmployeeHystrixFallbackService.class) 10 public interface EmployeeHystrixService { 11 @RequestMapping(value = "/employee/hystrix/ok/{id}") 12 public String employeeInfo_Ok(@PathVariable("id") Integer id); 13 14 @RequestMapping(value = "/employee/hystrix/timeout/{id}") 15 public String employeeInfo_Timeout(@PathVariable("id") Integer id); 16 }
3) 修改 src/main/java/com/example/controller/ConsumerController.java 文件
1 package com.example.controller; 2 3 import java.util.List; 4 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.web.bind.annotation.PathVariable; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.RestController; 9 10 import com.example.entity.Employee; 11 import com.example.service.EmployeeFeignService; 12 import com.example.service.EmployeeHystrixService; 13 14 @RestController 15 @RequestMapping(value = "/consumer") 16 public class ConsumerController { 17 @Autowired 18 private EmployeeFeignService employeeFeignService; 19 @Autowired 20 private EmployeeHystrixService employeeHystrixService; 21 22 @RequestMapping(value = "/employee/get/{id}") 23 public Employee get(@PathVariable("id") Integer id) { 24 return employeeFeignService.get(id); 25 } 26 27 @RequestMapping(value = "/employee/list") 28 public List<Employee> list() { 29 return employeeFeignService.list(); 30 } 31 32 @RequestMapping(value = "/employee/hystrix/ok/{id}") 33 public String employeeInfo_Ok(@PathVariable("id") Integer id) { 34 return employeeHystrixService.employeeInfo_Ok(id); 35 } 36 37 @RequestMapping(value = "/employee/hystrix/timeout/{id}") 38 public String employeeInfo_Timeout(@PathVariable("id") Integer id) { 39 return employeeHystrixService.employeeInfo_Timeout(id); 40 } 41 42 }
4) 运行
重启 server-8004,访问 http://localhost:8004/employee/hystrix/ok/1,4 秒后显示结果如下:
EmployeeServiceImpl -> employeeInfo_Ok(): thread = hystrix-EmployeeServiceImpl-1, id = 1, timeoutValue = 4, port: 8004
启动 ConsumerFeign 模块,访问 http://localhost/consumer/employee/hystrix/ok/1,3 秒后显示结果如下:
Client - standalone (OK): system in busy, please try later!
3. Hystrix 服务熔断
熔断机制是为了应对雪崩效应而出现的一种微服务链路保护机制。
当微服务系统中的某个微服务不可用或响应时间太长时,为了保护系统的整体可用性,熔断器会暂时切断请求对该服务的调用,并快速返回一个友好的错误响应。这种熔断状态不是永久的,在经历了一定的时间后,熔断器会再次检测该微服务是否恢复正常,若服务恢复正常则恢复其调用链路。
在熔断机制中涉及了三种熔断状态:
(1) 熔断关闭状态(Closed):当务访问正常时,熔断器处于关闭状态,服务调用方可以正常地对服务进行调用;
(2) 熔断开启状态(Open):默认情况下,在固定时间内接口调用出错比率达到一个阈值(例如 50%),熔断器会进入熔断开启状态。进入熔断状态后,后续对该服务的调用都会被切断,熔断器会执行本地的降级(FallBack)方法;
(3) 半熔断状态(Half-Open):在熔断开启一段时间之后,熔断器会进入半熔断状态。在半熔断状态下,熔断器会尝试恢复服务调用方对服务的调用,允许部分请求调用该服务,并监控其调用成功率。如果成功率达到预期,则说明服务已恢复正常,熔断器进入关闭状态;如果成功率仍旧很低,则重新进入熔断开启状态;
Hystrix 实现服务熔断的步骤如下:
(1) 当服务的调用出错率达到或超过 Hystix 规定的比率(默认为 50%)后,熔断器进入熔断开启状态;
(2) 熔断器进入熔断开启状态后,Hystrix 会启动一个休眠时间窗,在这个时间窗内,该服务的降级逻辑会临时充当业务主逻辑,而原来的业务主逻辑不可用;
(3) 当有请求再次调用该服务时,会直接调用降级逻辑快速地返回失败响应,以避免系统雪崩;
(4) 当休眠时间窗到期后,Hystrix 会进入半熔断转态,允许部分请求对服务原来的主业务逻辑进行调用,并监控其调用成功率;
(5) 如果调用成功率达到预期,则说明服务已恢复正常,Hystrix 进入熔断关闭状态,服务原来的主业务逻辑恢复;否则 Hystrix 重新进入熔断开启状态,休眠时间窗口重新计时,继续重复第 2 ~ 5 步;
本文将在 ServiceProviderHystrix 子模块基础上,修改代码和配置,演示实现熔断机制。
1) 修改 src/main/java/com/example/service/EmployeeService.java 文件
1 package com.example.service; 2 3 public interface EmployeeService { 4 5 // Hystrix 熔断器,显示 Ok 6 public String employeeInfo_Ok(Integer id); 7 8 // Hystrix 熔断器,显示 Timeout 9 public String employeeInfo_Timeout(Integer id); 10 11 // Hystrix 熔断机制 12 public String employeeInfo_CircuitBreaker(Integer id); 13 14 }
2) 修改 src/main/java/com/example/service/EmployeeServiceImpl.java 文件
1 package com.example.service; 2 3 import java.util.concurrent.TimeUnit; 4 import org.springframework.stereotype.Service; 5 import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 6 import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; 7 8 @Service("employeeService") 9 public class EmployeeServiceImpl implements EmployeeService { 10 11 @Override 12 @HystrixCommand(fallbackMethod = "timeoutHandler", 13 commandProperties = { 14 @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", 15 value = "5000") 16 }) 17 public String employeeInfo_Ok(Integer id) { 18 19 int timeoutValue = 4; 20 try { 21 TimeUnit.SECONDS.sleep(timeoutValue); 22 } catch (InterruptedException e) { 23 e.printStackTrace(); 24 } 25 26 return "EmployeeServiceImpl -> employeeInfo_Ok(): thread = " + Thread.currentThread().getName() + ", id = " + id + ", timeoutValue = " + timeoutValue; 27 } 28 29 @Override 30 @HystrixCommand(fallbackMethod = "timeoutHandler", 31 commandProperties = { 32 @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", 33 value = "5000") 34 }) 35 public String employeeInfo_Timeout(Integer id) { 36 37 int timeoutValue = 6; 38 try { 39 TimeUnit.SECONDS.sleep(timeoutValue); 40 } catch (InterruptedException e) { 41 e.printStackTrace(); 42 } 43 44 return "EmployeeServiceImpl -> employeeInfo_Timeout(): thread = " + Thread.currentThread().getName() + ", id = " + id + ", timeoutValue = " + timeoutValue; 45 } 46 47 public String timeoutHandler(Integer id) { 48 return "Server: system in busy, please try later! thread = " + Thread.currentThread().getName() + ", id = " + id; 49 } 50 51 @Override 52 @HystrixCommand( 53 fallbackMethod = "circuitBreakerHandler", 54 commandProperties = { 55 @HystrixProperty(name = "circuitBreaker.enabled", value = "true"), // 是否开启熔断器 56 @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds",value = "1000"), // 统计时间窗 57 @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "5"), // 统计时间窗内请求次数 58 @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "5000"), // 休眠时间窗口期 59 @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60"), // 在统计时间窗口期以内,请求失败率达到 60% 时进入熔断状态 60 } 61 ) 62 public String employeeInfo_CircuitBreaker(Integer id) { 63 if (id < 0) { 64 // 当传入的 id 为负数时,抛出异常,调用降级方法 65 throw new RuntimeException("Server (Circuit Breaker): error, invalid id"); 66 } 67 68 return "Server (Circuit Breaker): success, id = " + id; 69 } 70 71 // employeeInfo_CircuitBreaker 的降级方法 72 public String circuitBreakerHandler(Integer id) { 73 return "Server (Circuit Breaker): system in busy, please try later! id = " + id; 74 } 75 }
与 Hystrix 熔断机制相关的 4 个参数的含义如下表。
参数 | 描述 |
metrics.rollingStats.timeInMilliseconds | 统计时间窗。 |
circuitBreaker.sleepWindowInMilliseconds | 休眠时间窗,熔断开启状态持续一段时间后,熔断器会自动进入半熔断状态,这段时间就被称为休眠窗口期。 |
circuitBreaker.requestVolumeThreshold | 请求总数阀值。在统计时间窗内,请求总数必须到达一定的数量级,Hystrix 才可能会将熔断器打开进入熔断开启转态,而这个请求数量级就是 请求总数阀值。Hystrix 请求总数阈值默认为 20,这就意味着在统计时间窗内,如果服务调用次数不足 20 次,即使所有的请求都调用出错,熔断器也不会打开。 |
circuitBreaker.errorThresholdPercentage | 错误百分比阈值。当请求总数在统计时间窗内超过了请求总数阀值,且请求调用出错率超过一定的比例,熔断器才会打开进入熔断开启转态,而这个比例就是错误百分比阈值。错误百分比阈值设置为 50,就表示错误百分比为 50%,如果服务发生了 30 次调用,其中有 15 次发生了错误,即超过了 50% 的错误百分比,这时候将熔断器就会打开。 |
3) 修改 src/main/java/com/example/controller/EmployeeServiceImpl.java 文件
1 package com.example.controller; 2 3 import lombok.extern.slf4j.Slf4j; 4 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Value; 6 import org.springframework.web.bind.annotation.RestController; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.PathVariable; 9 10 import com.example.service.EmployeeService; 11 12 @RestController 13 @Slf4j 14 @RequestMapping(value = "/employee") 15 public class EmployeeController { 16 @Autowired 17 private EmployeeService employeeService; 18 @Value("${server.port}") 19 private String serverPort; 20 21 @RequestMapping(value = "/hystrix/ok/{id}") 22 public String employeeInfo_Ok(@PathVariable("id") Integer id) { 23 24 String result = employeeService.employeeInfo_Ok(id); 25 log.info("port:" + serverPort + ", result:" + result); 26 return result + ", port: " + serverPort; 27 28 } 29 30 // Hystrix 服务超时降级 31 @RequestMapping(value = "/hystrix/timeout/{id}") 32 public String employeeInfo_Timeout(@PathVariable("id") Integer id) { 33 34 String result = employeeService.employeeInfo_Timeout(id); 35 log.info("port:" + serverPort + ", result:" + result); 36 return result + ", port: " + serverPort; 37 38 } 39 40 // Hystrix 服务熔断 41 @RequestMapping(value = "/hystrix/circuit/{id}") 42 public String employeeInfo_CircuitBreaker(@PathVariable("id") Integer id) { 43 44 String result = employeeService.employeeInfo_CircuitBreaker(id); 45 log.info("port:" + serverPort + ", result:" + result); 46 return result + ", port: " + serverPort; 47 48 } 49 50 }
4) 运行
启动 server-7001、server-7002、server-7003,启动的间隔 5 ~ 10 秒,都启动后等待 10 秒左右。
启动 ServiceProviderHystrix 模块,访问 http://localhost:8004/employee/hystrix/circuit/1,显示结果如下:
Server (Circuit Breaker): success, id = 1, port: 8004
再访问 http://localhost:8004/employee/hystrix/circuit/-1 ,连续快速刷新页面 10 次(次数大于请求总数阀值,使调用出错率大于错误百分比阀值),显示结果如下:
Server (Circuit Breaker): system in busy, please try later! id = -1, port: 8004
在 5 秒内访问 http://localhost:8004/employee/hystrix/circuit/2 ,显示结果如下:
Server (Circuit Breaker): system in busy, please try later! id = 2, port: 8004
注:在熔断开启状态下,即使传入的参数已经是正数,调用的依然降级逻辑。
继续连续访问 http://localhost:8004/employee/hystrix/circuit/2,显示结果如下:
Server (Circuit Breaker): success, id = 2, port: 8004
注:当服务调用正确率上升到一定的比率后,Hystrix 进入熔断关闭状态。
4. Hystrix 故障监控
Hystrix 还提供了准实时的调用监控(Hystrix Dashboard)功能,Hystrix 会持续地记录所有通过 Hystrix 发起的请求的执行信息,并以统计报表的形式展示给用户,包括每秒执行请求的数量、成功请求的数量和失败请求的数量等。
本文将在上文修改过的 SringcloudDemo03 项目基础上,添加一个 HystrixDashboard 子模块,来监控 ServiceProviderHystrix 模块的运行情况。
SpringcloudDemo03 的 Spring Boot 版本是 2.3.12.RELEASE。
1) 创建 HystrixDashboard 模块
选择左上的项目列表中的 SpringcloudDemo03,点击鼠标右键,选择 New -> Module 进入 New Module 页面:
Maven -> Project SDK: 1.8 -> Check "Create from archtype" -> select "org.apache.maven.archtypes:maven-archtype-quickstart" -> Next
Name: HystrixDashboard
GroupId: com.example
ArtifactId: HystrixDashboard
-> Finish
注:模块 HystrixDashboard 创建后,Maven 命令会自动修改主项目 SpringcloudDemo03 的 pom.xml,添加如下内容:
<modules>
...
<module>HystrixDashboard</module>
</modules>
2) 修改 pom.xml 内容如下
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 5 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 6 <parent> 7 <artifactId>SpringcloudDemo03</artifactId> 8 <groupId>com.example</groupId> 9 <version>1.0-SNAPSHOT</version> 10 </parent> 11 <modelVersion>4.0.0</modelVersion> 12 13 <artifactId>HystrixDashboard</artifactId> 14 15 <name>HystrixDashboard</name> 16 <!-- FIXME change it to the project's website --> 17 <url>http://www.example.com</url> 18 19 <properties> 20 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 21 <maven.compiler.source>1.8</maven.compiler.source> 22 <maven.compiler.target>1.8</maven.compiler.target> 23 </properties> 24 25 <dependencies> 26 <dependency> 27 <groupId>junit</groupId> 28 <artifactId>junit</artifactId> 29 <version>4.12</version> 30 <scope>test</scope> 31 </dependency> 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-starter</artifactId> 35 </dependency> 36 <dependency> 37 <groupId>org.springframework.boot</groupId> 38 <artifactId>spring-boot-starter-test</artifactId> 39 <scope>test</scope> 40 </dependency> 41 <!-- hystrix-dashboard 监控的依赖 --> 42 <dependency> 43 <groupId>org.springframework.cloud</groupId> 44 <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> 45 </dependency> 46 <!-- 添加 Spring Boot 的监控模块 --> 47 <dependency> 48 <groupId>org.springframework.boot</groupId> 49 <artifactId>spring-boot-starter-actuator</artifactId> 50 </dependency> 51 </dependencies> 52 53 <build> 54 <plugins> 55 <plugin> 56 <groupId>org.springframework.boot</groupId> 57 <artifactId>spring-boot-maven-plugin</artifactId> 58 <configuration> 59 <mainClass>com.example.App</mainClass> 60 <layout>JAR</layout> 61 </configuration> 62 <executions> 63 <execution> 64 <goals> 65 <goal>repackage</goal> 66 </goals> 67 </execution> 68 </executions> 69 </plugin> 70 </plugins> 71 </build> 72 </project>
3) 创建 src/main/resources/application.yml 文件
1 server: 2 port: 9002 # 端口号, http://localhost:9002/hystrix 熔断器监控页面 3 4 hystrix: 5 dashboard: 6 proxy-stream-allow-list: 7 - "localhost" # http://localhost:8004/actuator/hystrix.stream 监控地址
4) 修改 src/main/java/com/example/App.java 文件
1 package com.example; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 7 @SpringBootApplication 8 @EnableHystrixDashboard 9 public class App { 10 public static void main(String[] args) { 11 SpringApplication.run(App.class, args); 12 } 13 }
5) 创建 src/main/java/com/example/config/HystrixDashboardConfig.java 文件
1 package com.example.config; 2 3 import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; 4 import org.springframework.boot.web.servlet.ServletRegistrationBean; 5 import org.springframework.context.annotation.Bean; 6 import org.springframework.context.annotation.Configuration; 7 8 @Configuration 9 public class HystrixDashboardConfig { 10 11 @Bean 12 public ServletRegistrationBean getServlet() { 13 HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); 14 ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); 15 registrationBean.setLoadOnStartup(1); 16 registrationBean.addUrlMappings("/actuator/hystrix.stream"); // 访问路径 17 registrationBean.setName("hystrix.stream"); 18 return registrationBean; 19 } 20 }
6) 运行
启动 server-7001、server-7002、server-7003。
启动 ServiceProviderHystrix 模块,访问 http://localhost:8004/actuator/,页面显示如下:
1 {"_links":{"self":{"href":"http://localhost:8004/actuator","templated":false}, 2 "archaius":{"href":"http://localhost:8004/actuator/archaius","templated":false}, 3 "beans":{"href":"http://localhost:8004/actuator/beans","templated":false}, 4 "caches-cache":{"href":"http://localhost:8004/actuator/caches/{cache}", 5 "templated":true},"caches":{"href":"http://localhost:8004/actuator/caches", 6 "templated":false}, 7 "health-path":{"href":"http://localhost:8004/actuator/health/{*path}", 8 "templated":true},"health":{"href":"http://localhost:8004/actuator/health", 9 "templated":false},"info":{"href":"http://localhost:8004/actuator/info", 10 "templated":false},"conditions":{"href":"http://localhost:8004/actuator/conditions","templated":false}, 11 "configprops":{"href":"http://localhost:8004/actuator/configprops","templated":false}, 12 "env":{"href":"http://localhost:8004/actuator/env","templated":false}, 13 "env-toMatch":{"href":"http://localhost:8004/actuator/env/{toMatch}","templated":true}, 14 "loggers":{"href":"http://localhost:8004/actuator/loggers","templated":false}, 15 "loggers-name":{"href":"http://localhost:8004/actuator/loggers/{name}","templated":true}, 16 "heapdump":{"href":"http://localhost:8004/actuator/heapdump","templated":false}, 17 "threaddump":{"href":"http://localhost:8004/actuator/threaddump","templated":false}, 18 "metrics-requiredMetricName":{"href":"http://localhost:8004/actuator/metrics/{requiredMetricName}","templated":true}, 19 "metrics":{"href":"http://localhost:8004/actuator/metrics","templated":false}, 20 "scheduledtasks":{"href":"http://localhost:8004/actuator/scheduledtasks","templated":false}, 21 "mappings":{"href":"http://localhost:8004/actuator/mappings","templated":false}, 22 "refresh":{"href":"http://localhost:8004/actuator/refresh","templated":false}, 23 "features":{"href":"http://localhost:8004/actuator/features","templated":false}, 24 "service-registry":{"href":"http://localhost:8004/actuator/service-registry","templated":false}, 25 "hystrix.stream":{"href":"http://localhost:8004/actuator/hystrix.stream","templated":false}}}
启动 HystrixDashboard 模块,访问 http://localhost:9002/hystrix,页面提示输入监控地址:
输入 http://localhost:8004/actuator/hystrix.stream ,点击 “Monitor Stream” 按钮。
多次访问 http://localhost:8004/employee/hystrix/circuit/1 和 http://localhost:8004/employee/hystrix/circuit/-2 , 再查看 http://localhost:9002/hystrix 页面上统计。
标签:http,hystrix,Hystrix,Springcloud,Spring,8004,import,id,localhost 来源: https://www.cnblogs.com/tkuang/p/16422160.html