天天看點

Linux CPU實時監控指令mpstat介紹

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

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

最新内容請見作者的github頁:http://qaseven.github.io/

繼續閱讀