Find out the number of connections to tomcat server

后端 未结 3 1588
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-03 10:55

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?

相关标签:
3条回答
  • 2021-02-03 11:08

    See the section under Tomcat Manager for an example of counting the sessions in a webapp.

    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.

    EDIT 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.

    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:

    <attribute   name="curProcessors"
        description="the number of processors currently in use"
        type="int"/>
    
    0 讨论(0)
  • 2021-02-03 11:15

    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 ;) )

    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.

    This is actually not a programming problem, hence I voted to migrate this question to serverfault.com.

    0 讨论(0)
  • 2021-02-03 11:15

    And if you need to figure to what each connection is doing , use this on linux

    netstat -an | grep :8080 | awk '{print $6}'
    

    If there are three connections , you will see

    LISTEN TIME_WAIT TIME_WAIT

    And if you only want to count connections which are in TIME_WAIT state

    netstat -an | grep :8080 | grep TIME_WAIT | wc -l
    
    0 讨论(0)
提交回复
热议问题