Monitoring Apache with mod_status

Posted by Steve on Mon 13 Jun 2005 at 05:19

When you have an Apache server serving multiple virtual hosts it becomes difficult to keep track of what it's serving at each moment - because in most cases each virtual host will log to a different place, you cannot read all the logfiles simultaneously.

There are tools which will process a single apache logfile, and show you what is happening with a particular virtual host for example apachetop - but this will not allow you to view two or three virtual hosts at the same time.

If you're interested in this kind of information you've got a couple of choices:

Using mod_status you get to see:

This information can be restricted (and probably should be) to a particular IP address so that you don't leak information about the available virtual hosts, or the currently incoming requests.

This module is available as part of a standard installation of either the Apache 1.x or Apache 2.x packages which are available under Debian, and configuration is very straightforward.

Enabling For Apache 1.3.x

The default Apache package for Debian already contains the relevent server settings which are commented out.

To enable them uncomment the following section in the file /etc/apache/httpd.conf:

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .your_domain.com
</Location>

You should check that the module is loaded by making sure the following entry exists in /etc/apache/modules.conf:

LoadModule status_module /usr/lib/apache/1.3/mod_status.so

Once you've made these changes you can restart your server with:

/etc/init.d/apache restart
Enabling For Apache 2.x

The default Apache2 package for Debian already contains the relevent server settings which are commented out.

You will only need to ensure that you have the mod_info module loaded which you can do by running:

a2enmod info

To enable the handler uncomment the following section in the file /etc/apache2/apache2.conf:

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .your_domain.com
</Location>

You should also add the following just above that:

ExtendedStatus On

Once this is done you can reload your server by running:

/etc/init.d/apache2 force-reload
Keeping Access Secure

You should change the "Allow from .your_domain.com" to either restrict access to your domain, or to your IP address.

For example you could use:

Allow from .foo.com
Allow from aa.bb.cc.dd

The first allows access to all hosts who have the hostname "*.foo.com", the second allows access only to the machine with IP address aa.bb.cc.dd.

Once you've restricted the access to the IP address, or hosts, you control you should be ready to test it.

Because these default settings are global you can connect to any virtualhost your server is setup to handle and request the servr information page:

If all goes well you'll see an output page looking something like this:

Current Time: Monday, 13-Jun-2005 06:05:17 BST
Restart Time: Sunday, 12-Jun-2005 01:38:55 BST
Parent Server Generation: 0
Server uptime: 1 day 4 hours 26 minutes 22 seconds
Total accesses: 48895 - Total Traffic: 322.9 MB
CPU Usage: u158.75 s17.74 cu997.49 cs0 - 1.15% CPU load
.478 requests/sec - 3306 B/second - 6.8 kB/request
6 requests currently being processed, 14 idle workers

Below that you'll see the actual request details (which are only included if you have ExtendedStatus On in your configuration file).

If you request the page with a "refresh=N" parameter you can cause the status page to reload itself every N seconds. For example:


This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2005 Steve - please ask for permission to republish or translate.