2

Ive seen quite a few php scripts to get and display the CPU usage as a % for all cores combined. But so far i have not been able to find a per core way of doing this.

Would it be possible to create a script that would be able to get CPU usage for just 1 core, then if the server had 4 cores, i could use the script 4 times, to get 4 different percentages for each core. The server im trying to do this on is linux, running Ubuntu 14.04, i can install any software onto it if required. If its possible could someone give me a point in the right direction.

Edit:

With the command htop i can get this data: im looking for something like the 4 core % usage.

enter image description here

3
  • 1
    scrape what ever linux command you need to to use to return the value you want Commented May 15, 2016 at 22:17
  • 3
    per core CPU usage doesn't really exist in linux. The best you've got is scraping /proc/stat and working out which value you need (probably the 4th?) but even then it's not really the best value. Commented May 15, 2016 at 22:23
  • unix.stackexchange.com/questions/58539/… Commented May 15, 2016 at 23:35

1 Answer 1

1

mpstat -P ALL 1 1 might give you what you want:

https://i.sstatic.net/VErPA.jpg

hillb@goliath:~$ mpstat -P ALL 1 1
Linux 3.16.0-71-generic (goliath)       05/16/2016      _x86_64_        (4 CPU)

06:52:17 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
06:52:18 AM  all    1.75    0.00    0.75    0.00    0.00    0.00    0.00    0.00    0.00   97.49
06:52:18 AM    0    1.02    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   98.98
06:52:18 AM    1    1.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.00
06:52:18 AM    2    1.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00    0.00   98.00
06:52:18 AM    3    4.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00    0.00   95.00

Average:     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
Average:     all    1.75    0.00    0.75    0.00    0.00    0.00    0.00    0.00    0.00   97.49
Average:       0    1.02    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   98.98
Average:       1    1.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.00
Average:       2    1.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00    0.00   98.00
Average:       3    4.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00    0.00   95.00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.