top command for Apache webserver

top is a well-known command used in Linux to see the running processes. A similar script is available for the Apache web server, so you can see the active connections.

The script is called apache-top and is located at https://github.com/fr3nd/apache-top

The requirements of the script are:

– python 2.4
– python-curses package
– Apache 2.0 webserver with mod_status and the ExtendedStatus directive activated. You will also need to be allowed to access from your ip address.

apache-top site

How to run the apache-top script:

1. Download the script from github:

# wget https://raw.githubusercontent.com/fr3nd/apache-top/master/apache-top.py
root@web [/temp3]# wget https://raw.githubusercontent.com/fr3nd/apache-top/master/apache-top.py
--2020-05-22 08:41:07--  https://raw.githubusercontent.com/fr3nd/apache-top/master/apache-top.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 199.232.32.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|199.232.32.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13846 (14K) [text/plain]
Saving to: 'apache-top.py'

100%[==============================================================================================================================>] 13,846      --.-K/s   in 0s

2020-05-22 08:41:07 (42.9 MB/s) - 'apache-top.py' saved [13846/13846]

root@web [/temp3]#

2. Make the script executable using the command:

# chmod +x apache-top.py

3. Run the script

# apache-top -u http://192.168.0.1/server-status

On a cPanel server, use:

# python apache-top.py -u http://127.0.0.1/whm-server-status
root@web [/temp3]# python apache-top.py -u http://127.0.0.1/whm-server-status
Parent Server Config. Generation: 2, Current Time: Friday, 22-May-2020 07:48:07 PDT
Server uptime:  17 hours 25 minutes 46 seconds
Server load: 1.19 1.24 1.11, Active/Idle: Total/Traffic:

__WW_WW_WRW__WR__WW...............................

PID   M SS     CPU  VHost           IP              Request
17791 W 339   0.00  59.11.188.230   1474.65         http/1.1
18287 W 236   0.32  202.62.57.13    845.82          http/1.1
17718 W 152   3.38  175.100.12.66   1630.35         http/1.1
18937 W 62    0.82  203.189.158.158 1702.08         http/1.1
19515 W 22    0.12  36.37.204.225   1170.14         http/1.1
19629 W 13    0.04  175.100.60.218  2029.91         http/1.1
19679 R 8     0.00  45.48.197.105   1506.24         http/1.1
19467 R 7     0.70  83.86.215.200   1001.44         http/1.1
19015 W 0     1.30  188.166.222.27  1363.12         http/1.1
19022 W 0     0.88  127.0.0.1       1467.23         http/1.1
19684 W 0     0.05  114.119.161.209 975.46          http/1.1

Some useful shortcuts when using the tool:

Shift+R		sort by Request
Shift+C		sort by CPU
Shift+I		sort by IP
Q		to exit the script 

As you can see, the output of the script is similar to the top command.

apache logo
Apache Web Server Logo

Leave a Reply