1

I have found that htop command was the only way to display nicely each CPU core's load. I need an average of each CPU core from the last few seconds. However, I do not know how to extract those numbers in a command line. For example, using grep or -n 1. I am running Ångström where I am not allowed to install any more extra packages.

I would like my end result to be:

CPU0: X% CPU1: X% 

I would appreciate any help.

2

1 Answer 1

1

Instead of htop which is more of a gui, go straight to /proc/stat and grab what you need.

Using awk:

awk '$1~/cpu[0-9]/{usage=($2+$4)*100/($2+$4+$5); print $1": "usage"%"}' /proc/stat 
Sign up to request clarification or add additional context in comments.

4 Comments

Unfortunately, it calculates the average since last reboot. I need an average of the last few seconds. How would I go about it?
/proc/stat info for anyone who is interested linuxhowtos.org/System/procstat.htm
Does not use htop.
@JongwookChoi That was not a requirement from OP. If that is a requirement for you, then it would be prudent to open a new question and note that limitation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.