gamemaster
09-03-2003, 03:09 PM
On a host that is not your own (Unix) is their a script that can record cup usage above a certain level?
Basically I want something that would equal the 'top' command but maybe to send an email showing what script or command, date, etc and how much the CPU usage was...
Thanks in advance.
How about running uptime from a cron job?
Rus
gamemaster
09-03-2003, 04:19 PM
I do not want to measure uptime, I want to measure CPU usage so I can know which scripts cause the most CPU usage. The reason I want this is because recently I saw that my host had a runaway script (not a problem on my own) which was using a lot of the CPU, I want to know when this happens. I can see it in real time with the unix command of 'top', but would like something recorded or emailed to me.
dan_erat
09-03-2003, 05:33 PM
This extremely ugly, poorly-written sh command should send you the output of top if the CPU is less than 30% idle (i.e. the usage is above 70%):if [ `top -n 1 -b | sed -ne 's/^Cpu(s):.*nice,[^0-9]*\([0-9]*\).*% idle/\1/p'` -lt 30 ]; then top -n 1 -b | mail <your address here>; fi
With uptime you can see the load average on the server so I was thinking you could use that
Rus
dan_erat
09-03-2003, 05:52 PM
Load is just the number of processes in the "running" state, I believe, so it's possible to have a high load with a low CPU usage or a low load with a high CPU usage.
Sheps
09-03-2003, 06:37 PM
load is a measure of many factors. % used, # processes, swap or RAM... etc
dan_erat
09-03-2003, 06:43 PM
Load can be affected by all those things, but it's not a measure of anything but the number of active processes. This page (http://www.teamquest.com/html/gunther/ldavg1.shtml) has more than anyone would want to know about it.
vselvara
09-03-2003, 08:29 PM
load does not measure available RAM, swap, disk usage, etc...
Load is only the average # of processes waiting for CPU time at a given time. Nothing more than that.
gamemaster
09-03-2003, 09:40 PM
Originally posted by dan_erat
This extremely ugly, poorly-written sh command should send you the output of top if the CPU is less than 30% idle (i.e. the usage is above 70%):if [ `top -n 1 -b | sed -ne 's/^Cpu(s):.*nice,[^0-9]*\([0-9]*\).*% idle/\1/p'` -lt 30 ]; then top -n 1 -b | mail <your address here>; fi
Thanks for taking the time to do this. I can place this in cgi-bin and just make it executable?
[UN]Jake
09-04-2003, 06:29 AM
Put the code in a text file. And name it topemail.sh and store it somewhere on the server. Then set a cron job to execute the script every hour or w/e you want.