0% found this document useful (0 votes)
147 views

Cpu Utilisation Commands

The top command and mpstat command can be used to monitor CPU utilization on Linux systems. Top displays overall system status and a list of processes, including each process's CPU usage. Mpstat displays CPU usage statistics for each CPU and the average. The sar command produces CPU usage reports over time that can be used to compare utilization levels between intervals. To identify resource-intensive processes, the ps command can display the top CPU consumers sorted by usage percentage.

Uploaded by

vijukm2000
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Cpu Utilisation Commands

The top command and mpstat command can be used to monitor CPU utilization on Linux systems. Top displays overall system status and a list of processes, including each process's CPU usage. Mpstat displays CPU usage statistics for each CPU and the average. The sar command produces CPU usage reports over time that can be used to compare utilization levels between intervals. To identify resource-intensive processes, the ps command can display the top CPU consumers sorted by usage percentage.

Uploaded by

vijukm2000
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Old good top command to find out Linux cpu load

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. The top command monitors CPU utilization, process statistics, and memory utilization. The top section contains information related to overall system status - uptime, load average, process counts, CPU status, and utilization statistics for both memory and swap space. Top command to find out Linux cpu usage Type the top command:
$ top

Output:

You can see Linux CPU utilization under CPU stats. The tasks share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment (multiple CPUS), top will operate in number of CPUs. Please note that you need to type q key to exit the top command display. The top command produces a frequently-updated list of processes. By default, the processes are ordered by percentage of CPU usage, with only the "top" CPU consumers

shown. The top command shows how much processing power and memory are being used, as well as other information about the running processes.

Find Linux CPU utilization using mpstat and other tools


Please note that you need to install special package called sysstat to take advantage of following commands. This package includes system performance tools for Linux (Red Hat Linux / RHEL includes these tools by default).
# apt-get install sysstat

Use up2date command if you are using RHEL:


# up2date sysstat

Display the utilization of each CPU individually using mpstat


If you are using SMP (Multiple CPU) system, use mpstat command to display the utilization of each CPU individually. It report processors related statistics. For example, type command: # mpstat Output:
Linux 2.6.15.4 (debian) 05:13:05 IST CPU %user %steal %idle intr/s 05:13:05 IST all 16.52 0.00 79.42 830.06 Thursday 06 April 2006 %nice 0.00 %sys %iowait 2.87 1.09 %irq 0.07 %soft 0.02

The mpstat command display activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.:
# mpstat -P ALL

Output:
Linux 2.6.15.4 (wwwportal1.xxxx.co.in) 05:14:58 IST CPU %user %steal %idle intr/s 05:14:58 IST all 16.46 0.00 79.48 835.96 05:14:58 IST 0 16.46 0.00 79.48 835.96 05:14:58 IST 1 15.77 0.00 81.44 822.54 %nice 0.00 0.00 2.70 Thursday 06 April 2006 %sys %iowait 2.88 2.88 3.17 1.08 1.08 2.01 %irq 0.07 0.07 0.05 %soft 0.02 0.02 0.03

Another output from my HP Dual Opteron 64 bit server:# mpstat -P ALLOutput:


Linux 2.6.5-7.252-smp (ora9.xxx.in) 04/07/06

07:44:18 CPU %idle intr/s 07:44:18 all 39.19 1063.46 07:44:18 0 24.16 262.11 07:44:18 1 49.02 268.92 07:44:18 2 54.73 260.96 07:44:18 3 28.83 271.47

%user 3.01 5.87 1.79 2.19 2.17

%nice %system %iowait 57.31 69.47 48.59 42.63 68.56 0.36 0.44 0.36 0.28 0.34 0.13 0.05 0.23 0.16 0.06

%irq 0.01 0.01 0.00 0.01 0.03

%soft 0.00 0.01 0.00 0.00 0.00

Report CPU utilization using sar command


You can display todays CPU activity, with sar command:
# sar

Output:
Linux 2.6.9-42.0.3.ELsmp (dellbox.xyz.co.in) 12:00:02 12:10:01 12:20:01 12:30:02 12:40:01 12:50:01 01:00:01 ... ..... .. 04:40:01 04:50:01 05:00:01 05:10:01 05:20:02 Average: AM AM AM AM AM AM AM CPU all all all all all all %user 1.05 0.74 1.09 0.76 1.25 0.80 %nice 0.00 0.00 0.00 0.00 0.00 0.00 %system 0.28 0.34 0.28 0.21 0.32 0.24 01/13/2007 %iowait 0.04 0.38 0.10 0.03 0.03 0.03 %idle 98.64 98.54 98.53 99.00 98.40 98.92

