Monitoring Apache With Apachetop
Much of the time spent managing a server is occupied by monitoring what the system is doing. This may take the form of watching the running processes on the server, or looking to see what an individual process is doing. When it comes to the Apache web server, this is normally monitored by looking through the log files that it keeps. There is an alternative method though, which is to use the Apachetop tool.
How to Install And Run Apachetop
As the name implies, this is a tool similar to the process monitoring tool top, but designed to give information about what Apache is doing. This tool scans the usual Apache log files for you and presents a real-time display of what the Apache web server is doing on your server.
Apachetop comes in the default repositories for Debian and Ubuntu, so installation is as simple as this:
sudo apt-get update
sudo apt-get install apachetop
On CentOS and Red Hat systems the EPEL repositories are required for Apachetop to install, so you’d need to install those first:
sudo yum install epel-release
sudo yum install apachetop
Once installed, Apachetop can be easily run by using the apachetop command:
apachetop
This will automatically scan the default apache log files on your system and display their details. If you want to scan files for a specific virtualhost, you can use the -f flag to direct Apachetop to use the log file for that virtualhost. For example:
apachetop -f /var/log/apache2/my_virtualhost_access_log
Once started, Apachetop will give a breakdown of the hits received, how much data is transferred and the pages that have been requested. By default it provides a summary of the previous 30 seconds, though this can be tweaked. Using the -T flag will allow you to adjust how many seconds’ worth of output is used. Using the -H flag lets you limit by a specific number of hits. So as an example:
apachetop -T 600
apachetop -H 10000
The first command will display statistics based on the previous 10 minutes of log data, while the second will display it based on the previous 10000 hits.
Apachetop SettingsLibrary
Once you’ve got Apachetop started with the parameters you require, there are a number of settings you can change from inside. Probably the most useful thing to remember is that pressing either ‘?’ or ‘h’ will take you to a help screen that provides an overview of the options available.
The main screen will show a list of all of the pages being requested and the amount of times each page is requested. Pressing the ‘d’ key will cycle this screen to show the referrers of each hit and how many hits from each referrer, or the hosts requesting the pages. The arrow keys can be used to select a specific entry on these pages; pressing the right arrow key will take you to more details about the line selected, then the left key will take you back to the previous screen.
A really helpful function of Apachetop is the filter menu, which can be brought up with the ‘f’ key. This allows you to filter the data displayed based on either the referrer, the URL being accessed, or the host requesting the page. The filters section provides a context menu that makes it simple to select the type of filter that you would like to use, and to add or remove them. As the name implies, these filters are then applied to the data being indexed allowing you to swiftly narrow down the information you are looking through.
This can be very handy when your server is being attacked by someone trying to find flaws in a website or brute forcing a login page. For example, if you are hosting a WordPress site, and someone is trying to brute force the admin login page, you can filter the output to connections requesting the wp-admin files, then view the hosts screen to see who is requesting the file. You can then add those hosts to your firewall to prevent them accessing your server in future.
Apachetop can be helpful in debugging problems with scripts running for too long and overloading the server, as it can allow you to see what exactly was requested by the end user. If you are running Apache on your server it’s worth installing and having a play with Apachetop to see how it can help you with your server management.