当前位置: 首页 > 科技观察

Linux常用性能分析命令

时间:2023-03-12 10:55:55 科技观察

性能分析vmstat虚拟内存统计使用情况Usage:vmstat[options][delay[count]]Options:-a,--activeactive/inactivememory-f,--forksnumberofforkssinceboot-m,--slabsslabinfo-n,--one-headerdonotredisplayheader-s,--statseventcounterstatistics-d,--diskdiskstatistics-D,--disk-summarizeddiskstatistics-p,--partitionpartitionspecificstatistics-S,--unitdefineddisplayunit-w,--widewideoutput-t,--timestampshowtimestamp-h,--helpdisplaythishelpandexit-V,--versionoutputversioninformationandexitexample[root@localhost~]#vmstatprocs------------memory-----------swap--------io-----system--------cpu-----rbswpdfreebuffcachesobiboincsussyidwast00712569272005651200011152236109900其中r:正在运行和等待CPU时间片的进程数。如果该值大于系统的CPU数,则说明CPU不足b:表示等待资源的进程数swpd:切换到内存交换区的内存大小(单位KB)free:大小offreephysicalmemory,我的机器一共有2G,剩余92M。buff:Linux/Unix系统用来存储,目录里有什么,权限等cachecache:直接用来记住我们打开的文件,对文件进行缓冲,将空闲物理内存的一部分用作文件和目录缓存是为了提高程序执行的性能。当程序使用内存时,buffer/cached会被快速使用或者内存泄漏,需要找到耗内存的进程并解决。so:每秒写入磁盘的虚拟内存大小,如果这个值大于0,同上。bi:块设备每秒接收的块数(读盘)(kb/s)bo:块设备每秒发送的块数(写盘)(kb/s)in:CPU数interruptspersecond,包括时间中断cs:每秒的上下文切换次数。us:用户进程消耗的CPU时间百分比sy:内核进程消耗的CPU时间百分比,当sy的值很高时,表示内核占用大量CPU资源id:空闲CPU时间百分比wt:百分比ofIOwaitingCPUtimefreememoryusage[root@localhost~]#freetotalusedfreesharedbuff/cacheavailableMem:18493361193336903441752565656460000Swap:2097148712482025900[root@localhost~]#free-htotalusedfreesharedbuff/cacheavailableMem:1.8G1.1G88M1.7M552M449MSwap:2.0G69M1.9G[root@localhost~]#free-mtotalusedfreesharedbuff/cacheavailableMem:18051165881552449Swap:2047691978[root@localhost~]#free-h2totalusedfreesharedbuff/cacheavailableMem:1.8G1.1G88M1.7M552M449MSwap:2.0G69M1.9G[root@localhostcachedfreemodb/usfreem~frees]#free-h2totalusedfreesharedbuff/缓存可用内存:1.8G1.1G88M1.7M552M449MSwap:2.0G69M1.9Gtotalusedfreesharedbuff/cacheavailableMem:1.8G1.1G88M1.7M552M449MSwap:2.0G69M1.9Gtotalusedfreesharedbuff/cacheavailableMem:1.8G1.1G88M1.7M552M449MSwap:2.0G69M1.9Guptime统计当前系统的运行情况[root@localhost~]#uptime09:59:55up2days,7min,1user,loadaverage:0.00,0.01,0.05loadaverage:系统1分钟、5分钟、15分钟的平均负载netstatcurrent网络信息使用方法usage:netstat[-vWeenNcCF][]-rnetstat{-V|--version|-h|--help}netstat[-vWnNcaeol][...]netstat{[-vWeenNac]-I[]|[-veenNac]-i|[-cnNe]-M|-s[-6tuw]}[delay]-r,--routedisplayroutingtable-I,--interfaces=displayinterfacetablefor-i,--interfacesdisplayinterfacetable-g,--groupsdisplaymulticastgroupmemberships-s,--statisticsdisplaynetworkingstatistics(likeSNMP)-M,--masqueradedisplaymasqueradedconnections-v,--verbosebeverbose-W,--widedon'ttruncateIPaddresses-n,--numericdon'tresolvenames--numeric-hostsdon'tresolvehostnames--numeric-portsdon'tresolveportnames--numeric-usersdon'tresolveusernames-N,--symbolicresolvehardwarenames-e,--extenddisplayother/moreinformation-p,--programsdisplayPID/Programnameforsockets-o,--timersdisplaytimers-c,--continuouscontinuouslisting-l,--listeningdisplaylisteningserversockets-a,--alldisplayallsockets(默认:已连接)-F,--fibdisplayForwardingInformationBase(默认)-C,--cachedisplayroutingcacheinsteadofFIB-Z,--contextdisplaySELinuxsecuritycontextforsockets<套接字>={-t|--tcp}{-u|--udp}{-U|--udplite}{-w|--raw}{-x|--unix}--ax25--ipx--netrom=Use'-6|-4'or'-A'or'--';default:inetListofpossibleaddressfamilies(whichsupportrouting):inet(DARPAInternet)inet6(IPv6)ax25(AMPRAX.25)netrom(AMPRNET/ROM)ipx(NovellIPX)ddp(AppletalkDDP)x25(CCITTX.25)其中-a(all)显示所有选项,默认不显示LISTENRelated-t(tcp)只显示tcp相关选项-u(udp)只显示udp相关选项-n拒绝显示别名,所有能显示的数字都转换成数字-l只列出处于Listen中的服务状态(监控)-p显示建立相关链接的程序名-r显示路由信息,路由表-e显示扩展信息,如uid等-s根据各个协议进行统计-c执行netstat命令定期提示:LISTEN和LISTENING的状态只能用-a或-ltop[root@localhostjava_demos]#toptop-14:36:14up2days,4:43,1user,loadaverage:0.00,0.01,0.05Tasks:110total,2running,108sleeping,0stopped,0zombie%Cpu(s):0.3us,0.2sy,0.0ni,99.3id,0.2wa,0.0hi,0.0si,0.0stKiBMem:1849336total,963348free,542372used,343616buff/cacheKiBSwap:209720648tous1126908availMemPIDUSERPRNIVIRTRESSHRS%CPU%MEMTIME+COMMAND1858mysql20014655042008006212S1.010.934:56.46mysqld1root2005663643082808S0.00.20:02.05systemd2root200000S0.00.00:00.04kthreadd3root200000S0.00.00:01.53ksoftirqd/05root0-20000S0.00.00:00.00kworker/0:0H7rootrt0000S0.00.00:00.07migration/08root200000S0.00.00:00.00rcu_bh9root200000S0.00.00:00.00rcuob/010root200000S0.00.00:00.00rcuob/111root200000S0.00.00:00.00rcuob/212root200000S0.00.00:00.00rcuob/313root200000S0.00.00:14.63rcu_sched14root200000S0.00.00:10.43rcuos/015root200000S0.00.00:04.67rcuos/1where***line:14:36:14currentsystemtimedays,4:43系统已经运行了2天4小时43分钟(期间没有重启过)1users当前有1个用户登录系统负载平均值:0.00、0.01、0.05,后面三个数字分别是1分钟、5分钟、15分钟的负载情况。loadaverage数据是每5秒检查一次活跃进程的个数,然后根据特定的算法计算出该值。如果用这个数字除以逻辑CPU的数量,结果大于5表示系统过载。第二行:Tasks任务(进程),系统现在一共有10个进程,其中2个正在运行,108个处于睡眠状态(sleep),0个处于停止状态,0个处于僵尸状态(zombie)。第三行:cpustatusus用户空间占用的CPU百分比sy内核空间占用的CPU百分比ni改变优先级的进程占用的CPU百分比id空闲CPU百分比waIO等待占用的CPU百分比hihardwareIRQoccupiedPercentageofCPUsi软件中断(SoftwareInterrupts)占用CPU的百分比第四行:内存状态totaltotaltotalphysicalmemoryfreetotalfreememoryusedtotalamountofmemoryinusebuff/cachecachedmemoryamount第五行:swapswappartitiontotal总计amountofswapareafree使用的空闲交换区总量使用的交换区总量availMem缓冲交换区总量第6行:每个进程(任务)的状态监控PID进程idUSER进程所有者PR进程优先级NI不错的价值。负值表示高优先级,正值表示低优先级VIRT进程使用的虚拟内存总量,单位为kb。VIRT=SWAP+RESRES进程使用的未换出的物理内存大小,单位kb。RES=CODE+DATASHR共享内存大小,单位kbS进程状态。D=不间断睡眠状态R=运行S=睡眠T=跟踪/停止Z=僵尸进程%CPU%自上次更新以来的CPU时间%MEM%进程使用的物理内存TIME+进程使用的总CPU时间,单位1/100secondCOMMAND进程名(命令名/命令行)监控java线程数:ps-eLfgrepjavawc-l监控网络客户端连接数:netstat-ngreptcpgrep监听端口wc-l