Apache’s 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?
Mod_status is an Apache module that displays a web page containing statistics about the web server’s current state including worker processes and active connections. It helps to monitor web server load with an HTML interface via a web browser.
The status module allows a server administrator to find out how well their server is performing. An HTML page is presented that gives the current server statistics in an easily readable form. For more information on this Apache module, please see http://httpd.apache.org/docs-2.0/mod/mod_status.html.
Apache’s mod_status module shows you the following information:
- Restart Time
- Server Uptime
- Server Load
- CPU Usage and CPU Load
- Total incoming requests
- Total number of bytes and counts server
- Total number of idle and busy workers
- Total Traffic
- PIDs with respective client and many more.
You can see a demo of Apache’s status by visiting the following URL: http://www.apache.org/server-status
Enable mod_status in Apache
By default, mod_status module is enabled in Ubuntu 14.04. If not, you can enable it by running:
# a2enmod status
To enable access to the server status page, you need to edit the mod_status default configuration file located in the “/etc/apache2/mods-enabled/” directory. You can edit the “status.conf” file by running:
# vim /etc/apache2/mods-enabled/status.conf
Find the section Location /server-status, remove the # before the 192.0.2.0/24 line and add the IP address of the remote computer you will be using to access your web server:
<Location /server-status> SetHandler server-status Require local Require ip 192.168.1.20 </Location>
The above configuration is only for the default Apache website. If you have created one or more websites (Virtual Hosts), then the above configuration won’t work. You will need to configure the above settings for each virtual host. In this example let’s configure the Apache default virtual host for mod_status.
You can do this by editing the Apache default virtual host config file:
# vim /etc/apache2/sites-enabled/000-default.conf
Add the following lines under the section VirtualHost *:80:
<Location /server-status> SetHandler server-status Require local Require ip 192.168.0.161 </Location>
Save and close the file and restart Apache to reflect the changes.
# /etc/init.d/apache2 restart
How to Enable mod_status in Apache
The default Apache installation comes with mod_status enabled. If not, make sure to enable it in Apache configuration file at.
# vi /etc/httpd/conf/httpd.conf
Search for the word “mod_status” or keep scrolling down until you find a line containing.
#LoadModule status_module modules/mod_status.so
If you see a ‘#‘ character at the beginning of “LoadModule”, that means mod_status is disabled. Remove the ‘#‘ to enable mod_status.
LoadModule status_module modules/mod_status.so
Now again search for the word “Location” or scroll down until you find a section for mod_status which should look like following.
# 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. ##<Location /server-status> # SetHandler server-status # Order deny,allow # Deny from all # Allow from .example.com #</Location>
In the above section, uncomment the lines for Location directive, SetHandler and the directory restrictions according to your needs. For example, I am keeping it simple with the Order Allow, deny and it’s allowed for all.
<Location /server-status> SetHandler server-status Order allow,deny Deny from all Allow from all </Location>
So, basically, you need to define the same configuration for each virtual host for any domains you’ve configured in Apache. For example, the virtual host configuration for mod_status will look like this.
<VirtualHost *:80> ServerAdmin email@example.com DocumentRoot /var/www/html/example.com ServerName example.com ErrorLog logs/example.com-error_log CustomLog logs/example.com-access_log common <Location /server-status> SetHandler server-status Order allow,deny Deny from all Allow from example.com </Location> </VirtualHost>
The “ExtendedStatus” settings adds more information to the statistics page like, CPU usage, request per second, total traffic, etc. To enable it, edit the the same httpd.conf file and search for the word “Extended” and Uncomment the line and set the status “On” for ExtendedStatus directive.
# 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
Now make sure that you’ve correctly enabled and configured Apache server status page. You can also check for the errors in the httpd.conf configuration using following command.
# httpd -t Syntax OK
Once, you get syntax is OK, you can able to restart the httpd service.
# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
Now, from a remote machine, open your web browser and access the Apache status page using url “http://your-server-ip/server-status“.
you can see that an HTML interface, which shows all information about server uptime, process Id with its respective client, the page they are trying to access.
It also shows the meaning and usage of all the abbreviations used to display the status which helps us to understand the situation better.
You can also refresh the page every time seconds (say 10 seconds) to see the updated statistics. To set the automate refresh, please add “?refresh=N” at the end of the URL. Where N can be replaced with the number of seconds which you want your page to get refreshed.