Get per-core CPU load in shell script
3
votes
5
answers
12930
views
I need to report the CPU load per core as a percentage from a shell script, but **I cannot run e.g. mpstat for one second**. Basically I think that the infos
top
is showing after pressing 1
is what I want, but I cannot configure top to show this in batch mode (at least I don't know how). I could create a ~/.toprc
file with the configuration, but then I have to hope that the users do not mess with it.
I looked at mpstat
and parse the output, but this supports only seconds as interval time. My script gets called via SNMP and waiting 1s for the response will generate a timeout, so this is not an option.
Are there other ways to get the per-core cpu load? I read about parsing /proc/stat
, but I think this is more a last resort.
Asked by Jens
(151 rep)
Sep 29, 2016, 11:56 AM
Last activity: Sep 14, 2021, 10:49 AM
Last activity: Sep 14, 2021, 10:49 AM