Java 找出到tomcat服务器的连接数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2209687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find out the number of connections to tomcat server
提问by Thunderhashy
I have a Java/Java EE web application deployed on Tomcat Server 5.5.17. I want to know the number of clients which are connected to the server. How can we find it out?
我在 Tomcat Server 5.5.17 上部署了一个 Java/Java EE Web 应用程序。我想知道连接到服务器的客户端数量。我们怎样才能找到它?
采纳答案by BalusC
Most reliable way would be to search for ip.addr.of.srv:port
in netstat
. Here's the Windows based example (sorry, no Linux guru here ;) )
最可靠的方法是ip.addr.of.srv:port
在netstat
. 这是基于 Windows 的示例(抱歉,这里没有 Linux 大师;))
netstat -np tcp | find "12.34.56.78:80"
Replace 12.34.56.78
by IP where Tomcat listens on and 80
by port where Tomcat listens on.
替换12.34.56.78
为 Tomcat 侦听的 IP 和 Tomcat 侦听80
的端口。
This is actually not a programming problem, hence I voted to migrate this question to serverfault.com.
这实际上不是编程问题,因此我投票决定将此问题迁移到serverfault.com。
回答by Thimmayya
See the section under Tomcat Managerfor an example of counting the sessions in a webapp.
有关计算 web 应用程序中会话的示例,请参阅Tomcat 管理器下的部分。
Counting the number of connections is probably a bit harder. Tomcat starts a new thread for each request coming in up to a maximum of maxProcessors
. Beyond this number, the requests are queued up to a maximum of acceptCount
. Requests beyond this number are refused/dropped (or crashes, I am not sure). The properties can be monitored using a JConsole: Steps here. The specific properties mentioned above are properties of the HTTP Connector.
计算连接数可能有点困难。Tomcat 为每个请求启动一个新线程,最多maxProcessors
. 超过这个数量,请求最多排队acceptCount
。超过此数量的请求将被拒绝/丢弃(或崩溃,我不确定)。可以使用 JConsole 监视属性:此处的步骤。上面提到的具体属性是HTTP Connector 的属性。
EDIT 1:
编辑 1:
After looking through source code of CoyoteConnector and AJP Connector, there is a private property called curProcessors
which tracks the number of processors currently in use. However, adding the curProcessors variable to the mbeans file for connectors does not seem to display the current value in the JConsole display.
在查看 CoyoteConnector 和 AJP 连接器的源代码后,有一个称为curProcessors
跟踪当前使用的处理器数量的私有属性。但是,将 curProcessors 变量添加到连接器的 mbeans 文件中似乎不会在 JConsole 显示中显示当前值。
Note: The mbeans XML file that I modified was in tomcat\server\lib\catalina.jar and is in the org\apache\catalina\connector directory in the jar. Below is an example of the entry I added:
注意:我修改的 mbeans XML 文件在 tomcat\server\lib\catalina.jar 中,在 jar 的 org\apache\catalina\connector 目录中。以下是我添加的条目的示例:
<attribute name="curProcessors"
description="the number of processors currently in use"
type="int"/>
回答by vsingh
And if you need to figure to what each connection is doing , use this on linux
如果您需要弄清楚每个连接在做什么,请在 linux 上使用它
netstat -an | grep :8080 | awk '{print }'
If there are three connections , you will see
如果有三个连接,您将看到
LISTEN TIME_WAIT TIME_WAIT
听 TIME_WAIT TIME_WAIT
And if you only want to count connections which are in TIME_WAIT state
如果您只想计算处于 TIME_WAIT 状态的连接数
netstat -an | grep :8080 | grep TIME_WAIT | wc -l