【裸奔吧linux】vmstat:一個系統監控工具,常用於性能分析

一. ubuntu14.04的man vmstat 描述:

NAME
       vmstat - Report virtual memory statistics(報告虛擬內存統計信息)
SYNOPSIS
       vmstat [options] [delay [count]]

二. 常用法:
1). vmstat [delay] [count]
例如:vmstat 2 2表示監測間隔爲2s, 監測次數爲2次.
2). vmstat [delay]
例如:vmstat 2 表示間隔2s, 一直監測到結束vmstat.
輸出格式爲:
vmstat 2 4

三. 各個輸出項解釋:
Procs
r: The number of runnable processes (running or waiting for run time).
 可運行進程的數目(正在運行或等待運行)[也就是在就緒隊列和運行隊列中的進程?]
 當這個值超過了CPU數目,就會出現CPU瓶頸了。
b: The number of processes in uninterruptible sleep.
 處於"不可中斷睡眠狀態"的進程數目.
 [可中斷睡眠:可以用信號喚醒]
 [不可中斷睡眠:不接受外來信號(異步信號).一般由IO引起,同步IO在做讀或寫操作時,cpu不能做其它事情,只能等待,這時進程處於這種狀態,如果程序採用異步IO,這種狀態應該很少見]

Memory
swpd: the amount of virtual memory used.
   以使用的虛擬內存.
free: the amount of idle memory.
   空閒的物理內存[注意是物理內存].
buff: the amount of memory used as buffers.
   被當做緩衝區的物理內存.
cache: the amount of memory used as cache.
   被當做高速緩衝區的物理內存
inact: the amount of inactive memory. (-a option)
   非活動的內存(-a選項)
active: the amount of active memory. (-a option)
   活動的內存(-a選項)
Swap
si: Amount of memory swapped in from disk (/s).
   每秒從磁盤讀入虛擬內存的大小,如果這個值大於0,表示物理內存不夠用或者內存泄露了.
so: Amount of memory swapped to disk (/s).
   每秒虛擬內存寫入磁盤的大小,如果這個值大於0,表示物理內存不夠用或者內存泄露了.
IO
bi: Blocks received from a block device (blocks/s).
   每秒從塊設備接收到的塊數量(讀塊設備),這裏的塊設備是指系統上所有的磁盤和其他塊設備,默認塊大小是1024byte.
bo: Blocks sent to a block device (blocks/s).
   每秒向塊設備發送的塊數量(寫塊設備),例如讀取文件,bo就要大於0。bi和bo一般都要接近0,不然就是IO過於頻繁,需要調整.
System
in: The number of interrupts per second, including the clock.
   每秒鐘中斷次數,包括時鐘中斷.
cs: The number of context switches per second.
   每秒上下文切換次數,例如我們調用系統函數,就要進行上下文切換,線程的切換,也要進程上下文切換,這個值要越小越好.上下文切換會影響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時間.(在linux 2.5.41之前包括IO等待時間.)
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
   等待IO的時間.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

補充:

R (TASK_RUNNING),可執行狀態。
S (TASK_INTERRUPTIBLE),可中斷的睡眠狀態。
D (TASK_UNINTERRUPTIBLE),不可中斷的睡眠狀態。
  一般由IO引起,同步IO在做讀或寫操作時,cpu不能做其它事情,只能等待,這時進程處於這種狀態,如果程序採用異步IO,這種狀態應該很少見.
T (TASK_STOPPED or TASK_TRACED),暫停狀態或跟蹤狀態。
Z (TASK_DEAD – EXIT_ZOMBIE),退出狀態,進程成爲殭屍進程。
X (TASK_DEAD – EXIT_DEAD),退出狀態,進程即將被銷燬。

O:進程正在處理器運行.
I:空閒狀態(idle)
B:進程正在等待更多的內存頁

四.vmstat的選項

       -a, --active
              Display active and  inactive memory, given a 2.5.41 kernel or better.
       -f, --forks
             The -f switch displays the number of forks since boot.  This includes the fork, vfork, and clone system calls, 
             and is equivalent to  the total  number  of  tasks  created.   Each process is represented by one or more tasks,
             depending on thread usage.  This display does not repeat.
       -m, --slabs
              Displays slabinfo.
       -n, --one-header
              Display the header only once rather than periodically.
       -s, --stats
              Displays a table of various event counters and memory statistics.  This display does not repeat.
       -d, --disk
              Report disk statistics (2.5.70 or above required).
       -D, --disk-sum
              Report some summary statistics about disk activity.
       -p, --partition device
              Detailed statistics about partition (2.5.70 or above required).
       -S, --unit character
              Switches outputs between 1000 (k), 1024 (K), 1000000 (m), or 1048576 (M) bytes.  
              Note this does not change the  swap  (si/so)  or  block(bi/bo) fields.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章