Enabling and using apache's mod_status on Debian and Ubuntu
mod_status module allows it to display a web page containing statistics about the web server's current state, including worker processes and active connections.
What is mod_status?
While you can get information on the connections being made to apache by checking the access log, if you want more immediate information about what apache is up to you can enable
mod_status. This module allows you to view a detailed status page for your web server. This information can be useful for watching your web server's performance during load testing or for allowing a monitoring program like munin or mrtg to gather activity data for later aggregation.
The Apache Project keeps their server status page available to the general public. To get a look at a fairly busy web site's status page, visit:
The default installation of apache usually has
mod_status enabled, but verify this. Check the contents of apache's enabled modules directory:
status.load. If those files aren't listed in that directory, you will need to enable
mod_status by running:
sudo /usr/sbin/a2enmod status
To enable access to the server status page, we'll need to add a
Location directive entry to the default virtual hosts for any domains configured for apache. If you haven't added any new virtual hosts to the default apache configuration, you need only edit the virtual host file at:
Add to each virtual host file that needs to be edited the following section, within the
VirtualHost configuration block:
SetHandler server-status Order deny,allow Deny from all Allow from localhost
Allow from localhost can be changed if you want to allow remote access to the apache status page, but we don't recommend it. We'll talk about how you'll be able to view the status page from the server itself in a later section.
One more change we may want to make is to enable the
ExtendedStatus setting in apache. This setting adds more information to the status page apache returns, like CPU use and requests per second. Enabling
ExtendedStatus makes apache do a little extra work when it gets a status request, so you might weigh the extra information gained against the potential performance hit to a busy server.
Many monitoring applications that record performance over time, like munin, require that
ExtendedStatus be enabled before they can monitor apache.
ExtendedStatus setting must be set at the server level and applies to all virtual hosts running under apache. We'll add this configuration option as a configuration snippet in apache's
conf.d directory, to make it easy to find and change later if necessary. Create and edit the file:
Add the following lines to the
extendedstatus file to enable
# ExtendedStatus controls whether Apache will generate "full" status # information (ExtendedStatus On) or just basic information (ExtendedStatus # Off) when the "server-status" handler is called. The default is Off. # ExtendedStatus On
ExtendedStatus later, either delete the extendedstatus file or change the setting in the file from
Now that we've made sure the apache server status page is enabled and configured the way we want, we'll need to restart apache:
sudo /usr/sbin/apache2ctl restart
With apache's server status page restricted to
localhost-only access we won't be able to see the page from our desktop's web browser. Fortunately the server status page is just a bunch of text with no graphics, letting us use a simple approach: Run a text-based web browser while logged into the server itself.
To try this option out we'll need to install a browser on the server first. The browser we'll use is called Lynx, and you can install it with the following command:
sudo aptitude install lynx
No configuration is necessary, but Lynx is keyboard-controlled so it is handy to know a few basic keystrokes when using it. There is a list of the most frequently-used commands at the bottom of the screen while Lynx is running. If you visit a site with Lynx you can navigate with the up and down keys and follow a highlighted link by hitting enter. Hit
q to quit (and hit
y to confirm the quit). Hit
h to access Lynx's documentation.
View the status page
The URL of the apache status page will be your domain name with
/server-status tacked onto the end. In this section, we assume you've configured your default server instance or virtual host to accept connections from the local host only. Tell Lynx to view your apache status page with the following command:
You will see something like the following page if you have
ExtendedStatus enabled (the example server was running Ubuntu Hardy, but should look similar for all recent versions of Linux and Apache). With ExtendedStatus disabled the page will look similar, but with a few lines missing.
Apache Status (p1 of 2) Apache Server Status for localhost Server Version: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch Server Built: Nov 13 2009 21:58:02 ______________________________________________________________________________ Current Time: Friday, 26-Mar-2010 19:04:17 UTC Restart Time: Friday, 19-Mar-2010 20:21:03 UTC Parent Server Generation: 1 Server uptime: 6 days 22 hours 43 minutes 14 seconds Total accesses: 386 - Total Traffic: 317 kB CPU Usage: u0 s0 cu0 cs0 .000643 requests/sec - 0 B/second - 840 B/request 1 requests currently being processed, 9 idle workers W_________...................................................... ................................................................ ................................................................ ................................................................ Scoreboard Key: "_" Waiting for Connection, "S" Starting up, "R" Reading Request, "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup, "C" Closing connection, "L" Logging, "G" Gracefully finishing, "I" Idle cleanup of worker, "." Open slot with no current process Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request 0-1 3425 0/36/45 W 0.00 0 0 0.0 0.04 0.04 127.0.0.1 www.example.com GET /server-status HTTP/1.0 1-1 3426 0/44/58 _ 0.00 4277 0 0.0 0.04 0.05 18.104.22.168 www.example.com GET /favicon.ico HTTP/1.1 -- press space for next page -- Arrow keys: Up and Down to move. Right to follow a link; Left to go back. H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list
If you get an error, troubleshoot accordingly. A
not found error would indicate that mod_status isn't properly enabled. A
forbidden error would mean that the Location configuration for
/server-status is restricting you from accessing the page. A
connection refused error means apache isn't listening on port 80 and may not be running.
Scoreboard Key, there will be a list of current connections, including the source addresses and the file being accessed.
Most of the server status page should be self-explanatory. The apache version is listed at the top, along with some of the modules loaded in apache. Some important stats following that include how long the apache server has been running since last restart, the traffic is has handled since then, how much CPU is being used by apache at that moment, and how frequently apache is serving requests.
The section between the number of current requests and the Scoreboard Key is a representation of apache's workers and their status. The worker is essentially apache's request handler. Apache keeps several active at a time.
The Scoreboard Key shows what each symbol in the worker list means. In the example you can see the apache server isn't very busy - several
_ characters show a handful of workers waiting for requests, while a lone
W shows a worker replying to a request (the request for the server status page, in fact). All the periods show slots that could be filled with workers if the server gets busy enough to need them.
If you visit the Apache Project's server status page you can see a more active server and a greater variety of worker states, like
K (keep-alive, a reused connection waiting for a new request from a browser),
R (reading a request from a browser), and
C (closing a terminated connection).
Yes, but what does it all mean?
Most often the
mod_status output is used by other tools to chart the server's activity over time. Viewed directly, the status page is handy for a quick overview of what your server is doing at a given moment. Some of the displayed data can indicate problems that merit investigation.
Examples of items to watch for on the status page include:
- A high CPU usage for apache could indicate a problem with an application being run through a module like
- While it is normal to see several keep-alives being handled by apache's workers, if they constitute a vast majority of the worker statuses you see then your web server might be keeping old connections alive too long. You may want to look into reducing the amount of time connections are kept alive by apache via the KeepAliveTimeout directive.
- If you see very few inactive workers (represented by
.characters) you may want to increase the MaxClients value for your apache server. Making sure you have idle workers ready to handle new requests can improve the web server's responsiveness (assuming you have enough memory on the server available to handle the extra connections).
Apache's status module is a handy complement to a monitor program, and the snapshot it provides of a web server's activity can highlight problems that would be otherwise difficult to isolate using standard system tools like top and lsof. Even if you're only enabling
mod_status for a monitoring tool, knowing how to access and read the status page can help you be a more effective web server administrator.
For more information about
mod_status and the details it reports check the Apache mod_status documentation.
© 2015 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
See license specifics and DISCLAIMER