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:

  • Log all virtualhosts to the same access.log file
  • Use mod_status to allow a real-time viewing of all the server's activity.

Using mod_status you get to see:

  • The number of children serving requests
  • The number of idle children
  • The status of each child, the number of requests that child has performed and the total number of bytes served by child
  • A total number of accesses and byte count served
  • The time the server was started/restarted and the time it has been running for
  • Averages giving the number of requests per second, the number of bytes served per second and the average number of bytes per request
  • The current percentage CPU used by each child and in total by Apache
  • The current hosts and requests being processed

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:

 

 


Posted by Steve (82.41.xx.xx) on Mon 13 Jun 2005 at 05:34
[ Send Message | View Steve's Scratchpad | View Weblogs ]

I almost included an example, but by the time I've editted out the IP addresses and hostnames there's little point..

Google can find many - such as this one which shows you what you can expect.

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (62.254.xx.xx) on Mon 13 Jun 2005 at 17:11
another handy article, i really do think this site is a great benefit to n00bs like myself :)

sno

[ Parent | Reply to this comment ]

Posted by Anonymous (130.231.xx.xx) on Fri 17 Jun 2005 at 20:24
Some systems (munin?) can also (be made to) graph some of the information.

[ Parent | Reply to this comment ]

Posted by Anonymous (151.41.xx.xx) on Sat 18 Jun 2005 at 12:25
> Once you've made these changes you can restart your
> server with:

> /etc/init.d/apache restart

Should be sufficient do a reload with:

/etc/init.d/apache reload

[ Parent | Reply to this comment ]

Posted by Anonymous (70.48.xx.xx) on Mon 27 Jun 2005 at 00:39
Thanks Steve!
That a great article; straightforward, clear and useful!

Say here's a silly question "Why does this not appear in /etc/apache2/mods-available/ ?".
Any one got a simple rule/explanation for these ?

Thx again Steve.

[ Parent | Reply to this comment ]

Posted by csmall (203.111.xx.xx) on Wed 29 Jun 2005 at 02:15
[ Send Message ]
The package JFFNMS is able to parse the information from Apache's mod_status output and make nice graphs about it.

Of course I would not install JFFNMS just for this feature as it is much more than just an Apache mod_status graph thingy, but worth checking out if you need to monitor a variety of things. NMS stands for Network Management System which is a program for monitoring servers and network equipment like switches and routers.

It's also packaged in Debian.

[ Parent | Reply to this comment ]

Posted by Anonymous (200.128.xx.xx) on Wed 10 Aug 2005 at 16:53
What package contain this mod?

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 10 Aug 2005 at 16:55
[ Send Message | View Steve's Scratchpad | View Weblogs ]

From the article:

This module is available as part of a standard installation of either the Apache 1.x or Apache 2.x packages .

ie. It is included in any of the Debian Apache packages - either the plain Apache package, or any of the Apache2 packages.

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (200.128.xx.xx) on Wed 10 Aug 2005 at 17:02
I see that part, but I installed the package apache2-common, but don't have this module...

local:/etc/apache2# dpkg -L apache2-common | grep modules
/usr/lib/apache2/modules
/usr/lib/apache2/modules/mod_auth_anon.so
/usr/lib/apache2/modules/mod_auth_dbm.so
/usr/lib/apache2/modules/mod_auth_digest.so
/usr/lib/apache2/modules/mod_file_cache.so
/usr/lib/apache2/modules/mod_cache.so
/usr/lib/apache2/modules/mod_disk_cache.so
/usr/lib/apache2/modules/mod_mem_cache.so
/usr/lib/apache2/modules/mod_ldap.so
/usr/lib/apache2/modules/mod_auth_ldap.so
/usr/lib/apache2/modules/mod_ext_filter.so
/usr/lib/apache2/modules/mod_include.so
/usr/lib/apache2/modules/mod_deflate.so
/usr/lib/apache2/modules/mod_mime_magic.so
/usr/lib/apache2/modules/mod_cern_meta.so
/usr/lib/apache2/modules/mod_expires.so
/usr/lib/apache2/modules/mod_headers.so
/usr/lib/apache2/modules/mod_usertrack.so
/usr/lib/apache2/modules/mod_unique_id.so
/usr/lib/apache2/modules/mod_proxy.so
/usr/lib/apache2/modules/mod_proxy_connect.so
/usr/lib/apache2/modules/mod_proxy_ftp.so
/usr/lib/apache2/modules/mod_proxy_http.so
/usr/lib/apache2/modules/mod_ssl.so
/usr/lib/apache2/modules/mod_dav.so
/usr/lib/apache2/modules/mod_asis.so
/usr/lib/apache2/modules/mod_info.so
/usr/lib/apache2/modules/mod_suexec.so
/usr/lib/apache2/modules/mod_cgid.so
/usr/lib/apache2/modules/mod_cgi.so
/usr/lib/apache2/modules/mod_dav_fs.so
/usr/lib/apache2/modules/mod_vhost_alias.so
/usr/lib/apache2/modules/mod_imap.so
/usr/lib/apache2/modules/mod_actions.so
/usr/lib/apache2/modules/mod_speling.so
/usr/lib/apache2/modules/mod_userdir.so
/usr/lib/apache2/modules/mod_rewrite.so
/usr/lib/apache2/modules/httpd.exp
I put the lines in my config file, but I want use the option "ExtendedStatus on", and I need the mod_status... In apache 1.3 works fine...

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 10 Aug 2005 at 17:04
[ Send Message | View Steve's Scratchpad | View Weblogs ]

My apologies the module is called mod_info in Apache2.

That should help. To enable it run:

a2enmod info

Then setup the handler as described above.

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 10 Aug 2005 at 17:07
[ Send Message | View Steve's Scratchpad | View Weblogs ]

(Article updated)

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (170.140.xx.xx) on Fri 27 Apr 2007 at 01:47
In My Etch install mod_status and mod_info are two different things; mod_info returns the apache configuration, not the status. Mod_status seems to be loaded by default but commented out in apache2.conf

[ Parent | Reply to this comment ]

Posted by Anonymous (82.141.xx.xx) on Tue 6 May 2008 at 14:31
mod_status is included in etch's apache2, so you don't need load, but the "status.conf" is needed

[ Parent | Reply to this comment ]

Posted by rmello (66.239.xx.xx) on Thu 29 May 2008 at 16:49
[ Send Message ]
This article is incorrect in instructing users to enable mod_info on Apache2. The information is provided by mod_status in Apache2 as well as Apache1. Just make sure you uncomment the Location entry for server-status in apache2.conf, or add a /etc/apache2/mods-available/status.conf file and symlink to it from mods-enabled.

[ Parent | Reply to this comment ]

Posted by Anonymous (173.228.xx.xx) on Thu 2 Sep 2010 at 22:56
thank you very much for the clear tutorial

[ Parent | Reply to this comment ]

Posted by Anonymous (115.111.xx.xx) on Wed 27 Feb 2013 at 04:16
Hi, Thanks for your help. I want to monitor concurrent incoming traffic on Apache. I have also used mrtg with snpm. but it also not giving real status.
Is it possible by mod_info. Please help.

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

Which init system are you using in Debian?






( 1060 votes ~ 6 comments )

 

 

Related Links