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.xEnabling For Apache 2.xThe 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.soOnce you've made these changes you can restart your server with:
/etc/init.d/apache restart
Keeping Access SecureThe 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 infoTo 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 OnOnce this is done you can reload your server by running:
/etc/init.d/apache2 force-reload
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.ddThe 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:
sno
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
> server with:
> /etc/init.d/apache restart
Should be sufficient do a reload with:
/etc/init.d/apache reload
[ Parent | Reply to this comment ]
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 ]
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 ]
[ Parent | Reply to this comment ]
[ 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 ]
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 ]
[ 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 ]
[ View Steve's Scratchpad | View Weblogs ]
(Article updated)
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
Is it possible by mod_info. Please help.
[ Parent | Reply to this comment ]
https://github.com/dioubernardo/apacheServerStatusCharts
[ Parent | Reply to this comment ]
[ 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 ]