簡介
mpstat是Multiprocessor Statistics的縮寫,是即時系統監控工具。其報告與CPU的一些統計資訊,這些資訊存放在/proc/stat檔案中。在多CPUs系統裡,其不但能查看所有CPU的平均狀況資訊,而且能夠查看特定CPU的資訊。mpstat最大的特點是:可以查看多核心cpu中每個計算核心的統計資料;而類似工具vmstat只能查看系統整體cpu情況。
文法
mpstat [-P {|ALL}] [internal [count]]參數 解釋-P {|ALL} 表示監控哪個CPU, cpu在[0,cpu個數-1]中取值internal 相鄰的兩次採樣的間隔時間、count 採樣的次數,count只能和delay一起使用當沒有參數時,mpstat則顯示系統啟動以後所有資訊的平均值。有interval時,第一行的資訊自系統啟動以來的平均資訊。從第二行開始,輸出為前一個interval時間段的平均資訊。
執行個體
查看多核CPU核心的當前健全狀態資訊, 每2秒更新一次
mpstat 219:45:12 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle19:45:14 all 0.04 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.9619:45:16 all 0.00 0.00 0.00 0.03 0.00 0.00 0.00 0.00 99.9719:45:18 all 0.00 0.07 0.07 0.00 0.00 0.00 0.00 0.00 99.87
如果要看每個cpu核心的詳細當前健全狀態資訊,輸出如下:
mpstat -P ALL 219:43:58 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle19:43:59 all 0.00 0.00 0.04 0.00 0.00 0.00 0.00 0.00 99.9619:43:59 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.0019:43:59 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00.......19:43:59 13 0.99 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.0119:43:59 14 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.0019:43:59 15 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
欄位的含義如下
%user 在internal時間段裡,使用者態的CPU時間(%),不包含nice值為負進程 (usr/total)*100%nice 在internal時間段裡,nice值為負進程的CPU時間(%) (nice/total)*100%sys 在internal時間段裡,核心程式的時間(%) (system/total)*100%iowait 在internal時間段裡,硬碟IO等待時間(%) (iowait/total)*100%irq 在internal時間段裡,硬停機時間(%) (irq/total)*100%soft 在internal時間段裡,非強制中斷時間(%) (softirq/total)*100%idle 在internal時間段裡,CPU除去等待磁碟IO操作外的因為任何原因而閒置時間閑置時間(%) (idle/total)*100
計算公式如下
total_cur=user+system+nice+idle+iowait+irq+softirqtotal_pre=pre_user+ pre_system+ pre_nice+ pre_idle+ pre_iowait+ pre_irq+ pre_softirquser=user_cur – user_pretotal=total_cur-total_pre其中_cur 表示當前值,_pre表示interval時間前的值。上表中的所有值可取到兩位小數點。
轉自 http://www.cnblogs.com/stephen-liu74/archive/2011/12/05/2257887.html