★★★★☆數據庫
vmstat 是 Virtual Memory Statistics ( 虛擬內存統計 ) 的縮寫,利用 vmstat 命令能夠對操做系統的內存信息、進程狀態和 CPU 活動等進行監視。可是隻能對系統的總體狀況進行統計,沒法對某個進程進行深刻分析。緩存
vmstat [option] [delay [count]]
vmstat [選項] [時間間隔 [次數]]
說明:服務器
1. 在 iftop 命令後面的每個選項裏,每一個元素之間都至少要有一個空格。
2. delay 表示兩次輸出之間的間隔時間。
3. count 表示按照 delay指定的時間間隔統計的次數。app
-a :顯示活躍和非活躍的內存 -f :顯示從系統啓動至今的 fork 進程數量 -m :顯示 slab 信息 -n :只在開始時顯示一次各字段名稱 -s :顯示內存相關統計信息及多種系統活動數量 ※ -d :顯示磁盤相關統計信息 -p :顯示指定磁盤分區統計信息 -S :使用指定單位顯示。參數有 k、K、m、M,分別表明 1000、1024、1 000 000、1 048 576 字節( byte )。默認單位爲 K ( 1024 byte ) -t :統計信息帶上時間戳
[root@localhost :~]# vmstat # 若是省略 "時間間隔" 和 "次數" 的參數,則僅顯示一次報告後就退出 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 8 76980 164 766248 0 0 9 16 28 24 0 0 100 0 0 [root@localhost :~]# vmstat 5 # 表示每5秒鐘更新一次輸出信息,循環輸出,按 Ctrl+C 組合鍵中止輸出 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 8 71008 164 772624 0 0 8 15 28 24 0 0 100 0 0 0 0 8 70984 164 772624 0 0 0 0 43 37 0 0 100 0 0 0 0 8 70984 164 772624 0 0 0 0 49 41 0 0 100 0 0 0 0 8 70984 164 772624 0 0 0 0 65 53 0 0 100 0 0 ^C [root@localhost :~]# vmstat 5 6 # 表示每5秒鐘更新一次輸出信息,統計6次後中止輸出 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 264 74236 0 767936 0 0 8 15 28 24 0 0 100 0 0 0 0 264 71064 0 770868 0 0 0 0 442 250 0 3 97 0 0 1 0 264 68244 0 773912 0 0 0 0 435 242 0 3 97 0 0 0 0 264 65012 0 776968 0 0 0 3638 458 237 0 4 96 0 0 0 0 264 63932 0 779476 0 0 0 6 362 208 0 3 97 0 0 0 0 264 63932 0 779476 0 0 0 0 83 76 0 0 100 0 0
[root@localhost :~]#
如下是命令結果的詳細說明:函數
第一列:procs: 1. r 列:the number of processes waiting for run time. 表示運行和等待 CPU 時間片的進程數。( 若是等待運行的進程數越多,意味着CPU很是繁忙。另外,若是該參數長期大於和等於邏輯cpu個數,則CPU資源可能存在較大的瓶頸。 ) 2. b 列:the number of processes in uninterruptible sleep. 表示處在非中斷睡眠狀態的進程數。( 意味着進程被阻塞。主要是指被資源阻塞的進程對列數(好比IO資源、頁面調度等),當這個值較大時,須要根據應用程序來進行分析,好比數據庫產品,中間件應用等。 )
第二列:memory: 1. swpd 列:the amount of virtual memory used. 表示使用虛擬內存的大小。若是虛擬內存使用較多,可能系統的物理內存比較吃緊,須要採起合適的方式來減小物理內存的使用。swapd 不爲0,並不意味物理內存吃緊,若是 swapd 沒變化,si、so 的值長期爲0,這也是沒有問題的
2. free 列:the amount of idle memory. 表示當前空閒的物理內存數量。 3. buff 列:the amount of memory used as buffers. 表示 buffers 的內存數量 ( 主要用於塊設備緩存,單位:KB )。 4. cache 列:the amount of memory used as cache. 表示 cache 的內存數量 ( 主要用於緩存文件,單位:KB )。 5. inact 列:the amount of inactive memory. (-a option) 表示非活躍的內存總量。 6. active: the amount of active memory. (-a option) 表示活躍的內存總量。
第三列:swap: 1. si( swap in )列:Amount of memory swapped in from disk (/s). 表示由磁盤交換到 swap 虛擬內存的交換頁數量,單位:KB/秒。也就是內存進入內存交換區的數量。若是這個值大於0,表示物理內存不夠用或者內存泄露了 2. so( swap out )列:Amount of memory swapped to disk (/s). 表示由 swap 虛擬內存交換到磁盤的交換頁數量,單位:KB/秒,若是這個值大於0,表示物理內存不夠用或者內存泄露了
3. 內存夠用的時候,這2個值都是0,若是這2個值長期大於0時,系統性能會受到影響,磁盤IO和CPU資源都會被消耗。 當看到空閒內存(free)不多的或接近於0時,就認爲內存不夠用了,這個是不正確的。不能光看這一點,還要結合si和so,若是 free 不多,可是 si 和 so 也不多(大多時候是0),那麼不用擔憂,系統性能這時不會受到影響的。 當內存的需求大於RAM的數量,服務器啓動了虛擬內存機制,經過虛擬內存,能夠將 RAM 段移到 SWAP DISK 的特殊磁盤段上,
這樣會出現虛擬內存的頁導出和頁導入現象,頁導出並不能說明RAM瓶頸,虛擬內存系統常常會對內存段進行頁導出,但頁導入操做就代表了服務器須要更多的內存了, 頁導入須要從SWAP DISK上將內存段複製回RAM,致使服務器速度變慢。
第四列:I/O項顯示磁盤讀寫情況: 1. bi 列:Blocks received from a block device (blocks/s). 表示從塊設備讀入的數據總量 ( 即讀磁盤,單位:塊/s )。 2. bo 列:Blocks sent to a block device (blocks/s). 表示寫入塊設備的數據總量 ( 即寫磁盤,單位:塊/s )。
第五列:system 顯示採集間隔內發生的中斷數: 1. in 列:the number of interrupts per second, including the clock. 表示在某一時間間隔中觀測到的每秒設備中斷數,包括時鐘中斷。 2. cs 列:the number of context switches per second. 每秒產生的上下文 ( 環境 ) 切換次數。好比咱們調用系統函數,就要進行上下文切換,而過多的上下文切換會浪費較多的 CPU 資源,這個數值應該越小越好。
第六列:CPU 項顯示了 CPU 的使用狀態: 1. us 列:time spent running non-kernel code. (user time, including nice time) 表示用戶消耗的 CPU 時間 ( 非內核進程佔用時間 )(單位爲百分比)。us 的值比較高時,說明用戶進程消耗的 CPU 時間多 2. sy 列:time spent running kernel code. (system time). 表示系統( 內核 )使用的 CPU 時間 ( 單位爲百分比 )。sy 的值高時,說明系統內核消耗的 CPU 資源多,這並非良性表現,咱們應該檢查緣由。 3. id 列:time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. 空閒的 CPU 的時間( 百分比 ),在 Linux 2.5.41 以前,這部分包含 IO 等待時間。 4. wa 列:time spent waiting for IO. Prior to Linux 2.5.41, shown as zero. 表示等待 IO 的 CPU 時間,在 Linux 2.5.41 以前,這個值爲0 .這個指標意味着 CPU 在等待硬盤讀寫操做的時間,用百分比表示。wait 越大則機器 IO 性能就越差。說明 IO 等待比較嚴重,這可能因爲磁盤大量做隨機訪問形成,也有可能磁盤出現瓶頸 ( 塊操做 )。 5. st 列:time stolen from a virtual machine. Prior to Linux 2.6.11, unknown. 表示虛擬機佔用的 CPU 時間的百分比。
[root@localhost :~]# vmstat -s 997948 K total memory 154556 K used memory 410924 K active memory 325044 K inactive memory 82296 K free memory 0 K buffer memory 761096 K swap cache 2097148 K total swap 520 K used swap 2096628 K free swap 3732 non-nice user cpu ticks 42 nice user cpu ticks 7159 system cpu ticks 4269971 idle cpu ticks 401 IO-wait cpu ticks 0 IRQ cpu ticks 281 softirq cpu ticks 0 stolen cpu ticks 280652 pages paged in 559486 pages paged out 0 pages swapped in 20 pages swapped out 1200688 interrupts 1037152 CPU context switches 1545624768 boot time 2803 forks
說明:這些信息分別來自於 /proc/meminfo、/proc/stat 和 /proc/vmstat 文件中性能
[root@localhost :~]# vmstat -d disk- ------------reads------------ ------------writes----------- -----IO------ total merged sectors ms total merged sectors ms cur sec sda 8291 47 561305 16707 4169 563 1118979 30026 0 12 sr0 0 0 0 0 0 0 0 0 0 0 dm-0 7114 0 540703 16390 4702 0 1114683 38429 0 11 dm-1 94 0 4456 29 20 0 160 201 0 0 [root@localhost :~]#
說明:這些信息主要來自於 /proc/diskstats。其中的 merged 表示一次來自於合併的寫/讀請求,系統通常會把多個鏈接/臨近的讀/寫請求合併到一塊兒來操做。this
[root@localhost :~]# vmstat -p /dev/sda1 sda1 reads read sectors writes requested writes 966 11322 10 4136 [root@localhost :~]#
說明:這些信息主要來自於 /proc/diskstats。各列的說明具體以下:spa
1. reads :來自於該分區的讀的次數。 2. read sectors :來自於該分區的讀扇區的次數。
3. writes :來自於該分區的寫的次數。 4. requested writes :來自於該分區的寫請求次數