As a web-server hosting an application for a client, which is high-volume or transaction server, I am required to find out "number of concurrent connections" currently in use by the server. This is required for a solution e.g NGFW, or WAF that is based upon this metric.

Can I run some script or built-in plugin to find this number? I need solution for Apache as well as IIS.

  • Most tools really cannot tell you concurrent users in any real sense because processing times are short and any tool cannot track session state well if at all. You will have to do some calculations yourself. However, most log file analyzers can really help. Piwik is one of the very best and completely free. Another option is to use Google Analytics, however, this does not include all traffic such as bots which is often vary large so that is limited too.
    – closetnoc
    Sep 11 '17 at 16:14
  • Asked & answered for Apache already: webmasters.stackexchange.com/questions/24687/… Sep 13 '17 at 7:30
  • Asked & answered for IIS too, total time searching took one minute: stackoverflow.com/questions/9181015/… Sep 13 '17 at 7:31

What you can do is run your website on a server that you have full back-end access to (such as a dedicated server) and enter the shell and see how many times the server program is running from a system monitor program. Since I use linux, I'll explain for that OS which is what half the servers run on anyway.

option 1

I have a setup in which apache is the server and run in prefork mode which is basically one instance of the apache app (named httpd).

When the server is running, in the shell, you can use the command TOP to get a live text-based version of what apps are running as well as the CPU and memory usage of each app.

Use the > and < key to sort the values until you see a bunch of lines in which the command is httpd. That will tell you how many apache processes (httpd) are ready to serve user requests. Now look at the percentage of CPU usage next to each. For each one where the CPU percent is high, that process is used up and the next user that wants access will use the next process and so on. That is one way you can get an idea as to how many concurrent connections are being processed per second.

option 2

Figure out what port your server listens to for managing website requests. This would normally be port 80 for HTTP and I believe port 443 for HTTPS.

I cannot remember the complete command off-hand for linux, but there is one you can enter that shows you at that moment how many connections are in use

In the unix command line type:

lsof | grep TCP | grep httpd

Then you'll see all your apache processes. along with a keyword in brackets at the end of each line. LISTEN means the process is ready for a new connection and ESTABLISHED means the connection is made, and anything else... you can safely assume the process is used for a connection.

I'm not sure if any of these work as good for the other apache modes except for prefork, but this should be a starting point for you for real-time capturing of number of concurrent connections per request for information.

As for per-second, the best you can do is write a script that calls the above command then determines how many concurrent connections there are per command execution and does that a few times or so per second, and which ever count is the highest can be considered the number of connections per second.

idea for IIS

If you're looking for a solution for IIS, it may be more difficult because linux offers a-lot of unix programs specifically for managing internet and Windows is a bit behind the game. For IIS, I'd contact microsoft to see if they have some sort of command-line utility that reports the number of connections to the computer through port 80 (http) or 443 (https) and then write a script to extract the relevant information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.