Monday, October 29, 2012

                                 The mpstat command is used for checking the cpu usage in Linux or monitor the Linux system performance. It gives the processor statistics. If your system has multiple processor cores, you can use the mpstat command to monitor each individual core. The mpstat command provides the same CPU utilization statistics as vmstat, but mpstat gives the statistics out on a per processor basis.
You can see example as below for CPU performance monitoring linux:
{desktop002:root} mpstat
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0  319   0    5   340  101  121    0   15    4    0   339    1   1   0  99
  1  113   0    2    94   16   81    0    7    4    0   113    0   1   0  99
  2  156   0    2    74   18   61    0    5    3    0   123    0   0   0 100
  3  154   0    2    66   22   61    0    3    3    0   169    0   0   0 100
  4 2156   0    3    51   32   73    0   28    5    0   962    1   2   0  97
  5   31   0    2    18    1   16    0    4    3    0    47    0   0   0 100
  6   11   0    2    19    2   14    0    4    2    0    24    0   0   0 100
  7    9   0    2    18    2   14    0    4    2    0    24    0   0   0 100
  8  265   0    1    40   11   42    0    4    2    0   153    0   0   0 100
  9  115   0    2    36    8   31    0    3    2    0    81    0   0   0 100
 10   72   0    1    37    7   40    0    2    2    0   118    0   0   0 100
 11  235   0    1    29    6   35    0    3    2    0   163    0   0   0 100
 12    8   0    2    18    3   12    0    4    2    0    16    0   0   0 100
 13    6   0    2    16    1   12    0    4    2    0    13    0   0   0 100
 14    6   0    2    17    1   13    0    4    2    0    19    0   0   0 100
 15    6   0    2    16    1   12    0    4    2    0    14    0   0   0 100
{desktop002:root}

mpstat command's general format to get output:
$ mpstat <interval> <count>

You can see the columns and its meaning as follows:
minf                          minor faults.
mjf                          major faults.
Xcal                         inter-processor cross calls
Intr                          interrupts
ithr                          interrupts as threads  (not  counting  clock interrupt)
csw                         context switches
icsw                        involuntary context switches
migr                        thread migrations (to another processor)
smtx                       spins on mutexes (lock not acquired on first try)
srw                          spins  on  readers/writer  locks  (lock  not acquired on first try)
syscl                        system calls
usr                           percent user time
sys                           percent system time
wt                            the I/O wait time is no longer calculated as a percentage of CPU time, and this statistic will always return zero.
idl                            percent idle time

mpstat command examples:
If you want to get 7 reports at interval of 60 seconds (1 minute) then use following command:
{desktop004:root} mpstat 60 7

You will get CPU usage 7 reports on every 1 minute interval. Run this background, and redirect its output to one file.
Posted by Machindra Dharmadhikari On 10/29/2012 08:54:00 PM No comments READ FULL POST

Saturday, October 27, 2012

Jmap Command                                                            Check java process performance statistics

Vmstat command collects and reports data about system's memory, paging, block IO, kernel threads, swap and processor utilization in real time. It is used to determine the root cause of linux system performance and memory use related issues. It reports virtual memory statistics.
[machindra@desktop03]~% vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0    208  83508 253692 2206428    0    0     0    14    0     1  8  3 89  0
[machindra@desktop03]~%

Difference between top and vmstat command:

 Field descriptions of vmstat command's output:
 Procs
       r: The number of processes waiting for run time.
       b: The number of processes in uninterruptible sleep.
   Memory
       swpd: The amount of virtual memory used.
       free: The amount of idle memory.
       buff: The amount of memory used as buffers.
       cache: The amount of memory used as cache.
       inact: The amount of inactive memory. (-a option)
       active: The amount of active memory. (-a option)


Click to  know more about: when and where not to use shell script
   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).
   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).
   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.
   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code. (user time, including nice time)
       sy: Time spent running kernel code. (system time)
       id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

Vmstat command examples:
·         Get vmstat five reports after 2 seconds interval as follows:
[machindra@desktop03]~% vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0    208  83308 253692 2206428    0    0     0    14    0     1  8  3 89  0
 0  0    208  83308 253692 2206428    0    0     0     0 1017    36  0  0 100  0
 0  0    208  83308 253692 2206428    0    0     0     6 1017    43  0  0 100  0
 0  0    208  83372 253692 2206428    0    0     0    22 1018    43  0  0 100  0
 0  0    208  83372 253692 2206428    0    0     0     0 1024    40  0  0 100  0
