/proc/stat 的解释

  • Post author:
  • Post category:其他




/proc/stat 的解释


关于linux 系统/proc/stat的解释和应用。

这段perl代码,可以提供计算cpu利用率数据采集






[~]$ cat /proc/stat

cpu 432661 13295 86656 422145968 171474 233 5346

cpu0 123075 2462 23494 105543694 16586 0 4615

cpu1 111917 4124 23858 105503820 69697 123 371

cpu2 103164 3554 21530 105521167 64032 106 334

cpu3 94504 3153 17772 105577285 21158 4 24

intr 1065711094 1057275779 92 0 6 6 0 4 0 3527 0 0 0 70 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

ctxt 19067887

btime 1139187531

processes 270014

procs_running 1

procs_blocked 0

输出解释

CPU 以及CPU0、CPU1、CPU2、CPU3每行的每个参数意思(以第一行为例)为:

参数 解释

user (432661) 从系统启动开始累计到当前时刻,用户态的CPU时间(单位:jiffies) ,不包含 nice值为负进程。1jiffies=0.01秒

nice (13295) 从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间(单位:jiffies)

system (86656) 从系统启动开始累计到当前时刻,核心时间(单位:jiffies)

idle (422145968) 从系统启动开始累计到当前时刻,除硬盘IO等待时间以外其它等待时间(单位:jiffies)

iowait (171474) 从系统启动开始累计到当前时刻,硬盘IO等待时间(单位:jiffies) ,

irq (233) 从系统启动开始累计到当前时刻,硬中断时间(单位:jiffies)

softirq (5346) 从系统启动开始累计到当前时刻,软中断时间(单位:jiffies)

CPU时间=user+system+nice+idle+iowait+irq+softirq

“intr”这行给出中断的信息,第一个为自系统启动以来,发生的所有的中断的次数;然后每个数对应一个特定的中断自系统启动以来所发生的次数。

“ctxt”给出了自系统启动以来CPU发生的上下文交换的次数。

“btime”给出了从系统启动到现在为止的时间,单位为秒。

“processes (total_forks) 自系统启动以来所创建的任务的个数目。

“procs_running”:当前运行队列的任务的数目。

“procs_blocked”:当前被阻塞的任务的数目。




sub

cpu_jiffies

{




my


%


data


;



my


@


line


;



open


(

FILE

,


"/proc/stat"


)


;



while


(


<

FILE

>


)


{




if


(


/


^

cpu/s

+


/


)


{




@


line


=


split


(


/


/

s

+


/


,


$


_


)


;



}


elsif


(


/


^

ctxt/s

+


/


)


{




$


data


{



'ctxt'


}


=


(


split


(


/


/

s

+


/


,


$


_


)


)


[

1

]


;



}


else


{




next


;



}



}



close


(

FILE

)


;



(


$


data


{



'user'


}


,


$


data


{



'sys'


}


,


$


data


{



'idle'


}


)


=


@


line


[

1

,

3

,

4

]


;



shift


@


line


;



$


data


{



'total'


}


+


=


$


_


foreach


@


line


;



return


%


data


;



}