Does anyone know of a script that will email me with a list of processes running (sorted by CPU time) whenever the server load exceeds a particular level? I've recently been getting some load problems, but I'm not sure what's causing it (as I'm usually not online when it happens). This is on a cPanel server using PHP Suexec (if it matters at all)
It shoudl be fairly simple to knock a script to do that together in bash:
1. get the load average from /proc/loadavg
2. if greater than (say) 10, run top redirected to a file
3. sleep for a while (30 seconds?)
That way yoiu'll have a file with containing a listing from top for every time the load went above a certain value. If your version of top does not include a timestamp, you'll want to add your own with something like "date >> busy.log.file" after the top command.
If you suspect that it is a cron job though, would it not be easier to look through the crontabs to see what gets kicked off around that time and not other times?
Or if it is very regular, just btry be online at the time?
High loadavg values can be cause by queued I/O rather than the CPU(s) being busy doing real work (i.e. the OS is in I/O Wait state for a large portion of each second). The most common causes of suddern bursts of I/O activity at a regular time are backup operations and log analysis runs.