关于使用@HystrixCommand在Hystrix-Dashboard上显示问题

今天在处理需要对请求其他组件的接口查看其熔断情况,一般有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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值