您的位置:首页 > 运维架构 > Linux

《高性能Linux服务器构建实战运维监控、性能调优与集群应用》 10.6 Linux下常见的性能分析工具 vmstat

2013-01-03 21:20 941 查看
10.6.1   vmstat 命令

lester@lester-ThinkPad-T410:~/study/vmstat$ cat vmstat.txt

VMSTAT(8)                                          System Administration                                         VMSTAT(8)

NAME

       vmstat - Report virtual memory statistics[n. 统计;统计学;[统计] 统计资料]

SYNOPSIS

       vmstat [options] [delay [count]]

DESCRIPTION

       vmstat reports information about processes, memory, paging, block IO, traps[软中断], disks and cpu activity.

       The  first report produced gives averages[平均值] since the last reboot.  Additional[adj. 附加的,额外的] reports give information on a sampling[n. 取样;抽样]

       period of length delay.  The process and memory reports are instantaneous[瞬间的;即时的;猝发的] in either case.

OPTIONS

       delay  The delay between updates in seconds.  If no delay is specified, only one report is printed with the average

              values since boot.

       count  Number of updates.  In absence of count, when delay is defined, default is infinite[n. 无限;[数] 无穷大;无限的东西(如空间,时间)].

       -a, --active

              Display active and  inactive[不活跃的;不活动的;怠惰的;闲置的] memory, given a 2.5.41 kernel or better.

       -f, --forks

              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.

       -m, --slabs

              Displays slab info.

       -n, --one-header

              Display the header only once rather than periodically[adv. 定期地;周期性地;偶尔;间歇].

       -s, --stats

              Displays a table of various event counters and memory statistics[统计,统计学].  This display does not repeat.

       -d, --disk

              Report disk statistics (2.5.70 or above required).

       -D, --disk-sum

              Report some summary statistics about disk activity.

       -p, --partition device

              Detailed statistics about partition (2.5.70 or above required).

       -S, --unit character

              Switches  outputs  between 1000 (k), 1024 (K), 1000000 (m), or 1048576 (M) bytes. 

Note this does not change the swap (si/so) or block (bi/bo) fields.

       -V, --version

              Display version information and exit.

       -h, --help

              Display help and exit.

FIELD DESCRIPTION FOR VM MODE

   Procs

       r: The number of processes waiting for run time.

       b: The number of processes in uninterruptible[adj. 不间断的] 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)

   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[adj. 闲置的;懒惰的;停顿的].  Prior to Linux 2.5.41, this includes IO-wait time.

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

       st: Time stolen【偷走的】 from a virtual machine.  Prior to Linux 2.6.11, unknown.

FIELD DESCRIPTION FOR DISK MODE

   Reads

       total: Total reads completed successfully

       merged: grouped reads (resulting in one I/O)

       sectors: Sectors read successfully

       ms: milliseconds spent reading

   Writes

       total: Total writes completed successfully

       merged: grouped writes (resulting in one I/O)

       sectors: Sectors written successfully

       ms: milliseconds spent writing

   IO

       cur: I/O in progress

       s: seconds spent for I/O

FIELD DESCRIPTION FOR DISK PARTITION MODE

       reads: Total number of reads issued to this partition

       read sectors: Total read sectors for partition

       writes : Total number of writes issued to this partition

       requested writes: Total number of write requests made for partition

FIELD DESCRIPTION FOR SLAB MODE

       cache: Cache name

       num: Number of currently active objects

       total: Total number of available objects

       size: Size of each object

       pages: Number of pages with at least one active object

NOTES

       vmstat does not require special permissions.

       These reports are intended to help identify system bottlenecks[瓶颈(bottleneck的复数)].  Linux vmstat does not count itself  as  a  running

       process.

       All linux blocks are currently 1024 bytes.  Old kernels may report blocks as 512 bytes, 2048 bytes, or 4096 bytes.

       Since procps 3.1.9, vmstat lets you choose units (k, K, m, M).  Default is K (1024 bytes) in the default mode.

       vmstat uses slabinfo 1.1

