Basic CPU information on Linux is obtained by reading the contents of the /proc/cpuinfo file.CPU details are obtained by reading the cpuXX lines from the /proc/stat file. The line contains a series of numbers - each line is a count of "jiffies" (a Linux unit of time measurement) which the CPU has spent in a particular state.
The /proc/cpuinfo file on Linux typically contains the following:
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Xeon(TM) CPU 3.00GHz
stepping : 3
cpu MHz : 3000.318
cache size : 0 KB
physical id : 0
siblings : 2
runqueue : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm lm
bogomips : 5989.99
CPU details are obtained by reading the cpuXX lines from the /proc/stat file. The line contains a series of numbers - each line is a count of "jiffies" (a Linux unit of time measurement) which the CPU has spent in a particular state. The exact format of this line is explained in the proc man-page, but should typically be counts for user, nice, kernel and wait times. These values are computed in the same way as on Sun Solaris above. Example file contents below:
cpu 377563827 1856477 81976835 998905574 101938732 943582 6953644
cpu0 194469698 890983 41542972 492819246 50337773 853201 4155498
cpu1 183094129 965494 40433863 506086328 51600959 90381 2798146
page 1487566273 1201634999
swap 55817271 96002355
intr 2852649243 786972470 6 0 0 18 0 5 0 1 0 0 0 357 0 2 0 1555781021 0 0 0 etc...
disk_io: (8,0):(520495216,355445940,2975131100,165049276,2403269978)
ctxt 3800176685
btime 1224148159
processes 90981644
procs_running 1
procs_blocked 1
The average CPU utilisation is calculated by the Linux kernel and stored in this file: /proc/stat. The first line beginning with just "cpu" is the average cpu ticks. The most likely reason why you are seeing this discrepancy is because of rounding. You are adding up values from the dataview that are only 2 decimal places, internally the netprobe stores a more detailed number. This extra information is being thrown away when you add up from the dataview. You will be able to verify these figures if you turn on the debug: LINUXCPU, subdebug setting: getCpuInfo (NOTE: This debug ONLY applies to the cpu plug-in).
So how do we compute for the average_cpu?
The formula for working out the average_cpu requires at least 2 samples. The difference of each of the cpu tick values is taken, see example below.
NOTE: this example is done using Linux kernel 2.4, older kernels can have less values in the /proc/stat file e.g. only user, nice, system and idle. Newer kernels may have more.
|
user |
nice |
system |
idle |
iowait |
irq |
softirq |
Total |
Sample 1 |
517279608 |
2456777 |
114166256 |
1210376547 |
78005118 |
1451214 |
12423956 |
1936159476 |
Sample 2 |
517310190 |
2456896 |
114173270 |
1210439776 |
78009008 |
1451367 |
12424766 |
1936265273 |
Difference |
30582 |
119 |
7014 |
63229 |
3890 |
153 |
810 |
105797 |
To calculate the average now, it is 100 - ( ( idle / total ) * 100 ), so in our example this would be 100 - ( ( 63229 / 105797 ) * 100 ) = 59.76 %
So how do we compute for the percentWaitTime of a logical CPU?
The formula is:
((current Wait - previous Wait) / (current Total - previous Total) * 100
To get the above values, the plugin's debug setting LINUXCPU > getCpuInfo needs to be enabled on the Netprobe Debug tab. Below is a screenshot of the said setting:
Once enabled, the Netprobe log will be populated by the following log entries:
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo cpu2:[ 7899915 22332 1924028 463503822 545843 1897 402339 0 ]
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo pLinuxCpu:0x25ebb10 pPrevLinuxCpu:0x2aaac806aa40
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Total:963 = nTotal:474300176 - pPrevLinuxCpu->nTotal:474299213
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo User:37 = nCurrUser:7899915 - pPrevLinuxCpu->nUser:7899878
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo System:7 = nCurrSystem:1924028 - pPrevLinuxCpu->nSystem:1924021
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Idle:919 = nCurrIdle:463503822 - pPrevLinuxCpu->nIdle:463502903
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Wait:0 = nCurrWait:545843 - pPrevLinuxCpu->nWait:545843
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Irq:0 = nCurrIrq:1897 - pPrevLinuxCpu->nIrq:1897
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Irq:0 = nCurrSoftIrq:402339 - pPrevLinuxCpu->nSoftIrq:402339
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo cpu3:[ 9623095 30717 2419741 460882081 531216 6636 860409 0 ]
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo pLinuxCpu:0x253eb90 pPrevLinuxCpu:0x2aaac806ad80
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Total:962 = nTotal:474353895 - pPrevLinuxCpu->nTotal:474352933
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo User:23 = nCurrUser:9623095 - pPrevLinuxCpu->nUser:9623072
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo System:6 = nCurrSystem:2419741 - pPrevLinuxCpu->nSystem:2419735
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Idle:927 = nCurrIdle:460882081 - pPrevLinuxCpu->nIdle:460881154
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Wait:1 = nCurrWait:531216 - pPrevLinuxCpu->nWait:531215
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Irq:0 = nCurrIrq:6636 - pPrevLinuxCpu->nIrq:6636
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Irq:5 = nCurrSoftIrq:860409 - pPrevLinuxCpu->nSoftIrq:860404
Using the said formula and data, to get the percentWaitTime of cpu_1_logical#3 (value is 0.10%):
1. Extract the data related to the chosen logical CPU:
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo cpu3:[ 9623095 30717 2419741 460882081 531216 6636 860409 0 ]
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo pLinuxCpu:0x253eb90 pPrevLinuxCpu:0x2aaac806ad80
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Total:962 = nTotal:474353895 - pPrevLinuxCpu->nTotal:474352933
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo User:23 = nCurrUser:9623095 - pPrevLinuxCpu->nUser:9623072
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo System:6 = nCurrSystem:2419741 - pPrevLinuxCpu->nSystem:2419735
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Idle:927 = nCurrIdle:460882081 - pPrevLinuxCpu->nIdle:460881154
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Wait:1 = nCurrWait:531216 - pPrevLinuxCpu->nWait:531215
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Irq:0 = nCurrIrq:6636 - pPrevLinuxCpu->nIrq:6636
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Irq:5 = nCurrSoftIrq:860409 - pPrevLinuxCpu->nSoftIrq:860404
2. Extract the Wait data:
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Wait:1 = nCurrWait:531216 - pPrevLinuxCpu->nWait:531215
3. Extract the Total data:
<Tue Dec 20 21:30:39> DEBUG: LINUXCPU:getCpuInfo Total:962 = nTotal:474353895 - pPrevLinuxCpu->nTotal:474352933
4. Compute:
((current Wait - previous Wait) / (current Total - previous Total) * 100)
N = ((531216 - 531215) / (474353895 - 474352933) * 100)
N = ((1 / 962) * 100)
N = 0.103950103950104 %
N = 0.10 %
Comments
0 comments
Please sign in to leave a comment.