eklikeroomys
November 16th, 2012, 03:28 PM
Hi,
I've been searching for a neat way of finding the total instantaneous CPU usage as a %, and found all sorts of tedious solutions.
I thought I'd share a simple one-liner that accomplishes the task really simply:
top -bn 1 | awk '{print $9}' | tail -n +8 | awk '{s+=$1} END {print s}'
Basically, it grabs the CPU column from top and sums all the values together. Simple as that.
Enjoy!
I've been searching for a neat way of finding the total instantaneous CPU usage as a %, and found all sorts of tedious solutions.
I thought I'd share a simple one-liner that accomplishes the task really simply:
top -bn 1 | awk '{print $9}' | tail -n +8 | awk '{s+=$1} END {print s}'
Basically, it grabs the CPU column from top and sums all the values together. Simple as that.
Enjoy!