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

09stephenb
  • 9,358
  • 15
  • 53
  • 91
  • 1
    scrape what ever linux command you need to to use to return the value you want –  May 15 '16 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. – Farkie May 15 '16 at 22:23
  • http://unix.stackexchange.com/questions/58539/top-and-ps-not-showing-the-same-cpu-result/58541#58541 – Axalix May 15 '16 at 23:35

1 Answers1

1

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

https://i.stack.imgur.com/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
Benny Hill
  • 6,191
  • 4
  • 39
  • 59