Thursday, September 24, 2009

How to monitor which domain burst CPU in Apache (Linux)

SkyHi @ Thursday, September 24, 2009
Thinking about monitoring CPU usage of each domain running on the same server (Virtual host), everybody would say apache-status mod is one of the best choice available (for free). Unfortunately, CPU usage seem confusing here. I expected CPU usage similar to the value shown when using top command. But the value shown here is accumulated number of seconds that thread-worker use CPU, not a single snapshot shown in top command.

Better solution is using apache-top ( It’s similar to top command but again CPU usage displayed here is not what I want as it’s the same thing shown in apache-status. Any way out? To achieve what I want, I will show you the way to (quick and dirty.. and may be silly) use top and apache-top together. Surprisingly, it’s work fine. I finally found the domain which load CPU heavily.

Step1: Install apache-top

Make sure that you have

* python 2.4
* 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.

Download apache-top from here
(See more detail in

Step2: Run both top and apache-top

$ top
/>./ -u

In this step you have to quick enough to see top screen and find PID of the process load CPU heavily and then look at apache-top screen to see which domain running on that particular PID. Not easy huh… If you’re not fast enough, PID may already be changed.

Step3: Sync both screen

In top screen

* display only process of apache by pressing “u” and enter apache’s username (my server is www-data)
* display only PID and CPU% by pressing “f” and then toggle fields via field letter
* sort by PID by pressing “F” and then select sort field via field letter.

In apache-top screen

* display all process by pressing “a”
* sort by PID (to have same sequence as top screen) by pressing “P”

Then move window to align both screen together


For now, I can see PID 31610, 31601 load which is (hidden) load CPU heavily.