如何监控/记录 Tomcat 的线程池?
我有一个 Tomcat 安装,我怀疑由于线程未正确释放,线程池可能会随着时间的推移而减少。当达到 maxthreads 时,我在 catalina.out 中收到错误,但我想每五分钟将正在使用的线程数记录到一个文件中,以便我可以验证这个假设。有人可以建议如何做到这一点吗?
此外,在此安装中没有 Tomcat 管理器,看来最初安装的人出于某种原因删除了管理器 web 应用程序。我不确定经理是否能够执行上述操作,或者我是否可以在不损坏现有安装的情况下重新安装它?我真正想做的就是跟踪线程池。
另外,我注意到 Tomcat 的最大线程数为 200,但 Apache 的最大并发连接数较低(Apache 使用 mod_proxy 和 mod_proxy_ajp (AJP 1.3) 来提供 Tomcat)。这似乎也是错误的,这些数字之间的正确关系是什么?
非常感谢任何帮助:D
更新:只是一个快速更新,说明直接 JMX 访问有效。不过,我还必须设置 Dcom.sun.management.jmxremote.host。我将其设置为 localhost 并且它有效,但是没有它就没有骰子。如果其他人在尝试启用 JMX 时遇到类似问题,我建议您也设置此值,即使您是从本地计算机连接也是如此。似乎某些版本的 Tomcat 需要它。
简单更新一下,直接 JMX 访问有效。不过,我还必须设置 Dcom.sun.management.jmxremote.host。我将其设置为 localhost 并且它有效,但是没有它就没有骰子。如果其他人在尝试启用 JMX 时遇到类似问题,我建议您也设置此值,即使您是从本地计算机连接也是如此。似乎某些版本的 Tomcat 需要它。
I have a Tomcat installation where I suspect the thread pool may be decreasing over time due to threads not being properly released. I get an error in catalina.out when maxthreads is reached, but I would like to log the number of threads in use to a file every five minutes so I can verify this hypothesis. Would anyone please be able to advise how this can be be done?
Also in this installation there is no Tomcat manager, it appears whoever did the original installation deleted the manager webapp for some reason. I'm not sure if manager would be able to do the above or if I can reinstall it without damaging the existing installation? All I really want to do is keep track of the thread pool.
Also, I noticed that maxthreads for Tomcat is 200, but the max number of concurrent connections for Apache is lower (Apache is using mod_proxy and mod_proxy_ajp (AJP 1.3) to feed Tomcat). That seems wrong too, what is the correct relationship between these numbers?
Any help much appreciated :D
Update: Just a quick update to say the direct JMX access worked. However I also had to set Dcom.sun.management.jmxremote.host. I set it to localhost and it worked, however without it no dice. If anyone else has a similar problem trying to enable JMX I recommend you set this value also, even if you are connecting from the local machine. Seems it is required with some versions of Tomcat.
Just a quick update to say the direct JMX access worked. However I also had to set Dcom.sun.management.jmxremote.host. I set it to localhost and it worked, however without it no dice. If anyone else has a similar problem trying to enable JMX I recommend you set this value also, even if you are connecting from the local machine. Seems it is required with some versions of Tomcat.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
直接 JMX 访问
尝试将其添加到
catalina.sh
/bat
:更新:Alex P 建议在某些情况下可能还需要以下设置:
这会在端口 5005 上启用远程匿名 JMX 连接。您还可以考虑 JVisualVM,它更受欢迎,并且允许通过插件浏览 JMX。
您正在寻找的是
Catalina
->线程池
->http-bio-8080
->各种有趣的指标。JMX 代理 servlet
更简单的方法可能是使用 Tomcat 的 JMX 代理 servlet,如下: < a href="http://localhost:8080/manager/jmxproxy">http://localhost:8080/manager/jmxproxy。例如,尝试以下查询:
一点点
grep
ping 和脚本编写,您就可以轻松远程监控您的应用程序。请注意,tomcat:tomcat
是conf/tomcat-users.xml
中具有manager-jmx
角色的用户的用户名/密码。Direct JMX access
Try adding this to
catalina.sh
/bat
:UPDATE: Alex P suggest that the following settings might also be required in some situations:
This enables remote anonymous JMX connections on port 5005. You may also consider JVisualVM which is much more please and allows to browse JMX via plugin.
What you are looking for is
Catalina
->ThreadPool
->http-bio-8080
-> various interesting metrics.JMX proxy servlet
Easier method might be to use Tomcat's JMX proxy servlet under: http://localhost:8080/manager/jmxproxy. For instance try this query:
A little bit of
grep
ping and scripting and you can easily and remotely monitor your application. Note thattomcat:tomcat
is the username/password of user havingmanager-jmx
role inconf/tomcat-users.xml
.您可以部署 jolokia.war ,然后检索 JSON 中的 mbean 值(无需管理器):
< a href="http://localhost:8080/jolokia/read/Catalina:name=%22http-nio-8080%22,type=ThreadPool?ignoreErrors=true" rel="nofollow noreferrer">http://localhost:8080/jolokia/read/Catalina:name=*,type=ThreadPool?ignoreErrors=true
如果您只需要一些值(currentThreadsBusy、maxThreads、currentThreadCount、connectionCount) ):
<一href="http://localhost:8080/jolokia/read/Catalina:name=%22http-nio-8080%22,type=ThreadPool/currentThreadsBusy,maxThreads,currentThreadCount,connectionCount?ignoreErrors=true" rel="nofollow noreferrer">http://localhost:8080/jolokia/read/Catalina:name=*,type=ThreadPool/currentThreadsBusy,maxThreads,currentThreadCount,connectionCount?ignoreErrors=true
注意:本示例适用于 Tomcat7+。
You can deploy jolokia.war and then retrieve mbeans values in JSON (without the manager):
http://localhost:8080/jolokia/read/Catalina:name=*,type=ThreadPool?ignoreErrors=true
If you want only some values (currentThreadsBusy, maxThreads, currentThreadCount, connectionCount):
http://localhost:8080/jolokia/read/Catalina:name=*,type=ThreadPool/currentThreadsBusy,maxThreads,currentThreadCount,connectionCount?ignoreErrors=true
Note: This example works on Tomcat7 +.
寻求更具企业级的解决方案。我一直在我们的生产环境中使用 New Relic。
这提供了线程池随时间变化的图表。
For a more enterprise solution. I have been using New Relic in our production environment.
This provides a graph of the changes to the threadpool over time.
同时还有更便宜的工具:我在这里使用这个罐子: https://docs.cyclopsgroup.org/jmxterm< /a>
您可以通过 shell/批处理脚本将其自动化。我对输出进行了正则表达式处理,并让 prometheus 轮询它以在 grafana 中显示它。
There are cheaper tools out meanwhile: I am using this jar here: https://docs.cyclopsgroup.org/jmxterm
You can automate it via shell/batch scripts. I regexed the output and let prometheus poll it for displaying it in grafana.