mpstat是MultiProcessor Statistics的縮寫,是實時系統監控工具。其報告與CPU的一些統計信息,這些信息存放在/proc/stat文件中。在多CPUs系統裡,其不但能查看所有CPU的平均狀況信息,而且能夠查看特定CPU的信息。下面只介紹mpstat與CPU相關的參數,mpstat的語法如下:
mpstat [-P {|ALL}] [internal [count]]
參數的含義如下:
參數 解釋
-P {|ALL} 表示監控哪個CPU, cpu在[0,cpu個數-1]中取值
internal 相鄰的兩次采樣的間隔時間
count 采樣的次數,count只能和delay一起使用
當沒有參數時,mpstat則顯示系統啟動以後所有信息的平均值。有interval時,第一行的信息自系統啟動以來的平均信息。
從第二行開始,輸出為前一個interval時間段的平均信息。與CPU有關的輸出的含義如下:
參數 解釋 從/proc/stat獲得數據
CPU 處理器ID
user 在internal時間段裡,用戶態的CPU時間(%),不包含 nice值為負 進程 (usr/total)*100
nice 在internal時間段裡,nice值為負進程的CPU時間(%) (nice/total)*100
system 在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
intr/s 在internal時間段裡,每秒CPU接收的中斷的次數intr/total)*100
CPU總的工作時間=total_cur=user+system+nice+idle+iowait+irq+softirq
total_pre=pre_user+ pre_system+ pre_nice+ pre_idle+ pre_iowait+ pre_irq+ pre_softirq
user=user_cur – user_pre
total=total_cur-total_pre
其中_cur 表示當前值,_pre表示interval時間前的值。上表中的所有值可取到兩位小數點。
范例1:average mode (粗略信息)
當mpstat不帶參數時,輸出為從系統啟動以來的平均值。
CODE:
[work@builder linux-2.6.14]$ mpstat
Linux 2.6.9-5.31AXsmp (builder.redflag-linux.com) 12/16/2005
09:38:46 AM CPU %user %nice %system %iowait %irq %soft %idle intr/s
09:38:48 AM all 23.28 0.00 1.75 0.50 0.00 0.00 74.47 1018.59
范例2: 每2秒產生了2個處理器的統計數據報告
下面的命令可以每2秒產生了2個處理器的統計數據報告,一共產生三個interval 的信息,然後再給出這三個interval的平
均信息。默認時,輸出是按照CPU 號排序。第一個行給出了從系統引導以來的所有活躍數據。接下來每行對應一個處理器的
活躍狀態。。
CODE:
[root@server yum_dir]# mpstat -P ALL 2 3
Linux 2.6.18-164.el5 (server.sys.com) 01/04/2010
09:34:20 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
09:34:22 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1001.49
09:34:22 PM 0 0.00 0.00 0.50 0.00 0.00 0.00 0.00 99.50 1001.00
09:34:22 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 0.00
09:34:22 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
09:34:24 PM all 0.00 0.00 0.25 0.00 0.00 0.00 0.00 99.75 1005.00
09:34:24 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1005.50
09:34:24 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 0.00
09:34:24 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
09:34:26 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1001.49
09:34:26 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1001.00
09:34:26 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 0.00
Average: CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
Average: all 0.00 0.00 0.08 0.00 0.00 0.00 0.00 99.92 1002.66
Average: 0 0.00 0.00 0.17 0.00 0.00 0.00 0.00 99.83 1002.49
Average: 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 0.00
[root@server yum_dir]#