Monitor Apache’s Performance with “mod_status” Module November 22, 2012Posted by Tournas Dimitrios in Linux.
Apache’s Status module (mod_status) allows a server administrator to find out how well his web-server is performing . All reports are generated in a html format and can be accessed via a graphical or text-based browser (terminal browser — lynx — ) . Accessing the html page produces an snapshot of Apache’s status (static content) , using a compatible browser though , a mirror of live statistics can be displayed (made by automatically refresh) . While we can get the same information by checking Apache’s access log-files or by using regular Linux / UNIX commands such as lsof – netstat – top – vmstat (and others) , it’s obvious how convenient our Apache monitoring tasks can be when all these information is gathered into one single access point . Although this module (mod_status) is installed by default on all Apache installations , it must be enabled from within Apache’s configuration file . Some of the details that are revealed by mod_status are listed below :
- Averages giving the number of requests per second
- The number of worker serving requests
- The number of idle worker
- The status of each worker, the number of requests that worker
- The time the server was started/restarted and the time it has been running for
- If mod_status is configured in extended-status , more details are displayed . Keep in mind though , the collection of extended status information can slow down the server.
The Apache Project keeps their server status page available to the general public .
Of course , we don’t want these information to be publicly accessible (hope it’s obvious) , so we will configure Apache’s configuration file to serve mod_status statistics only to local requests (via a text-based browser — lynx — ) . The process of enabling and configuring of mod_status is done from within Apache’s configuration file . This article presents the configurations made on a CentOs 6 installation (/etc/httpd/conf/httpd.conf ) , there shouldn’t be significant differences on other distributions though . Here follows the configuration process :
- Comment out the line with the following directive :
LoadModule status_module modules/mod_status.so
If there is a “#” character in front of LoadModule , that means mod_status is disabled . Remove the # to enable mod_status
- Still in httpd.conf , scroll down until you find the following section
Just un-comment lines 922 up-to line 927 (by removing the # ) , or duplicate these lines (as I did) . Notice the “Allow from” line , set it to 127.0.0.1 (this will restrict access only to localhost) .
If you had created one or more virtual hosts , you’ll want to paste this configuration for the /server-status location into the default virtual host for every domain configured in Apache’s configuration file . “example.com/server-status“). Then you would need to change each “<Location /server-status> ” line on every virtual host section . For instance , <Location http://www.example1.com/server-status> , <Location http://www.anotherexample.com/server-status> .
- Enabling ExtendedStatus : This setting adds more information to the status page Apache returns , like CPU use and requests per second . Enabling this directive makes Apache do a little extra work when it gets a status request , so you might get a performance hit on a busy server . Some monitoring applications , like munin , require that this directive is enabled before they can monitor Apache . Find the following line and un-comment it :
- Restart Apache
service httpd restart (on CentOs)
apachectl restart (on all distro’s)
- Installing a text-based browser (lynx) : With Apache’s status page restricted to localhost access we won’t be able to see the page from a web browser , so a terminal based browser will be installed .
yum install lynx
- Let’s have fun !
Most of the server status page statistics should be pretty self-explanatory . Most notable indication is the “CPU Usage” ( high CPU usage could indicate a problem with an running application –mod_php — , time to upgrade your server’s RAM ) . Another indication , the “__” waiting for connection , can be configured by increased by Apache’s “MaxClients” directive .
Of course , bench-marking Apache is out of the scope of this article . Factors that influence the results taken from mod_status are : hardware/platform that Apache is installed on , how many modules were initialized during Apache’s start-up process , how Apache was compiled ( prefork , worker , event ) and many more .