Sample Header Ad - 728x90

How can I get the total CPU usage of a Linux machine with 1 or n CPU cores?

2 votes
1 answer
3240 views
I am currently using the below method to extract CPU usage idle value from top command and subtracting the value from 100. Is this method correct and is there a better way to achieve the same. Also, my linux VM is a stripped down version and has only few basic tools like top. Installing other tools is not an option as the package manager is also removed. CPU_IDLE="$(top -bn2 | grep -F '%Cpu' | tail -n 4 | gawk '{print $8 $9}' | tr -s '\n\:\,[:alpha:]' ' '| gawk '{print $2}'),"
Asked by Bandi Sandeep (21 rep)
Apr 12, 2017, 06:07 AM
Last activity: May 28, 2025, 12:05 PM