简体   繁体   English

Spring Boot定义了REST接口,想定时请求-响应

[英]Spring Boot defines REST Interface, want to time Request - Response

I'm using Spring Boot to define a REST Interface and want to define a metric that times Request to Response. 我正在使用Spring Boot定义REST接口,并想定义对请求响应时间进行度量的指标。

I could just start the timer, when the function is called and stop it at the return, but that seems not right, since I don't know when Spring sends out the actual message. 我只能在调用函数时启动计时器,然后在返回时将其停止,但这似乎不对,因为我不知道Spring什么时候发出实际消息。 Is this possible without messing with the actual code behind Spring? 这有可能在不弄乱Spring背后的实际代码的情况下吗?

We use Perf4J to time operations. 我们使用Perf4J来计时操作。 Our application is structured as Filters -> Controller -> Business Logic -> Data Access -> Data Store . 我们的应用程序的结构为Filters -> Controller -> Business Logic -> Data Access -> Data Store In the first year we used to log response times for every request at both the Filter and Business Logic layers. 在第一年,我们曾经在过滤器和业务逻辑层记录每个请求的响应时间。 However, we did not see too much difference in times recorded at these two layers (less than 10%) so we have standardised on timing just the business logic operations. 但是,我们没有看到这两层记录的时间差异太大(小于10%),因此我们仅对业务逻辑操作的时间进行了标准化。

Try to read more on Spring MVC Interceptors. 尝试阅读有关Spring MVC拦截器的更多信息。 Quite a good introduction and example can be found here: http://www.journaldev.com/2676/spring-mvc-interceptors-example-handlerinterceptor-and-handlerinterceptoradapter 可以在这里找到很好的介绍和示例: http : //www.journaldev.com/2676/spring-mvc-interceptors-example-handlerinterceptor-and-handlerinterceptoradapter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM