VirtualMemoryStatistics(vmstat)是报告关于进程,虚拟内存,磁盘,CPU活动的一个统计报告.
在一个多CPU系统中,vmstat统计所有个数的CPU的平均输出.为每个进程进行统计.没有参数时,vmstat显示每一行是自从系统启动以后的虚拟内存的活动情况.
vmstat的语法我们可以通过linux的man命令来查看。
将man的结果导入到指定的文本
#manvmstat|col-b>/u01/tianlesoftware.txt
查看vmstat用法
#manvmstat
VMSTAT(8) LinuxAdministrator’sManual VMSTAT(8)
NAME
vmstat-Reportvirtualmemorystatistics
SYNOPSIS
vmstat[-a][-n][delay[count]]
vmstat[-f][-s][-m]
vmstat[-Sunit]
vmstat[-d]
vmstat[-pdiskpartition]
vmstat[-V]
DESCRIPTION
vmstatreportsinformationaboutprocesses,memory,paging,blockIO,
traps,andcpuactivity.
Thefirstreportproducedgivesaveragessincethelastreboot. Addi-
tionalreportsgiveinformationonasamplingperiodoflengthdelay.
Theprocessandmemoryreportsareinstantaneousineithercase.
Options
The-aswitchdisplaysactive/inactivememory,givena2.5.41kernel
orbetter.
The-fswitchdisplaysthenumberofforkssinceboot. Thisincludes
thefork,vfork,andclonesystemcalls, andisequivalenttothe
totalnumberoftaskscreated.Eachprocessisrepresentedbyoneor
moretasks,dependingonthreadusage.Thisdisplaydoesnotrepeat.
The-mdisplaysslabinfo.
The-nswitchcausestheheadertobedisplayedonlyonceratherthan
periodically.
The-sswitchdisplaysatableofvariousevent countersandmemory
statistics.Thisdisplaydoesnotrepeat.
delayisthedelaybetweenupdatesinseconds. Ifnodelayisspeci-
fied,onlyonereportisprintedwiththeaveragevaluessinceboot.
countisthenumberofupdates. Ifnocountisspecifiedanddelayis
defined,countdefaultstoinfinity.
The-dreportsdiskstatistics(2.5.70oraboverequired)
The-pfollowedbysomepartitionnamefordetailedstatistics(2.5.70
oraboverequired)
The-SfollowedbykorKormorMswitchesoutputsbetween 1000,
1024,1000000,or1048576bytes
The-Vswitchresultsindisplayingversioninformation.
FIELDDESCRIPTIONFORVMMODE
Procs
r:Thenumberofprocesseswaitingforruntime.
b:Thenumberofprocessesinuninterruptiblesleep.
Memory
swpd:theamountofvirtualmemoryused.
free:theamountofidlememory.
buff:theamountofmemoryusedasbuffers.
cache:theamountofmemoryusedascache.
inact:theamountofinactivememory.(-aoption)
active:theamountofactivememory.(-aoption)
Swap
si:Amountofmemoryswappedinfromdisk(/s).
so:Amountofmemoryswappedtodisk(/s).
IO
bi:Blocksreceivedfromablockdevice(blocks/s).
bo:Blockssenttoablockdevice(blocks/s).
System
in:Thenumberofinterruptspersecond,includingtheclock.
cs:Thenumberofcontextswitchespersecond.
CPU
ThesearepercentagesoftotalCPUtime.
us:Timespentrunningnon-kernelcode.(usertime,includingnicetime)
sy:Timespentrunningkernelcode.(systemtime)
id:Timespentidle.PriortoLinux2.5.41,thisincludesIO-waittime.
wa:TimespentwaitingforIO.PriortoLinux2.5.41,shownaszero.
FIELDDESCRIPTIONFORDISKMODE
Reads
total:Totalreadscompletedsuccessfully
merged:groupedreads(resultinginoneI/O)
sectors:Sectorsreadsuccessfully
ms:millisecondsspentreading
Writes
total:Totalwritescompletedsuccessfully
merged:groupedwrites(resultinginoneI/O)
sectors:Sectorswrittensuccessfully
ms:millisecondsspentwriting
IO
cur:I/Oinprogress
s:secondsspentforI/O
FIELDDESCRIPTIONFORDISKPARTITIONMODE
reads:Totalnumberofreadsissuedtothispartition
readsectors:Totalreadsectorsforpartition
writes:Totalnumberofwritesissuedtothispartition
requestedwrites:Totalnumberofwriterequestsmadeforpartition
FIELDDESCRIPTIONFORSLABMODE
cache:Cachename
num:Numberofcurrentlyactiveobjects
total:Totalnumberofavailableobjects
size:Sizeofeachobject
pages:Numberofpageswithatleastoneactiveobject
totpages:Totalnumberofallocatedpages
pslab:Numberofpagesperslab
NOTES
vmstatdoesnotrequirespecialpermissions.
Thesereportsareintendedtohelpidentifysystembottlenecks. Linux
vmstatdoesnotcountitselfasarunningprocess.
Alllinuxblocksarecurrently1024bytes.Old kernelsmayreport
blocksas512bytes,2048bytes,or4096bytes.
Sinceprocps3.1.9,vmstatletsyouchooseunits(k,K,m,M)default
isK(1024bytes)inthedefaultmode
vmstatusesslabinfo1.1 FIXME
FILES
/proc/meminfo
/proc/stat
/proc/*/stat
SEEALSO
iostat(1),sar(1),mpstat(1),ps(1),top(1),free(1)
BUGS
Doesnottabulatetheblockioperdeviceorcountthenumberof sys-
temcalls.
AUTHORS
WrittenbyHenryWare<[email protected]>.
FabianFrédérick<[email protected]>(diskstat,slab,partitions...)
ThroatwobblerGinkgoLabs 27July1994 VMSTAT(8)
示例:
#vmstat210
procs-----------memory---------------------------swap--------io-------system-------cpu------
rbswpdfreebuffcachesisobiboincsussyidwa
11208289603812826820400278401050370546445
1020828896381282682040012801054310438581
20208288963813626819600257551056301439525
202082489638136268196002571104259368770
00208286723813626819600257251052372446455
002082882438140268192001291111052316332641
102082876838148268184002571091050286970211
1020828512381482681840025711046327648432
0020828832381482681840025711047313542521
002082883238152268180002571091050308433595
每2秒显示一次,共显示10次。
在Unix(Solaris)平台下:
-bash-3.00$vmstat210
kthrmemorypagediskfaultscpu
rbwswapfreeremfpipofrdesrs0s1----insycsussyid
00050163444200040126512350000010073114167233097
0002065576237511214540000000008706259503096
00020655122375048115000000000095152910663097
0002065512237504811530000000008525489343097
000206551223750484400000000008364839073097
0002065512237504814460000000008736329583097
00020655122375048000000000008124178633097
000206551223750484400000000008104818743097
00020653842374920000000001008014068623096
0002065384237492014460000000008175458983097
<!--EndFragment-->一些标准说明:
CPU:
1)如果(processr)是连续的大于在系统中的CPU的个数表示系统现在运行比较慢,有多数的进程等待CPU.
2)如果r的输出数大于系统中可用CPU个数的4倍的话,则系统面临着CPU短缺的问题,或者是CPU的速率过低,系统中有多数的进程在等待CPU,造成系统中进程运行过慢.
3)如果空闲时间(cpuid)持续为0并且系统时间(cpusy)是用户时间的两倍(cpuus)系统则面临着CPU资源的短缺.
简单的说就是:
r和b不高于5,如果r经常大于4,且id经常少于40,则表示CPU负荷很重。
us+sy不超过80%,如果大于80,进程就会在运行队列中花费等待时间,响应时间和吞吐量就会下降。
wa不超过25,如果说wa>40表明磁盘io没有也许存在不合理的平衡,或者对磁盘操作比较频繁
一般情况下,导致CPU资源不足都是应用程序的问题.比如一些SQL语句不合理等等都会造成这样的现象.
内存:
si和so基本为零。其中si表示当前每秒交换回内存(Swapin)的总量,单位为kbytes;so表示当前每秒交换出内存(Swapout)的总量,单位为kbytes。如果si,so长期不等于0,表示系统使用swap频繁,即内存不足。
一般情况下,如果内存的占用率比较高,但是,CPU的占用很低的时候,可以考虑是有很多的应用程序占用了内存没有释放.
要注意的是,Linux内存在使用后不会释放,所以一般会看到内存使用率很高,要判断linux内存是否正常,需要通过对swap交换区的交换频率来看。
具体参考blog:Linux内存机制
http://blog.csdn.net/tianlesoftware/archive/2010/04/08/5463790.aspx