如何测量Spring Bean中调用方法的次数和响应时间
我想测量 Spring 提供的服务调用方法的次数。
在 EJB 领域,此信息通常由容器提供。
现在,由于 spring 是在广播中播放“你能做的任何事情,我能做得更好”时构思的,所以我希望有一个隐藏在某个地方的漂亮而优雅的组件,我可以使用一些 XML 将其编织到我的应用程序中。
有人知道这样的组件吗?
I would like to measure the number of times a method is called on a service provisioned by Spring.
In EJB land this information is usually provided by the container.
Now since spring is conceived when "Anything you can do, I can do better" was playing on the radio, I expect there to be a nice and elegant component hidden somewhere which I can weave into my application using a sprinkling of XML.
Does anybody know of such a component?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 JAMon API。
JAMon 收集聚合性能统计数据,例如点击次数、执行时间(总计、平均、最小、最大、标准偏差)以及并发信息(例如同时应用程序请求)。它易于使用,并提供多种查看报告的方式。
编辑: 另外,正如 @duffymo 所建议的,已经有开箱即用的拦截器,带有用于 jamon 集成的弹簧。 此链接可能会提供方向。
Have a look at JAMon API.
JAMon gathers aggregate performance statistics such as hits, execution times (total, average, minimum, maximum, standard deviation), as well as concurrency information such as simultaneous application requests. It is easy to use and provides multiple ways to view the reports.
Edit: Also as suggested by @duffymo , there are already available interceptors out of the box with spring for jamon integrarion. This link may provide a direction.
是的,我会看看 Spring 拦截器 和 AOP 提供“做得更好”的解决方案。也许 org.springframework.aop.interceptor.PerformanceMonitorInterceptor 会立即执行您想要的操作。
如果没有任何现成的拦截器能够满足您的需求,那么扩展接口、根据您的具体要求编写自己的拦截器并使用 Spring 配置将其编织起来是一件很容易的事情。
Yes, I'd look at the Spring interceptors and AOP for a "do better" solution. Maybe
org.springframework.aop.interceptor.PerformanceMonitorInterceptor
will do what you want out of the box.If none of the out of the box Interceptors meet your need, it's an easy matter to extend the interface, write your own to your exact requirements, and weave it in using Spring configuration.
您可能还想编写自己的方法级计时和日志记录。 这是我写的一个示例,它展示了如何使用 Spring AOP 来实现这一点。
You might also like to write your own method-level timing and logging. Here is an example I wrote that shows how to do it with Spring AOP.