0

如何使用 spring boot 执行器分别为给定 REST Endpoint 的 GET、POST 和 PUT 方法捕获指标。


默认情况下,我们得到:-“gauge.response.customer”:631,我需要

  1. “gauge.response.customer.GET”:631,或“gauge.response.GET.customer”:631,
  2. “gauge.response.customer.POST”:1631,或“gauge.response.POST.customer”:1631

提前致谢

4

1 回答 1

0

嗯,我不相信你可以像那样分解端点。但是,我确实知道执行器非常灵活,您可以向该端点添加新指标。看起来您主要对计数器感兴趣,所以我建议使用 Spring boot 具有的 CounterService。

private CounterService counterService;

@Autowired
public MyClassName(CounterService counterService) {
    this.counterService = counterService;
}

@RequestMapping(method=RequestMethod.POST)
public String myPostMethod(Object obj) {
    counterService.increment("mycontroller.post.method");
    //...
    return "myPostMethod";
}

@RequestMapping(method=RequestMethod.GET)
public String myGetMethod() {
    counterService.increment("mycontroller.get.method");
    //...
    return "myGetMethod";
}
于 2016-06-01T11:09:52.363 回答