Home / Redhat-LINUX / How to Find Out Linux CPU Utilization?

How to Find Out Linux CPU Utilization?

Due to huge resources demands from the newer applications , anytime your Linux box in to CPU bottle neck.As a system admin, we need to find out who and what has occupied the system CPU’s.To free up the CPU usage , you may need to contact the owner of the process and it most likely an application support team. Sometimes you never know that CPU may went to disabled state and that could cause CPU bottle necks.In those cases, you need to enable the disabled CPU’s.

This post is going to help you to find the following things in many ways.

1.Determine Number of CPU Cores  in redhat Linux.
2.System wide – CPU utilization (overall
3.Display the CPU utilization for each physical CPU’s
4.Determine which processes are consuming high CPU and owner of the process
5.Average CPU utilization since the server last reboot .

There are many utilities are available to determine the above things in redhat linux. Here we will see one by one with real time output.

=>.List all the available CPU’s in the system.
# cd /sys/devices/system/cpu
# ls -lrt |grep cpu

==>To get the Processors information.

[root@uagl1 Desktop]# more /proc/cpuinfo 
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 Duo CPU E6550 @ 2.33GHz
stepping : 11
cpu MHz : 2333.331
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_
tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm lahf_lm dts tpr_shadow vnmi flexpriority
bogomips : 4655.20
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 Duo CPU E6550 @ 2.33GHz
stepping : 11
cpu MHz : 2333.331
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_
tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm lahf_lm dts tpr_shadow vnmi flexpriority
bogomips : 4655.20
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:

[root@uagl1 Desktop]#


==> To find number of total CPU’s cores on the system, (1physical processor – 2 CPU cores)

[root@uagl1 Desktop]# nproc
2
[root@uagl1 Desktop]#

==> To find the system wide CPU usage overall.You can use traditional “top” command. 

[root@uagl1 Desktop]# top

top - 19:19:32 up 7 min, 2 users, load average: 0.05, 0.14, 0.08
Tasks: 228 total, 2 running, 226 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.3%us, 0.2%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2928580k total, 875336k used, 2053244k free, 30500k buffers
Swap: 5160952k total, 0k used, 5160952k free, 404584k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2764 root 20 0 132m 11m 7128 S 1.0 0.4 0:01.30 Xorg
4063 root 20 0 284m 12m 9368 S 1.0 0.4 0:00.26 gnome-terminal
4075 root 20 0 15152 1312 920 R 0.3 0.0 0:00.20 top
1 root 20 0 19348 1552 1244 S 0.0 0.1 0:02.57 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.15 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:01.35 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
7 root RT 0 0 0 0 S 0.0 0.0 0:00.14 migration/1
8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
9 root 20 0 0 0 0 S 0.0 0.0 0:00.26 ksoftirqd/1
10 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
11 root 20 0 0 0 0 S 0.0 0.0 0:00.02 events/0
12 root 20 0 0 0 0 R 0.0 0.0 0:00.03 events/1
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
16 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr
17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm
18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 sync_supers
19 root 20 0 0 0 0 S 0.0 0.0 0:00.00 bdi-default
20 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kintegrityd/0
21 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kintegrityd/1

==>To find the individual CPU usage using top command.(My system is having one physical CPU/2 cores). Enter “top” command then press “1” to see all the CPU’s.

[root@uagl1 Desktop]# top

top - 20:39:27 up 1:27, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 227 total, 1 running, 226 sleeping, 0 stopped, 0 zombie
Cpu0 : 0.0%us, 2.3%sy, 0.0%ni, 96.4%id, 1.3%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu1 : 6.9%us, 0.3%sy, 0.0%ni, 92.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2928580k total, 986572k used, 1942008k free, 91040k buffers
Swap: 5160952k total, 0k used, 5160952k free, 428524k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4063 root 20 0 285m 13m 9400 S 1.7 0.5 0:02.13 gnome-terminal
2764 root 20 0 133m 12m 7948 S 1.3 0.5 0:09.23 Xorg
3644 root 20 0 241m 6288 4956 S 0.3 0.2 0:00.11 gnome-session
3653 root 20 0 32292 1728 800 S 0.3 0.1 0:00.24 dbus-daemon
3810 root 20 0 305m 11m 7896 S 0.3 0.4 0:00.09 nm-applet
5431 root 20 0 15160 1312 924 R 0.3 0.0 0:00.16 top
1 root 20 0 19348 1552 1244 S 0.0 0.1 0:02.60 init
7 root RT 0 0 0 0 S 0.0 0.0 0:00.14 migration/1


==> You can also use “mpstat” command to find the CPU usage.

[root@uagl1 Desktop]# mpstat 
Linux 2.6.32-279.el6.x86_64 (uagl1) 11/08/2013 _x86_64_ (2 CPU)

07:20:53 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
07:20:53 PM all 1.37 0.00 1.65 5.25 0.01 0.01 0.00 0.00 91.70
[root@uagl1 Desktop]#


==> Using “mpstat” command ,you can get CPU wise usage.

[root@uagl1 Desktop]# mpstat -P ALL
Linux 2.6.32-279.el6.x86_64 (uagl1) 11/08/2013 _x86_64_ (2 CPU)

07:26:23 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
07:26:23 PM all 0.89 0.00 1.06 3.32 0.01 0.01 0.00 0.00 94.72
07:26:23 PM 0 0.87 0.00 1.15 3.46 0.01 0.01 0.00 0.00 94.51
07:26:23 PM 1 0.91 0.00 0.97 3.17 0.00 0.01 0.00 0.00 94.93
[root@uagl1 Desktop]#


==> Another important and more reliable command is “sar”.
If you enter “sar” command , it will bring the complete day cpu statistics. 

[root@uagl1 Desktop]# sar
Linux 2.6.32-279.el6.x86_64 (uagl1) 11/08/2013 _x86_64_ (2 CPU)

12:00:01 AM CPU %user %nice %system %iowait %steal %idle
12:10:01 AM all 0.01 0.00 0.03 0.11 0.00 99.84
12:20:01 AM all 0.01 0.00 0.03 0.11 0.00 99.84
12:30:01 AM all 0.01 0.00 0.02 0.11 0.00 99.85
12:40:01 AM all 0.01 0.00 0.03 0.07 0.00 99.89
12:50:01 AM all 0.01 0.00 0.02 0.06 0.00 99.91


==> To get real-time CPU usage using “sar”,

[root@uagl1 Desktop]# sar -u 5 5 
Linux 2.6.32-279.el6.x86_64 (uagl1) 11/08/2013 _x86_64_ (2 CPU)

07:27:21 PM CPU %user %nice %system %iowait %steal %idle
07:27:26 PM all 0.00 0.00 0.20 0.00 0.00 99.80
07:27:31 PM all 0.10 0.00 0.20 0.10 0.00 99.60
07:27:36 PM all 0.00 0.00 0.30 0.10 0.00 99.60
07:27:41 PM all 0.10 0.00 0.20 0.20 0.00 99.50
07:27:46 PM all 0.00 0.00 0.30 0.60 0.00 99.10
Average: all 0.04 0.00 0.24 0.20 0.00 99.52
[root@uagl1 Desktop]#


==> To Determine which processes are consuming high CPU and owner of the process.
“Top” also shows the same information,but you can also use the “ps” command to determine that.

[root@uagl1 Desktop]# ps -eo pcpu,pid,user,args |sort -k 1 -r |head -5
%CPU PID USER COMMAND
7.0 4336 root ps -eo pcpu,pid,user,args
0.2 4 root [ksoftirqd/0] 0.2 2764 root /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-xTolDD/database -nolisten tcp vt1
0.2 2398 root /usr/lib/vmware/bin/vmware-hostd -a /etc/vmware/hostd/config.xml
[root@uagl1 Desktop]#


==> Another useful command is “iostat” ,

[root@uagl1 Desktop]# iostat
Linux 2.6.32-279.el6.x86_64 (uagl1) 11/08/2013 _x86_64_(2 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
0.61 0.00 0.75 2.26 0.00 96.38

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 17.78 650.22 80.45 893930 110604
scd0 0.05 0.33 0.00 460 0
dm-0 30.29 642.61 80.41 883474 110544
dm-1 0.23 1.87 0.00 2576 0
dm-2 0.10 0.78 0.02 1074 24


==> “IOSTAT” also can be used to see the disk I/O bottle neck,

[root@uagl1 Desktop]# iostat -xtc 5 5 
Linux 2.6.32-279.el6.x86_64 (uagl1) 11/08/2013 _x86_64_ (2 CPU)

11/08/2013 07:35:13 PM
avg-cpu: %user %nice %system %iowait %steal %idle
0.60 0.00 0.74 2.22 0.00 96.44

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 6.07 7.39 14.73 2.71 636.99 79.10 41.07 0.53 30.33 2.92 5.08
scd0 0.00 0.00 0.05 0.00 0.33 0.00 6.87 0.00 73.87 73.87 0.35
dm-0 0.00 0.00 19.83 9.88 629.52 79.05 23.85 1.27 42.62 1.70 5.06
dm-1 0.00 0.00 0.23 0.00 1.84 0.00 8.00 0.00 6.75 3.49 0.08
dm-2 0.00 0.00 0.10 0.00 0.77 0.02 7.84 0.00 4.08 2.87 0.03


==> In redhat Linux, we also have graphical tool to monitor the system resources.
Just enter command, ” gnome-system-monitor”


==> To see the process list,Click on the process tab.


==> You can also see the system information,by clicking the system tab.


Hope now you are familiar  to pull out the CPU related information and usage on Redhat Linux.

Please leave a comment if you have any doubt. Thank you for visiting UnixArena.

VMTURBO-CLOUD-CAPACITY

One comment

  1. We can also use lscpu command to list the CPU in redhat linux

Leave a Reply

Your email address will not be published. Required fields are marked *