Check Apache concurrent Connections using Netstat command

    Posted in Linux Servers on Oct 12, 2018

    When your server is hitting high & overload, you might want to check, how many active connections are there and which IP take maximum of hit/connection from apache.

    To Count Apache concurrent connection’s, use any of the below commands.

    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
    
    ps -A | grep httpd | wc -l
    
    ps -ef | grep http | wc -l
    
    ps aux | grep httpd | wc -l
    
    ps aux | grep http | grep -v "\(root\|grep\)" | wc -l

    To print the active Internet connections to the server at port 80 and sort the results, use the below commands.

    netstat -an | grep :80 | sort
    or
    netstat -plan | grep :80
    or
    netstat -anp | grep :80

    To calculate and count, number of connection currently established from each IP address with server.

    netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

    To calculate and count, number of connection currently established from each IP address through TCP or UDP protocol with server.

    netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

    To Print ESTABLISHED connections instead of all connections, and displays the connections count for each IP

    netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

    To print the list of IP address and its connection count, that connect to port 80 on the server.

    netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1

    To print all the apache httpd actual processes in Linux, use the below commands.

    ps -aux | grep httpd
    or
    ps -ef | grep httpd