英文:
When Spring actuator meets Spring Metrics in a Webflux project
问题
我有一个小问题:
在Spring Webflux项目中,使用Spring Actuator和Spring Metrics两者有什么好处(如果有的话)?
从过去的几年来看,Actuator似乎变得越来越流行。然而,在"Spring生态系统"中也有Spring Metrics项目。
将这两者结合是否有益?还是只用其中一个就足够了(如果是这样的话,应该选哪一个)?也许只有同时使用两者才能实现某些用例?
最后,我想要在Webflux项目中跟踪执行某个操作所用的时间。比如:
- Webflux端点被调用了多少次?
- 在接收请求和响应请求之间花费了多少时间?
- 反应式数据库调用需要多少时间?
- 执行此服务需要多少时间?
等等……希望能够不必重复造轮子。是否有建议的适用于Spring的框架能够实现这一点?
谢谢
英文:
I have a a small question:
What are the benefits (if any) of using both Spring actuator plus Spring metrics in a Spring Webflux project please?
From the past years, it seems actuator is becoming more and more popular. However, in the "Spring ecosystem" there is this Spring metrics project.
Any benefits in combining the two? Or just one over the other is enough (in which case, which one)? Maybe some uses cases only having both together can be achieve?
Finally, I would like to track the time elapsed executing something in a Webflux project. Such as:
- How many times was a webflux endpoint invoked?
- How much time spent between receiving and responding to the request?
- How much time needed for the reactive database call?
- How much time spent executing this service?
etc... without hopefully having to reinvent the wheel. Any suggestion of a framework Spring friendly capable of achieving this?
Thank you
答案1
得分: 2
以下是翻译好的内容:
你不需要同时使用这两个库。Actuator 是你在为 Spring Boot 应用程序添加仪表的唯一库。Actuator 使用 Micrometer 作为其基础度量库。看起来在将此集成移入 Actuator 之前,已经创建了 Spring Metrics。我不认为 Spring Metrics 是一个受支持或维护的库了。
一个 WebFlux 端点被调用了多少次?
在接收请求和响应请求之间花费了多少时间?
Actuator 配备了一个 WebFilter
,对发往系统的每个 HTTP 调用进行仪表化。这是默认启用的。文档
响应式数据库调用需要多少时间?
我不认为这方面有现成的仪表化支持,但你可以使用 Micrometer
添加自定义代码来计时每个数据库调用。Micrometer 计时器文档
执行这个服务需要多少时间?
与上面类似。
Spring Boot 在为代码库的不同部分添加仪表化方面有很多开箱即用的支持。了解提供给你的内容的最佳位置是文档。
英文:
You do not need to use both libraries. Actuator is the only library you will need for instrumenting your spring boot application. Actuator uses Micrometer as it's underlying metrics library. It looks like Spring-metrics was created before this integration was moved into Actuator. I don't believe spring-metrics is a supported or maintained library anymore.
> How many times was a webflux endpoint invoked?
>
> How much time spent between receiving and responding to the request?
Actuator ships with a WebFilter
that instruments every http call made to your system. This is enabled by default. Docs
> How much time needed for the reactive database call?
I don't believe there is any instrumentation for this out of the box but you can use Micrometer
to add custom code to time each db call. Micrometer Timer Docs
> How much time spent executing this service?
Similar to above.
There is a lot of out of the box support for instrumenting different parts of your code base in spring boot. The best place to look to understand what is given to you is the documentation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论