罪丶犯 發表於 2011-2-26 13:07:07

Unix vmstat 命令详解宝典

<p>在一个多CPU系统中,vmstat统计所有个数的CPU的平均输出.为每个进程进行统计.没有参数时,vmstat显示每一行是自从系统启动以后的虚拟内存的活动情况. <br />vmstat 的语法我们可以通过linux的man 命令来查看。 <br />将man 的结果导入到指定的文本 <br /># man vmstat|col -b &gt; /u01/tianlesoftware.txt <br /><br /><strong>查看vmstat 用法 <br /></strong># man vmstat <br />VMSTAT(8) Linux Administrator&rsquo;s Manual VMSTAT(8) <br />NAME <br />vmstat - Report virtual memory statistics <br />SYNOPSIS <br />vmstat [-a] [-n] ] <br />vmstat [-f] [-s] [-m] <br />vmstat [-S unit] <br />vmstat [-d] <br />vmstat [-p disk partition] <br />vmstat [-V] <br />DESCRIPTION <br />vmstat reports information about processes, memory, paging, block IO, <br />traps, and cpu activity. <br />The first report produced gives averages since the last reboot. Addi- <br />tional reports give information on a sampling period of length delay. <br />The process and memory reports are instantaneous in either case. <br />Options <br />The -a switch displays active/inactive memory, given a 2.5.41 kernel <br />or better. <br />The -f switch displays the number of forks since boot. This includes <br />the fork, vfork, and clone system calls, and is equivalent to the <br />total number of tasks created. Each process is represented by one or <br />more tasks, depending on thread usage. This display does not repeat. <br />The -m displays slabinfo. <br />The -n switch causes the header to be displayed only once rather than <br />periodically. <br />The -s switch displays a table of various event counters and memory <br />statistics. This display does not repeat. <br />delay is the delay between updates in seconds. If no delay is speci- <br />fied, only one report is printed with the average values since boot. <br />count is the number of updates. If no count is specified and delay is <br />defined, count defaults to infinity. <br /><br />The -d reports disk statistics (2.5.70 or above required) <br />The -p followed by some partition name for detailed statistics (2.5.70 <br />or above required) <br />The -S followed by k or K or m or M switches outputs between 1000, <br />1024, 1000000, or 1048576 bytes <br />The -V switch results in displaying version information. <br /><br />FIELD DESCRIPTION FOR VM MODE <br />Procs <br />r: The number of processes waiting for run time. <br />b: The number of processes in uninterruptible sleep. <br />Memory <br />swpd: the amount of virtual memory used. <br />free: the amount of idle memory. <br />buff: the amount of memory used as buffers. <br />cache: the amount of memory used as cache. <br />inact: the amount of inactive memory. (-a option) <br />active: the amount of active memory. (-a option) <br />Swap <br />si: Amount of memory swapped in from disk (/s). <br />so: Amount of memory swapped to disk (/s). <br />IO <br />bi: Blocks received from a block device (blocks/s). <br />bo: Blocks sent to a block device (blocks/s). <br />System <br />in: The number of interrupts per second, including the clock. <br />cs: The number of context switches per second. <br />CPU <br />These are percentages of total CPU time. <br />us: Time spent running non-kernel code. (user time, including nice time) <br />sy: Time spent running kernel code. (system time) <br />id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. <br />wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero. <br /><br />FIELD DESCRIPTION FOR DISK MODE <br />Reads <br />total: Total reads completed successfully <br />merged: grouped reads (resulting in one I/O) <br />sectors: Sectors read successfully <br />ms: milliseconds spent reading <br />Writes <br />total: Total writes completed successfully <br />merged: grouped writes (resulting in one I/O) <br />sectors: Sectors written successfully <br />ms: milliseconds spent writing <br />IO <br />cur: I/O in progress <br />s: seconds spent for I/O <br /><br />FIELD DESCRIPTION FOR DISK PARTITION MODE <br />reads: Total number of reads issued to this partition <br />read sectors: Total read sectors for partition <br />writes : Total number of writes issued to this partition <br />requested writes: Total number of write requests made for partition <br /><br />FIELD DESCRIPTION FOR SLAB MODE <br />cache: Cache name <br />num: Number of currently active objects <br />total: Total number of available objects <br />size: Size of each object <br />pages: Number of pages with at least one active object <br />totpages: Total number of allocated pages <br />pslab: Number of pages per slab <br />NOTES <br />vmstat does not require special permissions. <br /><br />These reports are intended to help identify system bottlenecks. Linux <br />vmstat does not count itself as a running process. <br /><br />All linux blocks are currently 1024 bytes. Old kernels may report <br />blocks as 512 bytes, 2048 bytes, or 4096 bytes. <br /><br />Since procps 3.1.9, vmstat lets you choose units (k, K, m, M) default <br />is K (1024 bytes) in the default mode <br /><br />vmstat uses slabinfo 1.1 FIXME <br />FILES <br />/proc/meminfo <br />/proc/stat <br />/proc/*/stat <br />SEE ALSO <br />iostat(1), sar(1), mpstat(1), ps(1), top(1), free(1) <br />BUGS <br />Does not tabulate the block io per device or count the number of sys- <br />tem calls. <br />AUTHORS <br />Written by Henry Ware &lt;al172@yfn.ysu.edu&gt;. <br />Fabian Fr&eacute;d&eacute;rick &lt;ffrederick@users.sourceforge.net&gt; (diskstat, slab, partitions...) <br />Throatwobbler Ginkgo Labs 27 July 1994 VMSTAT(8) <br /><br /><strong>示例: <br /></strong># vmstat 2 10 <br />procs -----------memory---------------------- -----swap--- -----io---- ---system--- ----cpu------ <br />r b swpd free buff cache si so bi bo in cs us sy id wa <br />1 1 208 28960 38128 268204 0 0 278 40 1050 370 5 46 44 5 <br />1 0 208 28896 38128 268204 0 0 128 0 1054 310 4 38 58 1 <br />2 0 208 28896 38136 268196 0 0 257 55 1056 301 4 39 52 5 <br />2 0 208 24896 38136 268196 0 0 257 1 1042 593 6 87 7 0 <br />0 0 208 28672 38136 268196 0 0 257 25 1052 372 4 46 45 5 <br />0 0 208 28824 38140 268192 0 0 129 111 1052 316 3 32 64 1 <br />1 0 208 28768 38148 268184 0 0 257 109 1050 286 9 70 21 1 <br />1 0 208 28512 38148 268184 0 0 257 1 1046 327 6 48 43 2 <br />0 0 208 28832 38148 268184 0 0 257 1 1047 313 5 42 52 1 <br />0 0 208 28832 38152 268180 0 0 257 109 1050 308 4 33 59 5 <br /><br />每2秒显示一次,共显示10次。 <br /><br /><strong>在Unix(Solaris)平台下: <br /></strong>-bash-3.00$ vmstat 2 10 <br />kthr memory page disk faults cpu <br />r b w swap free re mf pi po fr de sr s0 s1 -- -- in sy cs us sy id <br />0 0 0 5016344 4200040 126 512 35 0 0 0 0 0 1 0 0 731 1416 723 3 0 97 <br />0 0 0 2065576 2375112 14 54 0 0 0 0 0 0 0 0 0 870 625 950 3 0 96 <br />0 0 0 2065512 2375048 11 50 0 0 0 0 0 0 0 0 0 951 529 1066 3 0 97 <br />0 0 0 2065512 2375048 11 53 0 0 0 0 0 0 0 0 0 852 548 934 3 0 97 <br />0 0 0 2065512 2375048 4 40 0 0 0 0 0 0 0 0 0 836 483 907 3 0 97 <br />0 0 0 2065512 2375048 14 46 0 0 0 0 0 0 0 0 0 873 632 958 3 0 97 <br />0 0 0 2065512 2375048 0 0 0 0 0 0 0 0 0 0 0 812 417 863 3 0 97 <br />0 0 0 2065512 2375048 4 40 0 0 0 0 0 0 0 0 0 810 481 874 3 0 97 <br />0 0 0 2065384 2374920 0 0 0 0 0 0 0 0 1 0 0 801 406 862 3 0 96 <br />0 0 0 2065384 2374920 14 46 0 0 0 0 0 0 0 0 0 817 545 898 3 0 97 <br /><br /><strong>一些标准说明: <br /></strong><br />CPU: <br />1) 如果(process r)是连续的大于在系统中的CPU的个数表示系统现在运行比较慢,有多数的进程等待CPU. <br />2) 如果r的输出数大于系统中可用CPU个数的4倍的话,则系统面临着CPU短缺的问题,或者是CPU的速率过低,系统中有多数的进程在等待CPU,造成系统中进程运行过慢. <br />3) 如果空闲时间(cpu id)持续为0并且系统时间(cpu sy)是用户时间的两倍(cpu us) 系统则面临着CPU资源的短缺. <br /><br /><strong>简单的说就是: <br /></strong>r 和 b 不高于5,如果r 经常大于4,且id 经常少于40,则表示CPU 负荷很重。 <br />us+sy 不超过80%,如果大于80,进程就会在运行队列中花费等待时间,响应时间和吞吐量就会下降。 <br />wa 不超过25, 如果说wa &gt;40表明磁盘io没有也许存在不合理的平衡,或者对磁盘操作比较频繁 <br /><br />一般情况下,导致CPU资源不足都是应用程序的问题.比如一些SQL语句不合理等等都会造成这样的现象. <br /><br />内存: <br />si和so基本为零。 其中si表示当前每秒交换回内存(Swap in)的总量,单位为kbytes;so表示当前每秒交换出内存(Swap out)的总量,单位为kbytes。如果si,so 长期不等于0,表示系统使用swap 频繁,即内存不足。 <br /><br />一般情况下,如果内存的占用率比较高,但是,CPU的占用很低的时候,可以考虑是有很多的应用程序占用了内存没有释放. <br /><br />要注意的是,Linux 内存在使用后不会释放,所以一般会看到内存使用率很高,要判断linux 内存是否正常,需要通过对swap 交换区的交换频率来看。 </p>
頁: [1]
查看完整版本: Unix vmstat 命令详解宝典