Spying Apache server activity and performance with mod_status

2 minute read

On Debian based systems such as Ubuntu… Apache comes with mod_status compiled in by default.

mod_status provides information on your apache server activity and performance.

This tutorial will show you how to enable this feature in such a way that only requested issued from localhost will be accepted and served.

Setting mod_status up

By default, server status report is commented so you can not access it. To enable it, you need to uncomment from /etc/apache2/apache2.conf:

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .your_domain.com
</Location>

This is a default setting, and will not work out of the box. What is said here is: server status will be acessible at location http://servername/server-status, access will be denied to everybody but people connecting from domain your_domain.com and any sub-domain from your_domain.com.

We want the server status to be provided only to people connected directly from the host running the apache server. Therefore we are going to deny access to /server-status to everybody except for people connecting from localhost, in the end the setting will look like:

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>

Note: You could be using localhost instead of 127.0.0.1, but keep in mind that if the directive HostnameLookups is turned to Off, apache won’t let you access to http://localhost/server-status .

OK, now that everything is set up, check that there is no error in your configuration by using:

apache2ctl -t

if everything is fine, reload apache2 configuration with:

sudo /etc/init.d/apache2 reload

Accessing Apache Status

To access apache status and activity, you need to request the page http://localhost/server-status, you could use text mode navigators such as elinks or links in order to connect through a console using ssh.

Now, you can access information such as server start time, server uptime, number of requests being processed, number of slots available …. The different keys are explained just under the server activity.

A neat feature of server-status is the ability to refresh every X seconds, in order to get up-to-date activity, by calling:

elinks http://localhost/server-status?refresh=2

In the previous example, the status will be updated every 2 seconds.

Getting more from Apache Server-status

If you want to get more information from your server activity, you can add the directive:

ExtendedStatus On

just above the <Location /server-status> directive. But keep in mind that this cannot be set on a per virtualhost basis and will use more resources.

But in another hand, you will be able to access more informations such as:

  • Total accesses
  • CPU usage
  • number of requests/sec, Bytes/sec and Bytes/request
  • See the different clients connected to your server, on which virtual host as well as the page there are requesting, you can even access the time it took to request a specific page as well as the resources required.

Conclusion

apache built-in mod_status is an easy to set up module which can easily permit a system administrator to see how its web server is behaving by checking the average number of simultaneous request.

By using the ExtendedStatus directive, it makes it easier to point out virtual hosts and pages behaving badly.

Article of interest: