Pick our brains...

Server Diagnosis & Tuning :: Basic Server Analysis

The first tool to reach for when analyzing and/or diagnosing a server is likely:


Top will give you a real-time, interactive view of the top processes consuming memory, cpu, etc…  Which is probably why it’s called “top”.  There’s a lot of rather cryptic keystrokes that you can use while running top, that will sort things based on various parameters, as well as other functions.  To get out of top, just hit ctrl-C.


If htop is installed that may a preferable alternative to top. The topcommand is older and more widely supported but not as feature rich. Seehttp://hisham.hm/htop/index.php?page=comparison


Another great tool to know about is:

ps aux

Ps aux will give you a listing of all running processes.  It differs from top in that it is not interactive and real-time, but rather a snapshot of a moment in time.  But it has other tricks up its sleeve.  Let’s say you wanted to see all the httpd processes that are running.  You can pipe the out of ps aux to grep, as such:

ps aux | grep httpd

Then, let’s say you wanted to count those httpd processes, to know how many have spawned.  You can pipe the output from grep to wc (word count), along with an optional flag for line count:

ps aux | grep httpd | wc -l

This will give you the number of httpd’s running, plus one (since the grep will also match on the grep process itself).


Now, here’s a particularly interesting goodie.  Let’s say you wanted to know what files a particular process has open.  For instance, if you see a process in top that’s consuming a bunch of resources, and you want to know more about that process.  You can list open files for a process id with:

lsof -p XXXX

(where XXXX is the process id)


If we need to start annihilating things, we can use the kill command, again using the process id:

kill -9 XXXX

(where XXXX is the process id)

(-9 is the highest priority of the kill command, no if’s, and’s, or but’s)

(note that killing things in serverland, just as in non-serverland, may have unintended consequences that need to be carefully considered)