By default, Apache supports 150 concurrent connections. Sometimes you may need to find the concurrent users in Apache server. In this article, we will look at how to check number of concurrent connections in Apache. You can also use these steps to find concurrent users for any server running on port 80.
How to Check Number of Concurrent Connections in Apache
Here are the steps to check number of concurrent connections in Apache. There are numerous ways to count the number of connections to your Apache server. You can use any of the following commands to do so.
1. Using Netstat
You can use any of the following netstat commands to check number of concurrent connections to Apache. Netstat command lists all active connections. We pass its output to grep where search for “80” since Apache runs on port 80. This gives a list of all active connections to Apache. We pass this output to wc command to count the number of lines, that is, number of connections.
netstat -nt | grep :80 | wc -l
netstat -plan|grep :80 | wc -l
netstat -an | grep 'EST' | wc -l
netstat -ant | grep ESTABLISHED | grep :80 | wc -l
Also read : How to Remove index.php from URL in CodeIgniter
2. Optional commands
If you want to list all active connections to Apache server, instead of counting them, skip the wc command above.
netstat -an | grep :80 | sort
netstat -plan | grep :80
netstat -anp | grep :80
If you want to count the number of active connections from each IP, use the following command.
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
It will list all IPs connected to your server along with number of incoming connections.
If you only want to list IPs with TCP/UDP connections use the following command.
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
That’s it. In this article, we have learnt how to check concurrent connections to Apache server. In fact, you can use these steps to count number of incoming connections to any server such as NGINX, Gunicorn, etc that runs on port 80.
Also read : How to Generate Subdomains on the fly
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.