Jersey Spring引导指标统计并衡量RESTful服务的每个requestURI

Jersey Spring引导指标统计并衡量RESTful服务的每个requestURI,jersey,spring-boot,metrics,Jersey,Spring Boot,Metrics,我用的是起动器球衣和起动器执行器。如果我有一个端点,如下所示 @Component @Path("/greeting") public class GreetingEndpoint { @GET @Path("{id}/{message}") @Produces(MediaType.APPLICATION_JSON) public Greeting sayHello(@PathParam("id") Long id, @PathParam("message") String m

我用的是起动器球衣和起动器执行器。如果我有一个端点,如下所示

@Component
@Path("/greeting")
public class GreetingEndpoint {

  @GET
  @Path("{id}/{message}")
  @Produces(MediaType.APPLICATION_JSON)
  public Greeting sayHello(@PathParam("id") Long id, @PathParam("message") String message) {
    return new Greeting(id, message);
  }
}
我会为每个请求URI设置计数器/仪表。这会导致内存膨胀吗

counter.status.200.greeting.1000.look: 1
counter.status.200.greeting.1001.watch-out: 1
counter.status.200.metrics: 1
gauge.response.greeting.1000.look: 109
gauge.response.greeting.1001.watch-out: 6
gauge.response.metrics: 32

要回答这个问题,是的,如果你有基本上无限的id/消息组合,它可能会爆炸。所有这些信息都存储在内存中。除非您控制调用端点的客户端,否则情况肯定会如此。这可能需要很长一段时间,但没有任何东西能够收获度量存储库,因此它们将在应用程序的生命周期中无限期地存在

你可能有一个解决办法(但我无法解释为什么这样做有效)。使用@RestController+@RequestMapping+@PathVariable。根据我的经验,它将为counter.status.200.greeting.id和message创建一个条目。如果您只是想摆脱HTTP请求的计数器/仪表,但保留所有其他自动配置功能,那么您可以包括此功能

@EnableAutoConfiguration(exclude={MetricFilterAutoConfiguration.class})
希望这有帮助