[machindra@desktop03]~%

·         Get size in kilobytes. Use –S for unit size and 1 1 for getting 1 report after 1 second. You can use  M instead of k, to get size in Mega Bytes.
[machindra@desktop03]~% vmstat -S k 1 1
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0    212  85315 259780 2259382    0    0     0    14    0     1  8  3 89  0
[machindra@desktop03]~%


Check CPU usage in Linux                                                     Recover deleted files in Linux
Posted by Machindra Dharmadhikari On 10/27/2012 05:51:00 PM 2 comments READ FULL POST

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 READ FULL POST

Thursday, October 18, 2012

                  It is very easy to extend already created logical volume, if you have free space in volume group. You need to understand the details about existing volume group from which this logical volume created before extending the logical volume. Follow the following steps:
Step1:  Check the Name of Volume Group of respective logical Volume. You can see it by two commands, lvs or lvdisplay.
[root@server92 ~]#
[root@server92 ~]# lvs
  LV           VG                        Attr        LSize   Origin Snap%  Move Log Copy%  Convert
  MyLogicalVol MyVolume            -wi-ao   300.00m
  home         vgsrv                              -wi-ao   256.00m
  root         vgsrv                                  -wi-ao                   3.31g
  swap         vgsrv                                -wi-ao   544.00m
[root@server92 ~]#

Step2: Check free space in Volume Group.
[root@server92 ~]#
[root@server92 ~]# vgdisplay MyVolume
  --- Volume group ---
  VG Name               MyVolume
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               496.00 MiB
  PE Size               4.00 MiB
  Total PE              124
  Alloc PE / Size       75 / 300.00 MiB
  Free  PE / Size       49 / 196.00 MiB                            // Free Space in Volume Group.
  VG UUID               ZQcrfp-FfVC-3WoP-ev8q-n854-AYEb-ZrPAex

[root@server92 ~]#
[root@server92 ~]#

Step3: You can extend the logical volume with free space present in its own Volume Group(VG). Currently, we have 196MB free space in Volume group of logical volume (MyLogicalVol). We will extend the partition /dev/mapper/MyVolume-MyLogicalVol by 100MB.
[root@server92 ~]#
[root@server92 ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-root
                      3.3G  2.1G  1.1G  68% /
tmpfs                 246M  260K  246M   1% /dev/shm
/dev/sda1             248M   30M  206M  13% /boot
/dev/mapper/vgsrv-home
                      248M   11M  226M   5% /home
/dev/mapper/MyVolume-MyLogicalVol
                      291M   11M  266M   4% /MyData
[root@server92 ~]#
[root@server92 ~]# lvextend -L +100M /dev/mapper/MyVolume-MyLogicalVol
  Extending logical volume MyLogicalVol to 400.00 MiB
  Logical volume MyLogicalVol successfully resized
[root@server92 ~]#
[root@server92 ~]#
[root@server92 ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-root
                      3.3G  2.1G  1.1G  68% /
tmpfs                 246M  260K  246M   1% /dev/shm
/dev/sda1             248M   30M  206M  13% /boot
/dev/mapper/vgsrv-home
                      248M   11M  226M   5% /home
/dev/mapper/MyVolume-MyLogicalVol
                      291M   11M  266M   4% /MyData
[root@server92 ~]#
[root@server92 ~]#
[root@server92 ~]# resize2fs /dev/mapper/MyVolume-MyLogicalVol
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/MyVolume-MyLogicalVol is mounted on /MyData; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/MyVolume-MyLogicalVol to 409600 (1k) blocks.
The filesystem on /dev/mapper/MyVolume-MyLogicalVol is now 409600 blocks long.

[root@server92 ~]#
[root@server92 ~]#
[root@server92 ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-root
                      3.3G  2.1G  1.1G  68% /
tmpfs                 246M  260K  246M   1% /dev/shm
/dev/sda1             248M   30M  206M  13% /boot
/dev/mapper/vgsrv-home
                      248M   11M  226M   5% /home
/dev/mapper/MyVolume-MyLogicalVol
                      388M   11M  358M   3% /MyData
[root@server92 ~]#

Step4: Check the free space of Logical Volume by command df –kh as mentioned above.
If you don't have free space in your Volume group, need to extend Volume group and then extend the Logical Volume. Click here to check how to extend the Volume group .
Posted by Machindra Dharmadhikari On 10/18/2012 12:04:00 AM No comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner