1.vmstat
vmstat(Virtual Meomory Statistics(虛擬記憶體統計)的縮寫,很多linux、unix會預設安裝。是核心線程、虛擬記憶體、磁碟、陷阱和 CPU 活動的統計資訊,不足是無法對某個進程深入分析。
虛擬記憶體:
系統中啟動並執行進程都需要使用記憶體,當記憶體不足時,核心會釋放某些進程所佔用但未使用的部分或所有實體記憶體,將其移到磁碟上,並將釋放的記憶體提供給需要使用的進程。
文法:vmstat [ -f ] [ -i ] [ -s ] [ -I ] [ -t ] [ -v ] [ PhysicalVolume ... ] [ Interval [ Count ] ]
[root@db-331 ~]# vmstat help
usage: vmstat [-V] [-n] [delay [count]]
-V prints version. 版本資訊。
-n causes the headers not to be reprinted regularly. 輸出的頭部資訊僅顯示一次。
-a print inactive/active page stats.
列印待用/活躍 的頁狀態,預設不列印。
-d prints disk statistics 列印磁碟統計資訊。
-D prints disk table 列印磁碟總資訊,包括讀寫分區等。
-p prints disk partition statistics 列印磁碟分割統計。
-s prints vm table
-m prints slabinfo
-S unit size 單位大小。
delay is the delay between updates in seconds.
delay表示兩次輸出之間間隔時間。
unit size k:1000 K:1024 m:1000000 M:1048576 (default is K) 指定單位,參數有k,K,m,M分別代表1000、1024、1000000、1048576(byte),預設K(1024 bytes)
count is the number of updates. count表示統計的次數,預設1.
例如:
vmstat 3 5
表示每3秒更新一次輸出資訊,統計5次。
[root@db-331 ~]# 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 st
1 0 624 109784 338108 18696476 0 0 0 15 0 0 0 0 99 0 0
0 0 624 108796 338108 18697148 0 0 5 939 6693 6865 0 0 99 0 0
0 0 624 108764 338124 18697624 0 0 5 1036 6172 6325 0 0 99 0 0
0 0 624 109628 338124 18698132 0 0 0 733 5054 4822 0 0 99 0 0
0 0 624 109832 338124 18698420 0 0 11 725 5031 4875 0 0 100 0 0
Procs(進程):
r: 運行隊列中進程數量。當這個值長期超過了CPU數目,表示CPU有瓶頸
b: 等待IO的進程數量
Memory(預設單位K):
swpd: 正使用虛擬記憶體大小
free: 可用記憶體大小
buff: 用作緩衝的記憶體大小
cache: 用作緩衝的記憶體大小
Swap:
si: 每秒從交換區寫到記憶體的大小(由磁碟調入記憶體)
so: 每秒寫入交換區的記憶體大小(由記憶體調入磁碟)
IO:
bi: 每秒讀取的塊數
bo: 每秒寫入的塊數
system:
in: 每秒中斷數,包括時鐘中斷。
cs: 每秒環境切換數。
CPU(以百分比表示):
us: 使用者進程消耗的CPU時間百分比
sy: 系統進程消耗的CPU時間百分比
id: 空閑時間(包括IO等待時間)
wa: O等待消耗的CPU時間百分比