AM AM AM AM AM

all all all all all all

8.39 8.68 7.10 8.78 8.30 3.09

0.00 0.00 0.00 0.00 0.00 0.00

33.17 37.51 30.48 37.74 35.45 9.14

0.06 0.04 0.04 0.03 0.06 0.09

58.38 53.78 62.39 53.44 56.18 87.68

Comparison of CPU utilization The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters. For example display comparison of CPU utilization; 2 seconds apart; 5 times, use:
# sar -u 2 5

Output (for each 2 seconds. 5 lines are displayed):


Linux 2.6.9-42.0.3.ELsmp (www1lab2.xyz.ac.in) 05:33:24 05:33:26 05:33:28 05:33:30 AM AM AM AM CPU all all all %user 9.50 16.79 17.21 %nice 0.00 0.00 0.00 %system 49.00 74.69 80.30 01/13/2007 %iowait 0.00 0.00 0.00 %idle 41.50 8.52 2.49

05:33:32 AM 05:33:34 AM Average:

all all all

16.75 14.29 14.91

0.00 0.00 0.00

81.00 72.43 71.49

0.00 0.00 0.00

2.25 13.28 13.61

Where,

-u 12 5 : Report CPU utilization. The following values are displayed: o %user: Percentage of CPU utilization that occurred while executing at the user level (application). o %nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority. o %system: Percentage of CPU utilization that occurred while executing at the system level (kernel). o %iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. o %idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

To get multiple samples and multiple reports set an output file for the sar command. Run the sar command as a background process using.
# sar -o output.file 12 8 >/dev/null 2>&1 &

Better use nohup command so that you can logout and check back report later on:
# nohup sar -o output.file 12 8 >/dev/null 2>&1 &

All data is captured in binary form and saved to a file (data.file). The data can then be selectively displayed ith the sar command using the -f option.
# sar -f data.file

Task: Find out who is monopolizing or eating the CPUs


Finally, you need to determine which process is monopolizing or eating the CPUs. Following command will displays the top 10 CPU users on the Linux system.
# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

OR
# ps -eo pcpu,pid,user,args | sort -r -k1 | less

Output:
%CPU PID USER COMMAND 96 2148 vivek /usr/lib/vmware/bin/vmware-vmx -C /var/lib/vmware/Virtual Machines/Ubuntu 64-bit/Ubuntu 64-bit.vmx -@ "" 0.7 3358 mysql /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pidfile=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock 0.4 29129 lighttpd /usr/bin/php 0.4 29128 lighttpd /usr/bin/php 0.4 29127 lighttpd /usr/bin/php 0.4 29126 lighttpd /usr/bin/php 0.2 2177 vivek [vmware-rtc] 0.0 9 root [kacpid]

0.0

8 root

[khelper]

Now you know vmware-vmx process is eating up lots of CPU power. ps command displays every process (-e) with a user-defined format (-o pcpu). First field is pcpu (cpu utilization). It is sorted in reverse order to display top 10 CPU eating process.

iostat command
You can also use iostat command which report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions. It can be use to find out your system's average CPU utilization since the last reboot. # iostatOutput:
Linux 2.6.15.4 (debian) Thursday 06 April 2006

avg-cpu: %user %nice %system %iowait %steal %idle 16.36 0.00 2.99 1.06 0.00 79.59 Device: hda hdb hdc sda tps 0.00 6.43 0.03 0.00 Blk_read/s 0.00 85.57 0.16 0.00 Blk_wrtn/s 0.00 166.74 0.00 0.00 Blk_read 16 875340 1644 24 Blk_wrtn 0 1705664 0 0

You may want to use following command, which gives you three outputs every 5 seconds (as previous command gives information since the last reboot):$ iostat -xtc 5 3

GUI tools for your laptops/desktops


Above tools/commands are quite useful on remote server. For local system with X GUI installed you can try out gnome-system-monitor. It allows you to view and control the processes running on your system. You can access detailed memory maps, send signals, and terminate the processes.
$ gnome-system-monitor

(Click to enlarge image) In addition, the gnome-system-monitor provides an overall view of the resource usage on your system, including memory and CPU allocation.

You might also like