vmstat 命令

命令简介:

 

 

 vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存、进程、IO读写、CPU活动等进行监视。它是对系统的整体情况进行统计,不足之处是无法对某个进程进行深入分析。

 

     指令所在路径:/usr/bin/vmstat

 

 

     注意事项: 本文实验、总结环境为RHEL 5.7,vmstat在不同版本的Unix与Linux有所差别,使用时,最好先参考对应操作系统的vmstat版本。

 

    

     命令手册中的介绍如下:

 

 

     DESCRIPTION

 

    vmstat  reports  information about processes, memory, paging, block IO,

 

       traps, and cpu activity.

 

 

 

       The first report produced gives averages since the last reboot.   Addi-

 

       tional  reports  give information on a sampling period of length delay.

 

       The process and memory reports are instantaneous in either case.

 

 

命令语法:

 

 

       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]

 

 

命令参数:

 

 

    此命令参数是Red Hat Enterprise Linux Server release 5.7下vmstat命令参数,不同版本Linux的cp命令参数有可能不同。不过默认应该都是[ delay [ count ] ] ,delay是间隔,count显示多少次信息。可以和上面的某些参数结合使用。

 

参数

英文描述

描叙

delay

 

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

count

 

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

-a

The -a switch displays active/inactive memory, given a 2.5.41 kernel or better.

开启显示active/inactive memory。

-f

The -f switch displays the number of forks since boot.  This includes the fork, vfork,  and  clone  system calls,  and is equivalent to the total number of tasks created. Each process is represented by one or more tasks, depending on thread usage. This display does not repeat.

显示此系统启动以来的forks的总数,包括fork、vfork和clone system calls

-m

The -m displays slabinfo

显示slabinfo信息

-n

The -n switch causes the header to be displayed only once rather than periodically.

只显示头信息,不周期性显示.也就是说开启这个参数,只显示头部信息一次。

-s

The -s switch displays a table of various event counters and memory statistics. This display does not repeat.

显示各种事件计数器表和内存统计信息,这显示不重复。

-d

The -d reports disk statistics (2.5.70 or above required)

显示磁盘统计数据(内核要求2.5.70 或以上)

-w

The -w enlarges field width for big memory sizes

可以扩大字段长度,当内存较大时,默认长度不够完全展示内存。

-p

The -p followed by some partition name for detailed statistics (2.5.70 or above required)

显示磁盘分区数据(disk partition statistics )

-S

The -S followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes

参数S控制输出性能指标的单位,k(1000) K(1024) 或 M(1048576) 默认单位为K(1024 bytes)

-V

The -V switch results in displaying version information.

 

查看vmstat命令的版本

输出字段意义:

 

 

Procs

       r: The number of processes waiting for run time.

 

       等待运行的进程数。如果等待运行的进程数越多,意味着CPU非常繁忙。另外,如果该参数长期大于和等于逻辑cpu个数,则CPU资源可能存在较大的瓶颈。

       b: The number of processes in uninterruptible sleep.

 

 

       处在非中断睡眠状态的进程数。意味着进程被阻塞。主要是指被资源阻塞的进程对列数(比如IO资源、页面调度等),当这个值较大时,需要根据应用程序来进行分析,比如数据库产品,中间件应用等

 

 

Memory

       swpd: the amount of virtual memory used.

 

       已使用的虚拟内存大小。如果虚拟内存使用较多,可能系统的物理内存比较吃紧,需要采取合适的方式来减少物理内存的使用。swapd不为0,并不意味物理内存吃紧,如果swapd没变化,si、so的值长期为0,这也是没有问题的

      

       free: the amount of idle memory.

 

       空闲的物理内存的大小

       buff: the amount of memory used as buffers.

 

       用来做buffer(缓存,主要用于块设备缓存)的内存数,单位:KB

       cache: the amount of memory used as cache.

 

       用来做cache(缓存,主要用于缓存文件)的内存,单位:KB

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

 

       inactive memory的总量

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

 

 

       active memroy的总量。

 

 

Swap

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

 

        从磁盘交换到内存的交换页数量,单位:KB/秒。

 

       so: Amount of memory swapped to disk (/s).

        从内存交换到磁盘的交换页数量,单位:KB/秒

 

        内存够用的时候,这2个值都是0,如果这2个值长期大于0时,系统性能会受到影响,磁盘IO和CPU资源都会被消耗。

   当看到空闲内存(free)很少的或接近于0时,就认为内存不够用了,这个是不正确的。不能光看这一点,还要结合si和so,

    如果free很少,但是si和so也很少(大多时候是0),那么不用担心,系统性能这时不会受到影响的。

 

       当内存的需求大于RAM的数量,服务器启动了虚拟内存机制,通过虚拟内存,可以将RAM段移到SWAP DISK的特殊磁盘段上,

   这样会 出现虚拟内存的页导出和页导入现象,页导出并不能说明RAM瓶颈,虚拟内存系统经常会对内存段进行页导出,

   但页导入操作就表明了服务器需要更多的内存了, 页导入需要从SWAP DISK上将内存段复制回RAM,导致服务器速度变慢。

 

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资源,这个数值应该越小越好。

 

CPU

       These are percentages of total CPU time.

 

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

 

        用户CPU时间(非内核进程占用时间)(单位为百分比)。 us的值比较高时,说明用户进程消耗的CPU时间多

 

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

 

         系统使用的CPU时间(单位为百分比)。sy的值高时,说明系统内核消耗的CPU资源多,这并不是良性表现,我们应该检查原因。

 

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

 

        空闲的CPU的时间(百分比),在Linux 2.5.41之前,这部分包含IO等待时间。

 

       wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

 

        等待IO的CPU时间,在Linux 2.5.41之前,这个值为0 .这个指标意味着CPU在等待硬盘读写操作的时间,用百分比表示。wait越大则机器io性能就越差。说明IO等待比较严重,这可能由于磁盘大量作随机访问造成,也有可能磁盘出现瓶颈(块操作)。

 

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

 

 

使用示例:

 

 

1: 查看vmstat命令的帮助信息

[root@DB-Server ~]# man vmstat

2: 显示活动(active)与非活动(inactive)的内存

3:不加任何参数,vmstat命令只输出一条记录,这个数据是自系统上次重启之后到现在的平均数值。

 

4:显示各种事件计数器表和内存统计信息,这显示不重复。

5:可以扩大字段长度,当内存较大时,默认长度不够完全展示内存时,会导致字段值便宜,导致查看不便

6:显示磁盘分区数据(disk partition statistics )

 

原文地址:https://www.cnblogs.com/Easonlou/p/8109965.html