jersey - Spring-boot 指标对 RESTful 服务的每个 requestURI 进行计数和测量

标签 jersey spring-boot metrics

我正在使用 starter-jersey 和 starter-actuator。如果我有如下端点,

@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 创建 1 个条目。如果您只是想摆脱 HTTP 请求的计数器/仪表,但保留所有其他自动配置功能,那么您可以包含此

@EnableAutoConfiguration(exclude={MetricFilterAutoConfiguration.class})

希望这有帮助。

关于jersey - Spring-boot 指标对 RESTful 服务的每个 requestURI 进行计数和测量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30332280/

相关文章:

mongodb - 存储用于分析的统计数据的最佳做法是什么?

java - 如果正文中传递的 id 不存在/无效,请更正 http 错误代码?

java - 泽西路径参数 : Multiple backslash separated param

java - org.hibernate.LazyInitializationException 关联集合

spring-boot - 将外部属性传递给 JUnit 的扩展类

spring-boot - Spring Boot bootstrap.yml 中的 Openshift secret

java - Spring Boot,使用 application-{profile}.properties

maven - 带有 Maven 依赖项的 Jersey + Gradle 不起作用

c# - 为什么这个可维护性指数会增加?

跟踪用户在网站上的进度