April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

HTTPD process check

HTTPD process check

The apache/httpd config file has a setting which determines how many running processes your apache /httpd daemon will commit to the system. The idea is, that if your web server needs more processes to handle more connections it will spawn a new child and serve the request.
If it is able it will kill the process off after and return it back into the pool.

prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves

StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000

I can spawn 256 additional child processes in the event that the systems needs them.
Any more, and the system will slow down while attempting to deal with the existing requests.
It is safe to assume that a normal web site serving hundreds of connections a minute (visitors) will consume approx 100 child processes.

You can count the number of processes spawned by running this very simple command (I use httpd, not apache2)

[root@localhost log]# pstree -G | grep httpd
??httpd???crlhelper
? ??9*[httpd]
? ??{httpd}

#!/bin/bash
# Apache check process script
HOSTNAME=`hostname`
THRESHOLD=180
ADDRTO=”admin@rmohan.com”
SUBJECT=”${HOSTNAME} – Apache Process Check”
LOCKFILE=”/tmp/apache_process_check.lock”
LOGFILE=”/var/log/apache_processes.log”

NUMHTTPD=`ps aux | grep http | grep -v “\(root\|grep\)” | wc -l`
echo “`date +’%Y-%m-%d %H:%M:%S %Z’` – ${NUMHTTPD}” >> ${LOGFILE}

if [[ ${NUMHTTPD} -gt ${THRESHOLD} ]]; then
if [ ! -e “${LOCKFILE}” ]; then
echo “The number of currently running httpd threads is ${NUMHTTPD}. Web services restarted” | mail -s “${SUBJECT} – Above Threshold” ${ADDRTO}
touch ${LOCKFILE}
service httpd stop && sleep 5 && service httpd start
fi
else
if [ -e “${LOCKFILE}” ]; then
rm -f “${LOCKFILE}”
fi
fi

SSH to your webserver you wish to run this script on
In the directory you wish to run the script, create the file and copy/paste the contents of the above script
Make changes to the ADDRTO and THRESHOLD variables as needed to suit your setup
Save the file then make it executable using chmod +x test.sh
Insert the script into crontab using

view source

1 */2 * * * * root /path/to/test.sh

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>