I need a command that would echo
the average CPU usage over the past 10 seconds in Ubuntu 18.
Each of the following conditions must be met:
- It must be lightweight with a very small footprint, running a background script constantly writing to the filesystem is a no no.
- The value must account for number of cores automatically (I don't know the number of cores prior).
- The value must be a number between 0 and 1. There shouldn't be any other output as it will be read by a script, not a human. Alternatively suggest a robust algorithm of parsing the output of the suggested command, whatever it is.
sudo
requirement is fine, but the script must be able to be run as a command over SSH and it must have a proper process return behavior (0
exit code for success).
Built-in commands and untilities are preferred, but additional software is OK too as long as it's available in the official repos.
sleep
periods in between.