vmstat :報告處理器、內存、頁、塊io、cpu活動信息
vmstat [-a] [-n] [-S unit] [delay [ count]]
vmstat [-s] [-n] [-S unit]
vmstat [-m] [-n] [delay [ count]]
vmstat [-d] [-n] [delay [ count]]
vmstat [-p disk partition] [-n] [delay [ count]]
vmstat [-f]
vmstat [-V]
-a:顯示活動和非活動內存
-f:顯示系統從啓動到現在的fork次數。
-m:顯示slab信息。
-d:顯示磁盤信息
[root@netnic ~]# vmstat 1
procs --------memory------- --swap-- ---io--- --system-- -----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 6128 3006 3485 1391 0 0 3 81 18 8 3 2 95 0 0
0 0 6128 3005 3485 1391 0 0 0 0 2295 11 2 2 97 0 0
0 0 6128 3005 3485 1391 0 0 0 0 2327 10 1 1 98 0 0
0 0 6128 3005 3485 1391 0 0 0 0 2194 6 1 1 99 0 0
0 0 6128 3005 3485 1391 0 0 28 0 1808 5 1 1 98 0 0
0 0 6128 3005 3485 1391 0 0 0 28 1760 6 1 0 98 0 0
Procs
r: The number of processes waiting for run time.
等待運行的進程數
b: The number of processes in uninterruptible sleep.
處於不可中斷狀態的睡眠進程數,常見的情況是由IO引起的,正常情況下爲0比較好。
【注】當r值超過服務器上cpu的數量,就可能存在cpu瓶頸,有一些任務就要等待執行。當業
務繁忙的時候,不超過2倍cpu數量,還是可以認爲合理的。
Memory
swpd: the amount of virtual memory used.
使用的虛擬內存數量
free: the amount of idle memory.
空閒的物理內存
buff: the amount of memory used as buffers.
作爲buffer cache的內存,對塊設備的讀寫進行緩衝
cache: the amount of memory used as cache.
作爲page cache的內存, 文件系統的cache
inact: the amount of inactive memory. (-a option)
非活動內存數量
active: the amount of active memory. (-a option)
活動內存數量
【注】swpd 的值比較大,但是 si, so 的值長期爲 0,這種情況我們可以不用擔心,不會影響
系統性能;如果 cache 的值很大,說明cache住的文件數很多。如果頻繁訪問到的文件都能被
cache住,那麼磁盤的讀IO bi會非常小。
【注1】buffer和cache的區別
buffer : 也叫塊緩衝,是根據磁盤的讀寫設計的,把分散的操作集中進行,減少磁盤碎片和硬
盤的反覆尋道,從而提高系統性能。
cache: 作爲page cache的內存, 是把讀取過的數據保存起來,重新讀取時若命中(找到需要的
數據)就不要去讀硬盤了,若沒有命中就讀硬盤。
Swap
si: Amount of memory swapped in from disk (/s).
交換內存使用,由磁盤調入內存的數量
so: Amount of memory swapped to disk (/s).
交換內存使用,由內存調入磁盤
【注】當內存短缺時,會導致虛擬內存頁頻繁導出和導入,頁導出並不能說明RAM瓶頸,虛擬內存
系統經常會對內存段進行頁導出,但頁導入操作就表明了服務器需要更多的內存了, 頁導入需要
從SWAP DISK上將內存段複製回RAM,導致服務器速度變慢,所以si值高時,有可能是內存短缺
問題造成。
【注2】paging和swap的區別
頁面調度paging:是將內存中最近不常使用的頁面換到磁盤上,把常使用的頁面(活動頁面)保留
在內存中供進程使用。
交換(swap):是系統將整個進程,而不是部分頁面,全部換到磁盤上。
IO
bi: Blocks received from a block device (blocks/s).
從塊設備讀入的數據塊數(讀磁盤)
bo: Blocks sent to a block device (blocks/s).
寫入到塊設備的數據塊(寫磁盤)
【注】磁盤寫的數據量稍大,如果是大文件的寫,10M以內基本不用擔心,如果是小文件寫2M
以內基本正常
System
in: The number of interrupts per second, including the clock.
每秒產生的中斷次數,包括時鐘中斷
cs: The number of context switches per second.
每秒產生的上下文切換次數
【注】上面這2個值越大,會看到由內核消耗的CPU時間會越多
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
非內核進程消耗的CPU時間百分比
sy: Time spent running kernel code. (system time)
內核進程消耗的CPU時間百分比
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
cpu處於空閒狀態的時間百分比
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
IO等待消耗的CPU時間百分比
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
被虛擬處理器專用的時間
【注】us 的值比較高時,說明用戶進程消耗的CPU時間多,但是如果長期超過50% 的
使用,那麼我們就該考慮優化,如果idle經常爲0,或者cpu sy是cpu us兩倍,那麼系
統可能面臨cpu資源短缺。sy 的值高時,說明系統內核消耗的CPU資源多,這並不是良
性的表現,我們應該檢查原因。
wa 的值高時,說明IO等待比較嚴重,這可能是由於磁盤大量作隨機訪問造成,也有可能
是磁盤的帶寬出現瓶頸(塊操作)。數字越大,表示文件系統活動阻礙cpu的情況越嚴重,
因爲cpu在等待慢速的磁盤系統提供數據。wa爲0是最理想的。如果wa經常大於10,可
能文件系統就需要進行性能調整了。