执行器指标标签PathVariable和通配符

时间:2019-10-06 10:32:09

标签: spring-boot spring-boot-actuator

我正在使用Spring Boot 2执行器指标来统计API请求。但是我遇到了一些问题,而且找不到太多相关文件。

  

请求总数导致响应为4xx

     

请求总数导致5xx响应

1

我可以使用http://localhost:8080/travel/actuator/metrics/http.server.requests?tag=status:400 获取状态400信息,但我想知道是否有任何方法可以对4xx请求进行通配?还是我必须在我的代码中一个接一个地循环所有4xx状态代码?

2

  @GetMapping("/{type}/{code}")
  public Mono<ResponseEntity<Location>> getLocationByTypeAndCode(
  @NotNull @PathVariable("type") final String type,
  @NotNull @PathVariable("code") final String code) {

我在控制器中使用PathVariable参数,但是当我使用 http://localhost:8080/travel/actuator/metrics/http.server.requests?tag=uri:/locations/ {type} / {code}

我收到400错误的请求错误

我是Spring Boot Actuator的新手,非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

1:要获取所有4xx错误,可以使用:public class Items implements Serializable { private String task; private String date; public Items(String task, String date) { this.task = task; this.date = date; } public String getTask() { return task; } public void setTask(String task) { this.task = task; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } }

2:方括号必须使用网址编码:?tag=outcome:CLIENT_ERROR