How to Monitor Web Server Traffic in Real Time Using Apachetop Tool

19-02-2024 02:26:49

This tutorial is about training and utilizing the Apachetop tool, a command-line utility for real-time monitoring of traffic on web servers such as Apache, Nginx, Litespeed, or Lighttpd. System administrators can leverage Apachetop to view visitors' IP addresses, accessed URL addresses, referring URLs, and other related information in real time.

Installing Apachetop is straightforward and can be easily done through the EPEL software repository.

sudo yum -y install epel-release
sudo yum clean all
sudo yum -y update
sudo yum -y install apachetop

To start using Apachetop, simply enter the command apachetop.

sudo apachetop

By default, Apachetop accesses Apache's default log file located at /var/log/httpd/access_log. If a custom log file path is set, use the -f parameter to specify the log file path.

sudo apachetop -f /var/log/nginx/wordpress_http_access.log

Apachetop defaults to showing data from the last 30 seconds. Use the -H or -T parameters to control this.

For example, display the last 1000 hits.

sudo apachetop -f /var/log/nginx/wordpress_http_access.log -H 1000

Or display hits from the last 600 seconds.

sudo apachetop -f /var/log/nginx/wordpress_http_access.log -T 600

The apachetop display interface consists of different sections

last hit: 13:59:43         atop runtime:  0 days, 00:42:31             14:02:14
All:           19 reqs (   0.0/sec)        111.3K (  151.8B/sec)    6001.0B/req
2xx:      12 (63.2%) 3xx:       7 (36.8%) 4xx:     0 ( 0.0%) 5xx:     0 ( 0.0%)
R ( 30s):       0 reqs (   0.0/sec)          0.0B (    0.0B/sec)       0.0B/req
2xx:       0 ( 0.0%) 3xx:       0 ( 0.0%) 4xx:     0 ( 0.0%) 5xx:     0 ( 0.0%)

Three parameters in the first line: Last hit time, duration of Apachetop, and current server time.Second and third lines show cumulative access data since Apachetop started, with response codes like 2xx, 3xx, 4xx, 5xx (e.g., 200, 404).Fourth and fifth lines display similar parameters but for the last 30 seconds.

Below the summary are lists of current access requests.

REQS REQ/S    KB KB/S URL
    1  0.10   9.8  1.0/
    1  0.14  13.6  1.9*/2016/01/25/hello-world/
    2  0.18  18.2  1.7 /category/uncategorized/
    1  0.07   9.9  0.7 /2016/01/

Apachetop provides several built-in shortcuts:

  • Up/Down arrows: Navigate access requests.
  • Right arrow: View details of the selected request, including visitor IP and referring URL.
  • Left arrow: Return to the list page.
  • p: Pause display.
  • q: Quit the program.