Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I know you can get server load for the past 1, 5, and 15 minutes using commands like "w". However, I would like to automatically retrieve one of those values via a cron job so I can make a note of it in a database and do some analysis and watch the trends. So... I need a command that will output JUST the server load so it can be simply treated as a number for use in my script. Can anyone give me a command that will parse output from a command like "w" and return only the server load value? I'd love to have variations that will return the 5 and 15 minute averages as well. Thanks!

share|improve this question
add comment

3 Answers

Each of them, 1, 5 and 15 minute load averages:

cut -f1 -d' ' /proc/loadavg
cut -f2 -d' ' /proc/loadavg
cut -f3 -d' ' /proc/loadavg
share|improve this answer
    
+1 cut is so handy for this type of thing. –  KPWINC Aug 15 '09 at 1:37
add comment

Something like this:

CpuLoadAverage=`uptime | awk 'BEGIN { FS=" |, " } { print $11 }'`
echo $CpuLoadAverage

for 5 and 15 minutes, just replace $11 with $12 or $13.

share|improve this answer
add comment

Try this:

uptime | perl -e 'while (<>) { m/average:\s(\d.\d+),\s(\d.\d+),\s(\d.\d+)/; print $1; }'

for the 1-minute average, or replace $1 with $2 or $3 for the 5-minute or 15-minute averages respectively.

share|improve this answer
    
Perl's a little heavy for that, don't you think? –  David Pashley Aug 15 '09 at 3:29
    
Yeah... I wanted to do it with awk or cut but I couldn't remember the syntax. –  David Z Aug 15 '09 at 15:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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