Skip to content

Instantly share code, notes, and snippets.

@Tab3r
Last active February 12, 2017 01:38
Show Gist options
  • Save Tab3r/ad43473fe0b00086ffc0 to your computer and use it in GitHub Desktop.
Save Tab3r/ad43473fe0b00086ffc0 to your computer and use it in GitHub Desktop.
Linux: CPU Usage in percernt
######## USING PS ##########
## Note: In hign loads, it could return more than 100% of load
# Show total %
ps aux | awk {'sum+=$3;print sum'} | tail -n 1
# Debug mode:
ps aux | awk {'value=$3; if ($3 != "0.0") {print "Adding: " value}; sum+=$3; sumt = "Total sum: " sum; print sumt'}
####### USING TOP #########
## Note: It needs 2 seconds to execute to be accurrate
top -bn 2 -d 2 | grep '^%Cpu' | tail -n 1 | awk '{print $2+$4+$6 "%"}'
@samirfor
Copy link

top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%*\ \{0,1\}id.*/\1/" | awk '{print 100 - $1"%"}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment