Tuesday, October 23, 2012


 There are different commands to check CPU usage in Linux/Unix. Depends on your requirement run the following commands to get desired output.
If you want to check the CPU utilization in Ubuntu then run the commands :
root@desktop210:~# Sudo apt-get install htop

root@desktop210:~# htop

 You can see the output like this in ubuntu:
  
You can check status in all OS by top command as well.
root@desktop02:~# top
top - 15:15:15 up 112 days,  2:33,  2 users,  load average: 0.03, 0.04, 0.00
Tasks: 187 total,   1 running, 186 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.2%us,  0.0%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1912840k total,  1842184k used,    70656k free,   267864k buffers
Swap:  3903752k total,   394900k used,  3508852k free,   614240k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
10789 root      18  -2  2580 1228  912 R    0  0.1   0:00.02 top
    1 root      20   0  3084  160  108 S    0  0.0   0:01.03 init
    2 root      15  -5     0    0    0 S    0  0.0   0:00.10 kthreadd
    3 root      RT  -5     0    0    0 S    0  0.0   0:01.22 migration/0
    4 root      15  -5     0    0    0 S    0  0.0   0:26.61 ksoftirqd/0
    5 root      RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog/0
    6 root      RT  -5     0    0    0 S    0  0.0   0:01.14 migration/1
    7 root      15  -5     0    0    0 S    0  0.0   0:34.93 ksoftirqd/1
    8 root      RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog/1
    9 root      15  -5     0    0    0 S    0  0.0   0:00.12 events/0

You can use the iostat command to get output as follows. It will show the average cpu used as per user, nice, system, iowait, steal, idle. This command can run on ubuntu, Linux, Solaris.
root@desktop04:~# iostat
Linux 3.0.0-12-generic (desktop02)   Tuesday 23 October 2012         _i386_  (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.26    0.02    0.21    0.27    0.00   99.24
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               1.24         8.42        18.31    5111489   11113852
You can check the memory consumed as like swap, memory, buffer, cache by cat /proc/meminfo. This command can run on Linux, solaris, Ubuntu.
root@desktop010:~ # cat /proc/meminfo
MemTotal:        1912840 kB
MemFree:           70240 kB
Buffers:          267864 kB
Cached:           614332 kB
SwapCached:       144680 kB
Active:           946200 kB
Inactive:         801444 kB
Active(anon):     434396 kB
Inactive(anon):   491604 kB
Active(file):     511804 kB
Inactive(file):   309840 kB
Unevictable:           8 kB
Mlocked:               8 kB
HighTotal:       1040968 kB
HighFree:          18284 kB
LowTotal:         871872 kB
LowFree:           51956 kB
SwapTotal:       3903752 kB
SwapFree:        3508852 kB

One more command to get details about CPU usage: mpstat Click on here to get detailed options and output of mpstat command.
root@desktop03:~# mpstat
Linux 3.0.0-12-generic (desktop03)   Tuesday 23 October 2012         _i686_  (4 CPU)

10:31:22  IST  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
10:31:22  IST  all    0.26    0.02    0.21    0.27    0.00    0.00    0.00    0.00   99.24
root@desktop03:~#

There are commands like sar, top,, some utilities like iftop, gnome-system-monitor to monitor the usage of CPU in Linux. Get more information regarding this as well, so you can use it where you need.
Posted by Machindra Dharmadhikari On 10/23/2012 05:30:00 PM No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner