vmstat :报告处理器、内存、页、块io、cpu活动信息

vmstat [-a] [-n] [-S unit] [delay [ count]]

vmstat [-s] [-n] [-S unit]

vmstat [-m] [-n] [delay [ count]]

vmstat [-d] [-n] [delay [ count]]

vmstat [-p disk partition] [-n] [delay [ count]]

vmstat [-f]

vmstat [-V]

-a:显示活动和非活动内存

-f:显示系统从启动到现在的fork次数。

-m:显示slab信息。

-d:显示磁盘信息

[root@netnic ~]# vmstat   1
procs --------memory------- --swap-- ---io--- --system-- -----cpu----
r  b   swpd   free   buff  cache   si   so    bi   bo   in   cs us sy  id wa st
0  0   6128 3006 3485 1391    0    0     3    81   18    8  3  2   95  0  0
0  0   6128 3005 3485 1391    0    0     0     0 2295 11  2  2   97  0  0
0  0   6128 3005 3485 1391    0    0     0     0 2327 10  1  1   98  0  0
0  0   6128 3005 3485 1391    0    0     0     0 2194  6   1  1   99  0  0
0  0   6128 3005 3485 1391    0    0    28    0 1808  5   1  1   98  0  0
0  0   6128 3005 3485 1391    0    0     0    28 1760 6   1  0   98  0  0

Procs

       r: The number of processes waiting for run time.

          等待运行的进程数

       b: The number of processes in uninterruptible sleep.

          处于不可中断状态的睡眠进程数,常见的情况是由IO引起的,正常情况下为0比较好。

【注】当r值超过服务器上cpu的数量,就可能存在cpu瓶颈,有一些任务就要等待执行。当业

务繁忙的时候,不超过2倍cpu数量,还是可以认为合理的。

 

Memory

swpd: the amount of virtual memory used.

           使用的虚拟内存数量

free: the amount of idle memory.

         空闲的物理内存

buff: the amount of memory used as buffers.

         作为buffer cache的内存,对块设备的读写进行缓冲

cache: the amount of memory used as cache.

          作为page cache的内存, 文件系统的cache

inact: the amount of inactive memory. (-a option)

          非活动内存数量

active: the amount of active memory. (-a option)

          活动内存数量

【注】swpd 的值比较大,但是 si, so 的值长期为 0,这种情况我们可以不用担心,不会影响

系统性能;如果 cache 的值很大,说明cache住的文件数很多。如果频繁访问到的文件都能被

cache住,那么磁盘的读IO bi会非常小。

【注1】buffer和cache的区别

buffer : 也叫块缓冲,是根据磁盘的读写设计的,把分散的操作集中进行,减少磁盘碎片和硬

盘的反复寻道,从而提高系统性能。

cache: 作为page cache的内存, 是把读取过的数据保存起来,重新读取时若命中(找到需要的

数据)就不要去读硬盘了,若没有命中就读硬盘。

 

Swap

       si: Amount of memory swapped in from disk (/s).

           交换内存使用,由磁盘调入内存的数量
       so: Amount of memory swapped to disk (/s).

           交换内存使用,由内存调入磁盘

【注】当内存短缺时,会导致虚拟内存页频繁导出和导入,页导出并不能说明RAM瓶颈,虚拟内存

系统经常会对内存段进行页导出,但页导入操作就表明了服务器需要更多的内存了, 页导入需要

从SWAP DISK上将内存段复制回RAM,导致服务器速度变慢,所以si值高时,有可能是内存短缺

问题造成。

【注2】paging和swap的区别

页面调度paging:是将内存中最近不常使用的页面换到磁盘上,把常使用的页面(活动页面)保留

在内存中供进程使用。

交换(swap):是系统将整个进程,而不是部分页面,全部换到磁盘上。

 

IO

bi: Blocks received from a block device (blocks/s).

      从块设备读入的数据块数(读磁盘)

bo: Blocks sent to a block device (blocks/s).

      写入到块设备的数据块(写磁盘) 

【注】磁盘写的数据量稍大,如果是大文件的写,10M以内基本不用担心,如果是小文件写2M

以内基本正常

 

System

in: The number of interrupts per second, including the clock.

      每秒产生的中断次数,包括时钟中断

cs: The number of context switches per second.

      每秒产生的上下文切换次数

【注】上面这2个值越大,会看到由内核消耗的CPU时间会越多

 

CPU

        These are percentages of total CPU time.

        us: Time spent running non-kernel code. (user time, including nice time)

              非内核进程消耗的CPU时间百分比

sy: Time spent running kernel code. (system time)

      内核进程消耗的CPU时间百分比

id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.

     cpu处于空闲状态的时间百分比

wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.

       IO等待消耗的CPU时间百分比

st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

       被虚拟处理器专用的时间

【注】us 的值比较高时,说明用户进程消耗的CPU时间多,但是如果长期超过50% 的

使用,那么我们就该考虑优化,如果idle经常为0,或者cpu sy是cpu us两倍,那么系

统可能面临cpu资源短缺。sy 的值高时,说明系统内核消耗的CPU资源多,这并不是良

性的表现,我们应该检查原因。

wa 的值高时,说明IO等待比较严重,这可能是由于磁盘大量作随机访问造成,也有可能

是磁盘的带宽出现瓶颈(块操作)。数字越大,表示文件系统活动阻碍cpu的情况越严重,

因为cpu在等待慢速的磁盘系统提供数据。wa为0是最理想的。如果wa经常大于10,可

能文件系统就需要进行性能调整了。