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
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
Something like this:
CpuLoadAverage=`uptime | awk 'BEGIN { FS=" |, " } { print $11 }'`
echo $CpuLoadAverage
for 5 and 15 minutes, just replace $11 with $12 or $13.
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.
-
-
Yeah... I wanted to do it with awk or cut but I couldn't remember the syntax.– David ZAug 15, 2009 at 15:54