FILES

       /proc/meminfo

       /proc/stat

       /proc/*/stat

SEE ALSO

       free(1), iostat(1), mpstat(1), ps(1), sar(1), top(1)

BUGS

       Does not tabulate[vt. 使成平面;把…制成表格] the block io per device or count the number of system calls.

AUTHORS

       Written by Henry Ware ⟨al172@yfn.ysu.edu⟩.

       Fabian Frédérick ⟨ffrederick@users.sourceforge.net⟩ (diskstat, slab, partitions...)

REPORTING BUGS

       Please send bug reports to ⟨procps@freelists.org⟩

procps-ng                                             September 2011                                             VMSTAT(8)

lester@lester-ThinkPad-T410:~/study/vmstat$ vmstat 3 5

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

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

 2  0      0     2167968 156720 923432    0    0    17    22  211  785  6    2    90   1

 1  0      0     2168084 156720 923560    0    0     0     0    368 1538  2   2    97   0

 0  0      0     2168084 156720 923432    0    0     0     0    348 1457  2   1    97   0

 0  0      0     2168084 156728 923432    0    0     0     5    352 1425  2   2    97   0

 0  0      0     2167960 156728 923432    0    0     0     0    353 1448  2   2    97   0

vmstat是Virtual Memory Statistics(虚拟内存统计)的缩写,可以对操作系统的内存信息,进程状态,CPU活动等进行监视,不足之处是无法对某个进程进行深入分析。

vmstat [-V] [-n] [delay [count]]

各个选项及参数含义如下:

-V 表示打印出版本信息,是可选参数

-n 表示在周期性循环输出时,输出的头部信息仅显示一次

delay 表示两次输出之间的间隔时间

count 表示按照"delay"指定的时间间隔统计的次数,默认为1

例如:

vmstat 3

表示每3秒更新一次输出信息,循环输出,按Ctrl+c停止输出

vmstat 3  5 表示每3秒更新一次输出信息,统计5次后停止输出

输出结果如下:

lester@lester-ThinkPad-T410:~/study/vmstat$ vmstat 3 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      0       2009456 161148 946436    0    0         14   20   205  768      6      2    90  1

 0  0      0       2022716 161156 932508    0    0         0     16    404  1343   7      6    87  0

 2  0      0       2022468 161160 932512    0    0         0      7     564  3223   18    5    76  0

 0  0      0       2011432 161160 943780    0    0         0      4     642  4382   29    7    64  0

 2  0      0       2014904 161168 938400    0    0         0     11    562  4695   20    7    73  0

每项输出的解释如下:

procs

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

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

memory

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

free列表示当前空闲的物理内存数量(以KB为单位)

buff 列表示buffers cache 的内存数量,一般对块设备的读写才需要缓冲。

cache 列表示page cached的内存数量,一般作为文件系统进行缓存,频繁访问的文件都会被缓存。如果cache值较大,说明缓存的文件数较多,如果此时io中的bi比较小,说明文件系统效率比较好

swap

si列表示由磁盘调入内存,也就是由内存进入内存交换区的内存大小

so列表示由内存调入磁盘,也就是由内存交换区进入内存的内存大小

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

io项现实磁盘读写状况

bi列表示从块设备读入数据的总量(即读磁盘)(kb/s)

bo列表示写到块设备的数据总量(即写磁盘)(kb/s)

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

sys显示采集间隔內发生的中断数

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%,如果超过20%,说明i/o等待严重。引起I/O等待的原因可能是磁盘大量随机读写造成的,也可能是磁盘或者磁盘控制器的带宽瓶颈(主要是块操作)造成的。

综上所述,在对CPU的评估中,需要重点注意procs项中r列和CPU项中的us、sy和id列的值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LINUX vmstat 性能