本文的內(nèi)容主要來自對(duì)Netflix的一篇技術(shù)博客(Linux Performance Analysis in 60,000 Milliseconds,并添加了一些自己的理解,僅供參考。
1. uptime
$uptime23:51:26up21:31,1user,loadaverage:30.02,26.43,19.0212
該命令可以大致的看出計(jì)算機(jī)的整體負(fù)載情況,load average后的數(shù)字分別表示計(jì)算機(jī)在1min、5min、15min內(nèi)的平均負(fù)載。
2. dmesg | tail
$dmesg|tail[1880957.563150]perlinvokedoom-killer:gfp_mask=0x280da,order=0,oom_score_adj=0[...][1880957.563400]Outofmemory:Killprocess18694(perl)score246orsacrificechild[1880957.563408]Killedprocess18694(perl)total-vm:1972392kB,anon-rss:1953348kB,file-rss:0kB[2320864.954447]TCP:PossibleSYNfloodingonport7001.Droppingrequest.CheckSNMPcounters.123456
打印內(nèi)核環(huán)形緩存區(qū)中的內(nèi)容,可以用來查看一些錯(cuò)誤;
上面的例子中,顯示進(jìn)程18694 因引內(nèi)存越界被kill掉以及TCP request被丟棄的錯(cuò)誤。通過dmesg可以快速判斷是否有導(dǎo)致系統(tǒng)性能異常的問題。
3. vmstat 1
$vmstat1procs---------memory-------------swap-------io-----system--------cpu-----rbswpdfreebuffcachesisobiboincsussyidwast3400200889792737085918280005610961300320020088992073708591860000592132844282981100320020089011273708591860000095012154991000320020088956873712591856000481190024599900003200200890208737125918600000158984840981100^C123456789
打印進(jìn)程、內(nèi)存、交換分區(qū)、IO和CPU等的統(tǒng)計(jì)信息;
vmstat的格式如下
>vmstat[options][delay[count]]
vmstat第一次輸出表示從開機(jī)到vmstat運(yùn)行時(shí)的平均值;剩余輸出的都是在指定的時(shí)間間隔內(nèi)的平均值,上述例子中delay的值設(shè)置為1,除第一次以外,剩余的都是1秒統(tǒng)計(jì)一次,count未設(shè)置,將會(huì)一直循環(huán)打印。
$vmstat103procs-----------memory-------------swap-------io-----system--------cpu-----rbswpdfreebuffcachesisobiboincsussyidwast1002527112108688813720228001142111990000025271561086888137198560001043003490100990000025264121086888137199040001033454870019900123456
上述的例子中delay設(shè)置為10,count設(shè)置為3,表示每行打印10秒內(nèi)的平均值,只打印3次。
需要檢查的列
r:表示正在運(yùn)行或者等待CPU調(diào)度的進(jìn)程數(shù)。因?yàn)樵摿袛?shù)據(jù)不包含I/O的統(tǒng)計(jì)信息,因此可以用來檢測(cè)CPU是否飽和。若r列中的數(shù)字大于CPU的核數(shù),表示CPU已經(jīng)處于飽和狀態(tài)。
free:當(dāng)前剩余的內(nèi)存;
si, so:交換分區(qū)換入和換出的個(gè)數(shù),若換入換出個(gè)數(shù)大于0,表示內(nèi)存不足;
us, sy, id, wa:CPU的統(tǒng)計(jì)信息,分別表示user time、system time(kernel)、idle、wait I/O。I/O處理所用的時(shí)間包含在system time中,因此若system time超過20%,則I/O可能存在瓶頸或異常;
4. mpstat -P ALL 1
$mpstat-PALLLinux3.10.0-229.el7.x86_64(localhost.localdomain)05/30/2018_x86_64_(16CPU)04:03:55PMCPU%usr%nice%sys%iowait%irq%soft%steal%guest%gnice%idle04:03:55PMall3.670.000.610.710.000.000.000.000.0095.0204:03:55PM03.520.000.570.760.000.000.000.000.0095.1504:03:55PM13.830.000.610.710.000.000.000.000.0094.8504:03:55PM23.800.000.610.600.000.000.000.000.0094.9904:03:55PM33.680.000.580.600.000.000.000.000.0095.1304:03:55PM43.540.000.570.600.000.000.000.000.0095.30[...]1234567891011
該命令用于每秒打印一次每個(gè)CPU的統(tǒng)計(jì)信息,可用于查看CPU的調(diào)度是否均勻。
5. pidstat 1
$pidstat1Linux3.13.0-49-generic(titanclusters-xxxxx)07/14/2015_x86_64_(32CPU)07:41:02PMUIDPID%usr%system%guest%CPUCPUCommand07:41:03PM090.000.940.000.941rcuos/007:41:03PM042145.665.660.0011.3215mesos-slave07:41:03PM043540.940.940.001.898java07:41:03PM065211596.231.890.001598.1127java07:41:03PM065641571.707.550.001579.2528java07:41:03PM60004601540.944.720.005.669pidstat07:41:03PMUIDPID%usr%system%guest%CPUCPUCommand07:41:04PM042146.002.000.008.0015mesos-slave07:41:04PM065211590.001.000.001591.0027java07:41:04PM065641573.0010.000.001583.0028java07:41:04PM10867181.000.000.001.000snmp-pass07:41:04PM60004601541.004.000.005.009pidstat^C123456789101112131415161718
該命令用于打印各個(gè)進(jìn)程對(duì)CPU的占用情況,類似top命令中顯示的內(nèi)容。pidstat的優(yōu)勢(shì)在于,可以滾動(dòng)的打印進(jìn)程運(yùn)行情況,而不像top那樣會(huì)清屏。
上述例子中,%CPU中兩個(gè)java進(jìn)程的cpu利用率分別達(dá)到了1590%和1573%,表示java進(jìn)程占用了16顆CPU。
6. iostat -xz 1
類似vmstat,第一次輸出的是從系統(tǒng)開機(jī)到統(tǒng)計(jì)這段時(shí)間的采樣數(shù)據(jù);
$iostat-xz1Linux3.13.0-49-generic(titanclusters-xxxxx)07/14/2015_x86_64_(32CPU)avg-cpu:%user%nice%system%iowait%steal%idle73.960.003.730.030.0622.21Device:rrqm/swrqm/sr/sw/srkB/swkB/savgrq-szavgqu-szawaitr_awaitw_awaitsvctm%utilxvda0.000.230.210.184.522.0834.370.009.9813.805.422.440.09xvdb0.010.001.028.94127.97598.53145.790.000.431.780.280.250.25xvdc0.010.001.028.86127.79595.94146.500.000.451.820.300.270.26dm-00.000.000.692.3210.4731.6928.010.013.230.713.980.130.04dm-10.000.000.000.940.013.788.000.33345.840.04346.810.010.00dm-20.000.000.090.071.350.3622.500.002.550.235.621.780.03[...]^C123456789101112131415
檢查列
r/s, w/s, rkB/s, wkB/s,表示每秒向I/O設(shè)備發(fā)出的reads、writes、read Kbytes、write Kbytes的數(shù)量。
await,表示應(yīng)用程序排隊(duì)等待和被服務(wù)的平均I/O時(shí)間,該值若大于預(yù)期的時(shí)間,這表示I/O設(shè)備處于飽和狀態(tài)或者異常。
avgqu-sz,表示請(qǐng)求被發(fā)送給I/O設(shè)備的平均時(shí)間,若該值大于1,則表示I/O設(shè)備可能已經(jīng)飽和;
%util,每秒設(shè)備的利用率;若該利用率超過60%,則表示設(shè)備出現(xiàn)性能異常;
7. free -m
$free-mtotalusedfreesharedbufferscachedMem:245998245452214538359541-/+buffers/cache:23944222053Swap:00012345
檢查的列:
buffers: For the buffer cache, used for block device I/O.
cached: For the page cache, used by file systems.
若buffers和cached接近0,說明I/O的使用率過高,系統(tǒng)存在性能問題。Linux中會(huì)用free內(nèi)存作為cache,若應(yīng)用程序需要分配內(nèi)存,系統(tǒng)能夠快速的將cache占用的內(nèi)存回收,因此free的內(nèi)存包含cache占用的部分。
8. sar -n DEV 1
sar是System Activity Reporter的縮寫,系統(tǒng)活動(dòng)狀態(tài)報(bào)告。
-n { keyword [,…] | ALL },用于報(bào)告網(wǎng)絡(luò)統(tǒng)計(jì)數(shù)據(jù)。keyword可以是以下的一個(gè)或者多個(gè): DEV, EDEV, NFS, NFSD, SOCK, IP, EIP, ICMP, EICMP, TCP, ETCP, UDP, SOCK6, IP6, EIP6, ICMP6, EICMP6 和UDP6。
-n DEV 1, 每秒統(tǒng)計(jì)一次網(wǎng)絡(luò)的使用情況;-n EDEV 1,每秒統(tǒng)計(jì)一次錯(cuò)誤的網(wǎng)絡(luò)信息;
$sar-nDEV1Linux3.10.0-229.el7.x86_64(localhost.localdomain)05/31/2018_x86_64_(16CPU)03:54:57PMIFACErxpck/stxpck/srxkB/stxkB/srxcmp/stxcmp/srxmcst/s03:54:58PMens323286.007207.00283.3418333.900.000.000.0003:54:58PMlo0.000.000.000.000.000.000.0003:54:58PMvethe915e510.000.000.000.000.000.000.0003:54:58PMdocker00.000.000.000.000.000.000.0003:54:58PMIFACErxpck/stxpck/srxkB/stxkB/srxcmp/stxcmp/srxmcst/s03:54:59PMens323304.007362.00276.8918898.510.000.000.0003:54:59PMlo0.000.000.000.000.000.000.0003:54:59PMvethe915e510.000.000.000.000.000.000.0003:54:59PMdocker00.000.000.000.000.000.000.00^C123456789101112131415
IFACE ,網(wǎng)絡(luò)接口名稱;
rxpck/s ,每秒接收到包數(shù);
txpck/s ,每秒傳輸?shù)膱?bào)數(shù);(transmit packages)
rxkB/s ,每秒接收的千字節(jié)數(shù);
txkB/s ,每秒發(fā)送的千字節(jié)數(shù);
rxcmp/s ,每秒接收的壓縮包的數(shù)量;
txcmp/s ,每秒發(fā)送的壓縮包的數(shù)量;
rxmcst/s,每秒接收的組數(shù)據(jù)包數(shù)量;
9. sar -n TCP,ETCP 1
該命令可以用于粗略的判斷網(wǎng)絡(luò)的吞吐量,如發(fā)起的網(wǎng)絡(luò)連接數(shù)量和接收的網(wǎng)絡(luò)連接數(shù)量;
TCP, 報(bào)告關(guān)于TCPv4網(wǎng)絡(luò)流量的統(tǒng)計(jì)信息;
ETCP, 報(bào)告有關(guān)TCPv4網(wǎng)絡(luò)錯(cuò)誤的統(tǒng)計(jì)信息;
$sar-nTCP,ETCP1Linux3.10.0-514.26.2.el7.x86_64(aushop)05/31/2018_x86_64_(2CPU)04:16:27PMactive/spassive/siseg/soseg/s04:16:44PM0.002.0015.0013.0004:16:45PM0.003.00126.00203.0004:16:46PM0.000.0099.0099.0004:16:47PM0.000.0018.009.0004:16:48PM0.000.005.006.0004:16:49PM0.000.001.001.0004:16:50PM0.001.004.004.0004:16:51PM0.003.00171.00243.00^C12345678910111213
檢測(cè)的列:
active/s: Number of locally-initiated TCP connections per second (e.g., via connect()),發(fā)起的網(wǎng)絡(luò)連接數(shù)量;
passive/s: Number of remotely-initiated TCP connections per second (e.g., via accept()),接收的網(wǎng)絡(luò)連接數(shù)量;
retrans/s: Number of TCP retransmits per second,重傳的數(shù)量;
10. top
top命令包含更多的指標(biāo)統(tǒng)計(jì),相當(dāng)于一個(gè)綜合命令。
$toptop-00:15:40up21:56,1user,loadaverage:31.09,29.87,29.92Tasks:871total,1running,868sleeping,0stopped,2zombie%Cpu(s):96.8us,0.4sy,0.0ni,2.7id,0.1wa,0.0hi,0.0si,0.0stKiBMem:25190241+total,24921688used,22698073+free,60448buffersKiBSwap:0total,0used,0free.554208cachedMemPIDUSERPRNIVIRTRESSHRS%CPU%MEMTIME+COMMAND20248root2000.227t0.012t18748S30905.229812:58java4213root20027225446464044232S23.50.0233:35.37mesos-slave66128titancl+2002434423321172R1.00.00:00.07top5235root20038.227g54700449996S0.70.22:02.74java4299root20020.015g2.682g16836S0.31.133:14.42java1root2003362029201496S0.00.00:03.82init2root200000S0.00.00:00.02kthreadd3root200000S0.00.00:05.35ksoftirqd/05root0-20000S0.00.00:00.00kworker/0:0H6root200000S0.00.00:06.94kworker/u256:08root200000S0.00.02:38.05rcu_sched12345678910111213141516171819
11. 總結(jié)
下面的圖片很好的展示了各個(gè)命令的主要作用,如使用vmstat查看系統(tǒng)的整體性能,mpstat用于查看cpu的性能,pidstat用于查看進(jìn)程的狀態(tài),iostat用于查看io的狀態(tài),free用于產(chǎn)看內(nèi)存的狀態(tài),sar用于產(chǎn)看網(wǎng)絡(luò)的狀態(tài)等。
image.png
Linux常用性能工具一覽
Linux Performance Tools
-
cpu
+關(guān)注
關(guān)注
68文章
10829瀏覽量
211194 -
Linux
+關(guān)注
關(guān)注
87文章
11232瀏覽量
208957
原文標(biāo)題:Linux性能檢測(cè)常用的10個(gè)基本命令
文章出處:【微信號(hào):magedu-Linux,微信公眾號(hào):馬哥Linux運(yùn)維】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論