up vote 2 down vote favorite
1
share [g+] share [fb]

I have a box on Linode that's going through weird behavior. Every now and then CPU and disk I/O will shoot to 100% and the server becomes unresponsive and has to be booted. I'd like to investigate better what's going on, but I don't know how to find who's responsible for all that CPU and I/O. I'm running Gentoo 2.6.18.

link|improve this question

67% accept rate
feedback

5 Answers

up vote 5 down vote accepted

You could try to do something like this:

while true; do ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> logfile.txt; echo "\n" >> logfile.txt; sleep 3; done

that would show you the top ten processes in terms of CPU usage. You can change the number of processes shown by changing the 10 in "head -10" to a different number, and how often it updates by changing the 3 in "sleep 3" or taking out the "sleep 3" part entirely.

link|improve this answer
Make sure you have some sort of sleep in there, otherwise there is a good chance that your shell process will always be in the top 10. :) – jedberg Oct 10 '09 at 17:21
feedback

Check out atop it will write a binary log of pretty much everything you would possibly want and then you can use a top like gui to go through the time slices of the day (default is to take the data every 5 minutes). http://www.atcomputing.nl/Tools/atop/

link|improve this answer
feedback

I think that munin is one of the goods tools of monitoring that will help your to get some information about your box's activities. Also, there are some command line tool like sar, iostat, ps, top for such use.

link|improve this answer
feedback

The other answers have only shown you how you can look at what's currently going on, which doesn't help if the system has been rebooted.

If you want this information recorded for posterity (or billing, or whatever other use you might also have), what you want is process accounting.

Here's a HOWTO I found, but I'll be honest -- it's been a decade since I've used process accounting.

http://tldp.org/HOWTO/Process-Accounting/

link|improve this answer
feedback

Doesn't Gentoo have the "top" command as wel?

machine:~/# top

should give you the running stats of which programs causes the most load.

link|improve this answer
Yeah I know, but I'd like to have that logged so I can see the history later. When the CPU spikes, the machine becomes unresponsive, so I can't log in and run top to see who's the culprit. I want to check back later and see which process did it. – obvio171 Oct 10 '09 at 15:31
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.