linux下vmstat命令解析 (性能相关以及系统性能诊断)

来源:互联网 发布:网络教育本科统考免考 编辑:程序博客网 时间:2024/05/22 01:36

[root@localhost ~]# vmstat 1 5

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----

 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa

 1  0      0 4886396 147552 2905036    0    0     1     4    4     3  0  0 100  0

 0  0      0 4886396 147552 2905036    0    0     0   228 4144  4103  1  1 98  0

 0  0      0 4886396 147552 2905036    0    0     0    88 1964  1286  0  0 99  0

 0  0      0 4886396 147552 2905036    0    0     0   100 2321  2007  1  0 99  0

 1  0      0 4886332 147552 2905036    0    0     0   156 2647  2265  1  0 99  0

[root@localhost ~]#

 

 

 

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.

 命令参数:

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

-f:显示从系统启动至今的fork数量 。

-m:显示slabinfo

-n:只在开始时显示一次各字段名称。

-s:显示内存相关统计信息及多种系统活动数量。

delay:刷新时间间隔。如果不指定,只显示一条结果。

count:刷新次数。如果不指定刷新次数,但指定了刷新时间间隔,这时刷新次数为无穷。

-d:显示磁盘相关统计信息。

-p:显示指定磁盘分区统计信息

-S:使用指定单位显示。参数有 k 、K 、m 、M ,分别代表1000、1024、1000000、1048576字节(byte)。默认单位为K(1024 bytes)

-V:显示vmstat版本信息。

vmstat是一个相当全面的性能分析工具,可以观察到系统的进程状态、内存使用、虚拟内存使用、磁盘的IO、中断、上下问切换、CPU使用等性能信息

 

 

   Procs

       r: The number of processes waiting for run time.(运行的和等待(CPU时间片)运行的进程数,这个值也可以判断是否需要增加CPU(长期大于cpu个数)

       b: The number of processes in uninterruptible sleep.(处于不可中断状态的进程数,这个值一般为2-3cpu的个数就表明cpu排队比较严要了,常见的情况是由IO引起的

 

 

   Memory

       swpd: the amount of virtual memory used.(现在已经使用的虚拟内存,单位k

       free: the amount of idle memory.(空闲物理内存,单位k

       buff: the amount of memory used as buffers.(作为buffer使用的物理内存,对块设备读写进行缓冲,单位k

       cache: the amount of memory used as cache. (作为cache使用的物理内存,对文件系统的缓冲,单位k

       inact: the amount of inactive memory. (-a option) (没有活动的物理内存,单位k)

       active: the amount of active memory. (-a option) (有活动的物理内存,单位k)

procs

        r:运行和等待CPU时间片的进程数,这个值如果长期大于系统CPU的个数,说明CPU不足,需要增加CPU。

        b:在等待资源的进程数,比如正在等待I/O或者内存交换等。

memory

        swpd:切换到内存交换区的内存大小。如果swpd的值不为0,或者比较大,只要si、so的值长期为0,这种情况一般不用担心,不会影响系统性能。

        free:当前空闲的物理内存大小。

        buff:buffers cache的内存大小。

        cache:page cached的内存大小

swap

        si:由磁盘调入内存

        so:由内存调入磁盘

在一般情况下,si、so的值都为0,如果si、so的值长期不为0,则表示系统内存不足,需要增加系统内存。

io

        bi:从块设备读入数据的总量(读磁盘)

        bo:写到块设备的数据总量(写磁盘)

这里设置的bi+bo参考值为1000,如果超过1000,而且wa值较大,则表示系统磁盘I/O有问题,应该考虑提高磁盘的读写性能。

system显示采集间隔内发生的中断数。

        in:在某一时间间隔内观测到的每秒设备中断数。

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

上面这两个值越大,由内核消耗的CPU时间越多。

CPU项显示了CPU的使用状态:

        us:显示用户进程消耗的CPU时间百分比。us的值比较高时,说明用户进程消耗的CPU时间多,但是如果长期大于50%,就需要考虑优化程序或算法。

        sy:显示内核进程消耗的CPU时间百分比。sy的值越高时,说明内核消耗的CPU资源很多。

根据经验,us+sy的参考值为80%,如果us+sy大于80%,说明可能存在CPU资源不足。

        id:显示CPU处在空闲状态的时间百分比。

        wa:显示IO等待所占用的CPU时间百分比。wa值越高,说明I/O等待越严重。

根据经验,wa的参考值为20%,如果wa超过20%,说明I/O等待严重。


buffer和cache的区别:

buffers are only used for file metadata (inodes, etc) and data from raw block devices. It's accessed via block device and block number.
Cache has file data blocks, and memory mapped information (i.e. files mapped with mmap() calls). It's accessed primarily via inode number.
  So, the main difference would be scope, One's more concerened with blocks on a device, the other with information in a file.

 buffer and cache both can flush to disk, however. The buffer to the device file and the cache through the file system layer to the block device.  


   Swap

       si: Amount of memory swapped in from disk (k/s). (每秒由磁盘调入内存的数量)

       so: Amount of memory swapped to disk (k/s). (每秒由内存调入磁盘的数量)

 

   IO

       bi: Blocks received from a block device (blocks/s). (从块设备读入的数据块数量)

       bo: Blocks sent to a block device (blocks/s).  (写到块设备的数据块数量)

如果这两个值比较大,说明io的压力也较大,cpu在io的等待可能也会大

 

   System

       in: The number of interrupts per second, including the clock. (每秒产生中断的次数)

       cs: The number of context switches per second.(每秒产生上下文切换的次数)

这个两个值比较大说明,说明消耗内核上cpu较多,可能不合理的使用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的时间,这个值越小,说明cpu可能很忙)

       wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero. (等待io使用cpu的时间)

 



2 0
原创粉丝点击