Linux常用命令之vmstat--rainnyzhong的博客

来源:百度文库 编辑:神马文学网 时间:2024/04/28 03:36:06
.vmstatvmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可用来纪录 processes, memory, paging, block IO, traps, 与 cpu activity [root@raclinux1 ~]# vmstat --help
usage: vmstat [-V] [-n] [delay [count]]
              -V prints version.
              -n causes the headers not to be reprinted regularly.
              -a print inactive/active page stats.
              -d prints disk statistics
              -D prints disk table
              -p prints disk partition statistics
              -s prints vm table
              -m prints slabinfo
              -S unit size
              delay is the delay between updates in seconds.
              unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)
              count is the number of updates. 其中红色部分是新选项,2.5.70及以上内核适用 2.举例:[oracle@raclinux1 ~]$ vmstat 3
procs -----------------memory---------------swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache       si   so     bi    bo   in    cs us sy id wa
 0  0      0   1672  29032 108664    0    0    66    16 1012   259  2  7 87  3
 0  0      0   1672  29040 108664    0    0     0    11  930   199  1  4 95  0
 0  0      0   1676  29040 108664    0    0     0    39  949   202  1  3 96  0
 0  0      0   1680  29048 108664    0    0     0     4  937   199  1  3 96  0
 0  0      0   1680  29048 108664    0    0     0    25  932   198  1  4 95  0
 0  0      0   1680  29056 108664    0    0     0     4  944   206  1  3 96  0
 0  0      0   1680  29056 108664    0    0     0     0  932   198  1  3 96  0
 0  0      0   1680  29064 108664    0    0     0     4  935   196  1  3 96  0
 0  0      0   1680  29064 108664    0    0     0     0  941   198  1  3 96  0
 0  0      0   1680  29072 108664    0    0     0     4  949   202  1  2 96  0
 0  0      0   1680  29072 108664    0    0     0     0  938   196  1  3 96  0
 其中:   Procs
       r: The number of processes waiting for run time.在运行队列中等候运行
       b: The number of processes in uninterruptible sleep.被资源阻塞(I/0,页面调度,等等)

                                                                                
   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)
                                                                               
   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. 3.解读:A.CPU问题:下面几列需要被察看,以确定cpu是否有问题 Processes in the run queue (procs r)
User time (cpu us)
System time (cpu sy)
Idle time (cpu id)
 问题情况:
1.) 如果processes in run queue (procs r)的数量远大于系统中cpu的数量,将会使系统便慢。
2.) 如果这个数量是cpu的4倍的话,说明系统正面临cpu能力短缺,这将使系统运行速度大幅度降低
3.) 如果cpu的idle时间经常为0的话,或者系统占用时间(cpu sy)是用户占用时间(cpu us)两辈的话,系统面临缺少cpu资源 解决方案 :
解决这些情况,涉及到调整应用程序,使其能更有效的使用cpu,同时增加cpu的能力或数量 B.内存问题:主要查看页导入的数值(swap中的si),如果该值比较大就要考虑内存,大概方法如下:1).最简单的,加大RAM  
2).改小SGA,使得对RAM需求减少  
3).减少RAM的需求(如:减少PGA)  4.新参数: 1).vmstat -D 显示磁盘信息(只能一次性,delay参数无效)[oracle@raclinux1 ~]$ vmstat -D
           25 disks
            6  partitions 
     17577  total reads
      4140   merged reads
  587320   read sectors
  248149   milli reading
     6889   writes
    13672  merged writes
  164444  written sectors
  167353  milli writing
           0  inprogress IO
        178 milli spent IO
 2).vmstat -d 查看磁盘统计信息  [oracle@raclinux1 ~]$ vmstat -d | grep -v ram
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
hdc       13     88     680     249      0      0       0       0      0      0
sda    17396   2644  580819  243635   6983  13749  165836  167797      0    178
sdb       46    657    1185    1808      0      0       0       0      0      0
sdc       53    420    1436    1667      6      4      56       7      0      1
sdd       24    132    1248     348      0      0       0       0      0      0
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
sde       36    135    1368     288      0      0       0       0      0      0
sdf        9     64     584     154      0      0       0       0      0      0
fd0        0      0       0       0      0      0       0       0      0      0
md0        0      0       0       0      0      0       0       0      0      0
 3).vmstat -s (一次性,delay参数无效) [oracle@raclinux1 ~]$ vmstat -s
       256044  total memory
       254428  used memory
       153584  active memory
        70960  inactive memory
         1616  free memory
        33976  buffer memory
       104140  swap cache
      1044184  total swap
            0  used swap
      1044184  free swap
        13214 non-nice user cpu ticks
         3759 nice user cpu ticks
        43122 system cpu ticks
       827934 idle cpu ticks
        14246 IO-wait cpu ticks
           98 IRQ cpu ticks
        27960 softirq cpu ticks
       293660 pages paged in
        83714 pages paged out
            0 pages swapped in
            0 pages swapped out
      9369649 interrupts
      2217323 CPU context switches
   1143195570 boot time
        29804 forks