/home/www/work]# cat /proc/stat
cpu 91470110 1515303 13832985 1975547688 57093076 457452 0
cpu0 48348024 680662 5550500 986377548 28583984 417596 0
cpu1 43122086 834640 8282484 989170140 28509091 39856 0
intr 4229107630 2324183029 21 0 2 2 0 0 0 36387 0 0 0 3 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 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 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 1802215968 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 102672140 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 79 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 99239585008
btime 1230083813
processes 15607577
procs_running 1
procs_blocked 0
Above cpu value is made of sum betwen cpu1, cpu2. After booting, size of consumed jiffies is indicated.
First column is cpu number, second column is user, third filed is user in low priority (nice), fourth column is idle.
Therefore, It is possible to get cpu usage through those values.
cpu usage = (idle jiffies)*100 / (idle jiffies + use jiffies + system jiffies + low prio jiffies)
# CPU value
#cat /proc/stat | grep -e '^cpu ' | grep -v grep | awk '{print $0}' > cpudata
ncpuinfo=`cat /proc/stat | grep -e '^cpu ' | grep -v grep | awk '{print $0}'`
cpuinfo=(`echo $ncpuinfo | tr '.' ' '`)
total=`expr ${cpuinfo[1]} + ${cpuinfo[3]} + ${cpuinfo[4]}`
echo $total, ${cpuinfo[4]}
* Reference
/proc/stat in man proc
cpu 3357 0 4313 1362393
The number of jiffies (1/100ths of a second) that the system spent in user mode, user mode with low priority (nice), system mode, and the idle task, respectively. The last value should be 100 times the second entry in the uptime pseudo-file.
'c or linux' 카테고리의 다른 글
Introduction about web NTOP (0) | 2009.05.13 |
---|---|
Linux) deleting old files and directory. (0) | 2009.05.08 |
리눅스 메모리 많이 먹는 녀석 찾아내기 (0) | 2009.02.21 |
rsh timeout 옵션과 함께 동작시키기 (0) | 2009.02.04 |
리눅스 rsh 의 timeout 기능 (0) | 2009.02.04 |