Linux CPU實時監控命令mpstat介紹

hxw2ljj發表於2015-10-30
1,簡介
       mpstat是Multiprocessor  Statistics的縮寫,是實時系統監控工具。其報告是CPU的一些統計資訊,這些資訊存放在/proc/stat檔案中。在多CPUs系統裡,其不但能檢視所有CPU的平均狀況資訊,而且能夠檢視特定CPU的資訊。mpstat最大的特點是:可以檢視多核心cpu中每個計算核心的統計資料;而類似工具vmstat只能檢視系統整體cpu情況。

2,安裝
[root@ora10g ~]# mpstat
-bash: mpstat: command not found
[root@ora10g ~]# mount -o loop -t iso9660 /dev/cdrom /mnt/cdrom
[root@ora10g ~]# cd /mnt/cdrom/Server/
[root@ora10g Server]# rpm -ivh sysstat-7.0.2-3.el5.i386.rpm 
warning: sysstat-7.0.2-3.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
   1:sysstat                ########################################### [100%]

3,例項
用法
 mpstat -V  顯示mpstat版本資訊
 mpstat -P ALL 顯示所有CPU資訊
 mpstat -P n 顯示第n個cup資訊,n為數字,計數從0開始 
 mpstat n m  每個n秒顯示一次cpu資訊,連續顯示m次,最後顯示一個平均值
 mpstat n    每個n秒顯示一次cpu資訊,連續顯示下去
 
檢視每個cpu核心的詳細當前執行狀況資訊,輸出如下:   
 [root@ora10g ~]# mpstat -P ALL
Linux 2.6.18-194.el5 (ora10g.up.com)    11/05/14
09:13:02     CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
09:13:02     all    0.62    0.01    0.54    3.48    0.00    0.02    0.00   95.32   1039.58
09:13:02       0    0.92    0.01    1.18    8.77    0.01    0.05    0.00   89.06   1030.23
09:13:02       1    0.27    0.00    0.31    1.46    0.00    0.01    0.00   97.96      1.00
....
09:13:02      14    1.12    0.02    0.45    2.99    0.00    0.01    0.00   95.39      7.74
09:13:02      15    0.18    0.00    0.22    0.70    0.00    0.01    0.00   98.90      0.59

檢視多核CPU核心的當前執行狀況資訊, 每2秒更新一次
[root@ora10g ~]# mpstat -P ALL 2

檢視某個cpu的使用情況,數值在[0,cpu個數-1]中取值
[root@ora10g ~]# mpstat -P 2
Linux 2.6.18-194.el5 (ora10g.up.com)    11/05/14
10:19:28     CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
10:19:28       2    0.08    0.00    0.04    0.22    0.00    0.01    0.00   99.64      0.55

檢視多核CPU核心的當前執行狀況資訊, 每2秒更新一次,顯示5次
[root@ora10g ~]# mpstat -P ALL 2 5

4,欄位含義如下
英文解釋:
CPU:Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
%user:Show the percentage of CPU utilization that occurred while executing at the user level (application).
%nice:Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
%sys:Show  the  percentage  of CPU utilization that occurred while executing at the system level (kernel). Note that
              this does not include time spent servicing interrupts or softirqs.
%iowait:Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk  I/O request.
%irq:Show the percentage of time spent by the CPU or CPUs to service interrupts.
%soft:Show  the  percentage  of time spent by the CPU or CPUs to service softirqs.  A softirq (software interrupt) is
              one of up to 32 enumerated software interrupts which can run on multiple CPUs at once.
%steal:Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was  ser-vicing another virtual processor.
%idle:Show  the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
intr/s:Show the total number of interrupts received per second by the CPU or CPUs.

引數解釋 從/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時間前的值。上表中的所有值可取到兩位小數點。
   

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18796236/viewspace-1818780/,如需轉載,請註明出處,否則將追究法律責任。

相關文章