2

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!

3 Answers 3

4

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
1
  • +1 cut is so handy for this type of thing.
    – KPWINC
    Aug 15, 2009 at 1:37
1

Something like this:

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

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

0

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.

2
  • Perl's a little heavy for that, don't you think? Aug 15, 2009 at 3:29
  • Yeah... I wanted to do it with awk or cut but I couldn't remember the syntax.
    – David Z
    Aug 15, 2009 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .