> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/v.-spring-boot-actuator/54.-metrics/54.3-supported-metrics/54.3.1-spring-mvc-metrics.md).

# 54.3.1 Spring MVC指标

自动配置允许使用Spring MVC处理请求。当`management.metrics.web.server.auto-time-requests`为`true`，此检测用于所有请求。或者，当设置为`false`时，你可以通过向请求处理方法添加`@Timed`来启用：

```java
@RestController
@Timed 1
public class MyController {

    @GetMapping("/api/people")
    @Timed(extraTags = { "region", "us-east-1" }) 2
    @Timed(value = "all.people", longTask = true) 3
    public List<Person> listPeople() { ... }

}
```

1. 一个控制器类，用于对控制器中的每个请求处理程序启用计时。
2. 为单个端点启用的方法。如果你在类中有计时器，则没有必要这样做，但是可以使用它进一步定制此特定端点的计时器。
3. 具有`longTask = true`的方法，用于为该方法启用长任务计时器。长任务计时器需要一个单独的度量名称，可以使用短任务计时器进行堆叠。

默认情况下，使用`http.server.requests`来生成度量标准。可以通过设置`management.metrics.web.server.requests-metric-name`属性来定制名称。

默认情况下，与Spring MVC相关的指标用以下信息标记：

* `方法`，请求的方法(例如，`GET`或`POST`)。
* `uri`，请求在变量替换之前的uri模板，如果可能的话(例如`/api/person/{id}`)。
* `状态`，响应的HTTP状态码(例如，`200`或`500`)。
* `异常`，处理请求时抛出的任何异常的简单类名。

  要自定义标记，请提供一个实现`WebMvcTagsProvider`的`@Bean`。
