从 Servlet(或过滤器)访问 Tomcat 内部
我想从 servlet(或过滤器)访问 Tomcat 内部数据。特别是,我想从线程池管理器中读取有关繁忙线程的信息。所以,我的问题是这是否可能(我可以想象它可能出于安全原因被阻止)?如果可能的话,也许有人可以给我任何从哪里开始的建议(一些入口点单例等)?
我知道,我可以通过 JMX 检索此信息。但我更喜欢直接 API(因为 JMX 可能相当重,不是吗?)。
I would like to get access to the Tomcat internal data from a servlet (or filter). In particular, I would like to read information about busy threads, from thread pool manager. So, my question is if it is possible at all (I can imagine that it could be blocked for safety reason)? If it's possible, maybe someone could give me any advice where to start (some entry point singleton, etc.)?
I know, that I could retrieve this information through the JMX. But I would rather prefer direct API (because the JMX is probably quite heavy, isn't it?).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ServerFactory#getServer () 有帮助吗?它提供对运行 servlet/filter 的 Tomcat 服务器实例的访问。从那里,您也许能够深入查找所需的信息/
回答您关于 JMX 是否“繁重”的问题:可能不会。如果您只是定期监视数据,那么应该没问题,特别是如果您通过平台 MBeanServer 访问同一虚拟机内的 mbean
Would ServerFactory#getServer() help? It provides access to the Tomcat Server instance that the servlet/filter is running in. From there, you might be able to dig down to find the information you need/
To answer your question regarding JMX being "heavy": probably not. If you're just doing periodic monitoring of the data, you should be fine, especially if you're accessing the mbeans inside the same VM through the platform MBeanServer
您到底想实现什么目标? Lambda Probe 是一个优秀的 Tomcat 监控工具,可能有您想要的东西。
What exactly are you trying to accomplish? Lambda Probe is an excellent monitoring tool for Tomcat that might have what you're looking for.
在测试了不同的方法之后,我最终决定使用 JMX。开销似乎没有我预期的那么重要。
After testing different approaches I eventually decided to use JMX. The overhead appeared to be less significant that I had expected.