• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to get current cpu usage?

aceO07

Diamond Member
Using standard linux (Ubuntu) commands, how do I get the printout of the current cpu usage. I will be capturing that text, so the program cannot loop/refresh. So, 'top' is not an option. 'mpstat' would be good, but it only shows avg since reboot.
 
I would think that "mpstat" does exactly what you want. Just run something like "mpstat 1 > cpu-usage.log" and it'll capture the CPU usage every second to a file.
 
Thanks guys. I did do quite a bit of google searching for a solution before I resorted to posting here.

I think I'll try 'top -b -n 1' first.
 
Someone needs to read the man pages...

top -b -n 1

Will do exactly what you want.

I finally got a chance to try this out. Unfortunately it doesn't work as expected. It also gives me the same % as mpstat, which isn't the current cpu usage but average for entire uptime, unless refreshing.

I decided to use this: 'top -b -n 2'

The 2nd iteration is the one with the current cpu usage.
 
For historical views try sar. Install sar and run sar -r -q for a historical text view of CPU+memory and system load.
 
Last edited:
Back
Top