Enabling and using apache's mod_status on CentOS, Fedora, Red Hat Enterprise Linux, Gentoo and Arch
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.
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.
The default installation of apache usually has mod_status enabled, but this must be verified. Open the apache configuration file at:
mod_status, or scroll down until you find a line containing:
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.
Note:To enable mod_status on Gentoo, you'll need to add the "STATUS" keyword to apache's start options. Open the configuration file at:
Edit the list of keywords in the APACHE2_OPTS setting to include "-D STATUS", similar to:
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5 -D STATUS"
That keyword is used to tell apache to load the configuration file for mod_status, which is:
In the httpd.conf file, scroll down until you find the following section:
# Allow server status reports generated by mod_status, # with the URL of http://servername/server-status # Change the ".example.com" to match your domain to enable. # # # SetHandler server-status # Order deny,allow # Deny from all # Allow from .example.com #
If you haven't set up any virtual hosts in apache (i.e. you're using the default configuration), you'll be editing this configuration block in place.
If you have created one or more virtual hosts, you'll want to paste this configuration for the
/server-status location into the default virtual host for any domains configured in apache (any domains that could return something if you request "domainname.com/server-status"). Then you would make any needed changes to the Location configuration block in each file.
In either case, the first change to make to this configuration block is to uncomment (remove the
# characters from the front of) the lines that contain the location configuration from between "" to "", inclusive.
The other change you'll need to make is to the
Allow from .example.com line. This setting should reflect what host or range of hosts you want to allow to view your server status page. We recommend setting that permission to
localhost only so user's outside your network can't see detailed information about your web server. We'll talk about how you'll be able to view the status page from the server itself in a later section.
The altered Location block you'll ultimately want in either your httpd.conf file or your default virtual host configuration file would (if restricted to localhost) look like:
SetHandler server-status Order deny,allow Deny from all Allow from localhost
One more change you 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.
The ExtendedStatus setting must be set at the server level and applies to all virtual hosts running under apache. To enable it edit the httpd.conf file and look for the following entry:
# 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 Uncomment that last line to enable ExtendedStatus, changing the configuration block to: # 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
Note:On Gentoo, the mod_status configuration file will be:
On Arch, the configuration file will be:
Include line for that config file is commented out in httpd.conf by default.
Now that we've made sure the apache server status page is enabled and configured the way we want it, we'll need to restart apache:
sudo /usr/sbin/apachectl 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. Because the server status page is text with no graphics, you can 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 yum install lynx
Note:to install lynx on Gentoo:
sudo emerge --sync sudo emerge 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 added to end of the domain. In this section we're assuming you've configured your default server instance or virtual host to accept connections from the localhost 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 it 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 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 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).
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, click here. 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 mod_php.
- 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).
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