Finding out Average and Peak Number of Concurrent Connections for Apache

In order to optimize Apache’s configuration we needed “Average and Peak Number of Concurrent Connections” but we didn’t have an external software like Prometheus or Zabbix to record and analyze historical data.
So we needed to find a way with what we had at hand. First comes to mind:

  1. Daily Process Log in WHM:
    1. This log provides a snapshot of your server’s activity throughout the day, including the number of connections. You can manually check this log at different times of the day to get an idea of the average and peak number of connections.
  2. Apache’s access_log
    1. This log records all requests processed by the server. You can write a script to parse this log and count the number of requests in each time interval (e.g., each minute or each hour). This will give you the number of connections over time, from which you can calculate the average and peak number of connections.
  3. AWStats
    1. AWStats provides a summary of your server’s traffic, including the number of visits and hits. You can use this data to get an idea of the server’s load. However, AWStats does not directly provide the number of concurrent connections.

Daily Process Log in WHM give you a good idea who uses the most traffic but without any connection numbers

awk '{print $4}' /var/log/apache2/access_log | cut -d: -f1,2 | uniq -c | awk '{ total += $1; count++ } END { print total/count }'

This command does the following:

  • awk '{print $4}' /var/log/apache2/access_log | cut -d: -f1,2 | uniq -c : This part is the same as before. It counts the number of requests for each minute.
  • awk '{ total += $1; count++ } END { print total/count }' : This part calculates the average. It adds up the number of requests ($1 refers to the first field, which is the count of requests) and increments a counter for each line. At the end (END), it prints the total divided by the count, which is the average.

This will give you the average number of connections per minute. If you want the average number of connections per hour or per day, you can modify the cut -d: -f1,2 part to cut out the hour or day part of the timestamp.

And to find peak connections

awk '{print $4}' /var/log/apache2/access_log | cut -d: -f1,2 | uniq -c | sort -nr | head -n 1

You can change the -n 1 to -n 3 or -n 10 to list top 3 or top 10 concurrent times.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *