今天在处理需要对请求其他组件的接口查看其熔断情况,一般有HystrixDashboard服务监控、Turbine聚合监控,可以监控feign方式,可以使用@HystrixCommand注解,对相关的方法进行监控,现使用turbine聚合情况处理做个简单的记录,如有不同建议请留言一起讨论。
使用Turbine需要重建一个项目hystrix-turbine,引用相关的包。
1、pom文件引用的相关修改:
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> </dependency> </dependencies>
2、application.yml文件
turbine: appConfig: testModel aggregator: clusterConfig: default clusterNameExpression: new String("default")
3、Application .java
@EnableTurbine @EnableHystrixDashboard @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
4、新建另一个项目TestModel,建立一个controller,如下:
@RestController @RequiredArgsConstructor public class EurekaTestController { @HystrixCommand(fallbackMethod = "a1") @RequestMapping(value = "/api/json/public/test1",method = RequestMethod.POST) public Mono test123(){ return testPublic1(); } public Mono a1(){ return Mono.just(true); } public Mono testPublic1(){ return Mono.just(true); } }
5、 请求后,打开监控面板,比如http://localhost:8773/hystrix/monitor?stream=http%3A%2F%2Flocalhost%3A8773%2Fturbine.stream&title=de,显示结果如图:
PS:如果是通过Feign请求第三方服务,你想监控接口情况,需要打开相关的配置,如下:
feign: client: config: default: connectTimeout: 5000 readTimeout: 5000 hystrix: enabled: true