Apachetop: Real-Time Website Monitoring

Real-Time Website Traffic Monitoring with Apachetop
As a webmaster, the ability to observe website traffic as it happens is often highly desirable. While tools like Google Analytics excel at analyzing trends over time, they typically involve a delay of several hours. This makes it difficult to view metrics such as requests per second or total data transfer in real-time. The apachetop utility addresses this need.
What is Apachetop?
Apachetop is a straightforward command-line tool designed for real-time traffic monitoring. It functions by analyzing Apache log files and presenting relevant data directly on the screen.
Using Apachetop
After installation, launching apachetop is simple: just type apachetop in your command line. If apachetop defaults to an incorrect log file directory, you can specify the log file location using the -f parameter. This is particularly useful when managing multiple virtual hosts on a single server.
For example:
apachetop -f /var/www/vhosts/howtogeek.com/statistics/logs/access_log
Upon execution, you'll begin to see data appear as requests are received.
Monitoring Timeframe
By default, apachetop displays data for a 30-second window. Therefore, the total counts won't continuously increase indefinitely. You can adjust this timeframe using command-line arguments.
Here are a couple of examples:
apachetop -H hits(Displays stats for the last specified number of hits)
apachetop -T secs(Displays stats for the last specified number of seconds)
Experimenting with ranges of 5-10 minutes can provide valuable insights.
Filtering the Data
Apachetop allows you to filter the displayed information. Press the f key to access the filter options, which will appear as a small line on the screen.
Press the a key to add a filter, and you'll be presented with choices to filter by URL, referrer, or host.
For instance, filtering by URL can focus the display on traffic related to specific directories, such as articles.
To filter by URL, press the u key. A dialog box will appear at the bottom of the screen.
Entering a subdirectory, like /howto/, will limit the display to hits within that directory, excluding traffic for images and other assets.
Viewing Request Details
Use the up and down arrow keys to select a specific request. An asterisk (*) will indicate the currently selected request.
Pressing the Right arrow key will navigate to a details page for that request, revealing information such as the originating host and referrer.
The referrer information can be particularly useful for understanding traffic sources.
Use the Left arrow key to return to the main list.
Switching Between Views
The d key allows you to easily switch between different views, such as hosts, referrers, and URLs.
This enables you to quickly analyze traffic patterns based on different criteria.
Helpful Resources
At any time, pressing the ? or h keys will display the help screen, providing a comprehensive overview of available options.
Installation Instructions
Ubuntu
To install on Ubuntu, use the following command:
sudo apt-get install apachetop
CentOS (From Source)
For CentOS, installation from source is required:
wget http://www.webta.org/apachetop/apachetop-0.12.6.tar.gz
yum install readline-devel
yum install ncurses-devel
tar xvzf apachetop-0.12.6.tar.gz
cd apachetop-0.12.6
./configure
make
The compiled binary will be located in the src/apachetop directory and can be copied to a suitable location.
Ubuntu (From Source)
To install from source on Ubuntu:
wget http://www.webta.org/apachetop/apachetop-0.12.6.tar.gz
sudo apt-get install ncurses-dev
sudo apt-get install libreadline5-dev
tar xvzf apachetop-0.12.6.tar.gz
cd apachetop-0.12.6
./configure
make
The binary can then be found in src/apachetop and moved to your desired location.