There are numerous tools available to find out the CPU utilization in linux. Following are the few commands
1. top – This command displays all the Linux tasks, cpu usage, memory usage etc.,
linuxinternetworks ~ # top
Now press 1 to check all the CPU usage information
linuxinternetworks sathish # top -b -n 1 | grep -i ^cpu Cpu(s): 2.2%us, 2.7%sy, 0.1%ni, 94.4%id, 0.5%wa, 0.0%hi, 0.0%si, 0.0%st
2. w – Its displays the number of users logging into the system, cpu load average information, uptime
3. vmstat – vmstat reports information about processes, memory, paging, block IO, traps, disks and cpu activity.
linuxinternetworks ~ # vmstat -S M
4. iostat – The iostat command generates three types of reports, the CPU Utilization report, the Device Utilization report and the Network Filesystem report.
linuxinternetworks ~ # iostat -c
%user — Show the percentage of CPU utilization that occurred while executing at the user level (application).
%nice — Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
%system — Show the percentage of CPU utilization that occurred while executing at the system level (kernel).
%iowait — Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%steal — Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
%idle — Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
linuxinternetworks sathish # iostat -tc 2 10
The above command will check and displays the CPU utilization reports for every two seconds with time.
5. sar – Collect, report, or save system activity information.
For debian based distro – apt-get install sysstat
For rpm based distro – yum install sysstat
Enable the services permanently
service sysstat start
chkconfig sysstat on
inuxinternetworks ~ # sar
linuxinternetworks ~ # sar -u
CPU Utilization report for every two seconds
linuxinternetworks ~ # sar -u 2 10
where 2 refers 2 seconds and 10 refers 10 reports
Save and Compare the CPU Utilization for future use
linuxinternetworks sathish # sar -o <file_name> interval count >/dev/null 2>&1 &
Where interval is time taken between the cpu check, count is the number of reports you required.
ex: linuxinternetworks sathish # sar -o cpu_utilization 2 10 >/dev/null 2>&1 &
This command will check the cpu utilization every 2 seconds for 10 times. The cpu_utilization file which has been created is a binary file and you can check with sar command
linuxinternetworks sathish #sar -f <file_name>
linuxinternetworks sathish #sar -f cpu_utilization
or you can use with nohup,
linuxinternetworks sathish # nohup sar -o <file_name> interval count >/dev/null 2>&1 &
linuxinternetworks sathish # sar -P ALL
Display all CPU Utilization for every second for 10 times
linuxinternetworks sathish # sar -P ALL 1 10
Display first cpu core utilization for every second for 10 times
linuxinternetworks sathish # sar -P 0 1 10
For detailed information
linuxinternetworks sathish # sar -A
linuxinternetworks sathish # sar -f /var/log/sysstat/sa29
Please check the sar man page for more.
6. mpstat – Its report the process related statistics
linuxinternetworks sathish #mpstat
linuxinternetworks sathish #mpstat -u 1 10
It will display the cpu utilization every second for ten times
7. ps – Process command to check the cpu utilization
linuxinternetworks sathish # ps -eo pcpu,pid,user,args | sort -r -k1 | head linuxinternetworks sathish # ps -eo pcpu,pid,user,args | sort -r -k1 | less linuxinternetworks sathish # ps -au
8. CPU Load Average
linuxinternetworks sathish # cat /proc/loadavg 0.00 0.10 0.13 1/347 14192
9. System Monitor – Its a GNOME tool which displays the information about the currently running tasks, file system, cpu usage, RAM usage, Swap usage.
If you are using any other method to find out the cpu utilization, please let me know through commands.