You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Jeff Hair <je...@greenqloud.com> on 2014/05/08 16:59:23 UTC

GetHostStatsCommand on KVM/Libvirt inaccurate?

Watching the output of the GetHostStatsCommand shows that the CPU
utilization is almost always the same. This is because the
LibvirtComputingResource runs this script to calculate CPU Idle time:

idle=$(top -b -n 1|grep Cpu\(s\):|cut -d% -f4|cut -d, -f2);echo $idle

Then it subtracts that number from 100. Because top always returns the
average idle time since boot on its first run, this can lead to some rather
constant data. Was this an intended effect? Running top multiple times and
averaging the results but ignoring the first value will produce more
accurate data for the stats collector. For example:

top -b -n 5 -d 1 | grep Cpu
%Cpu(s): 17.9 us,  3.8 sy,  0.0 ni, 76.1 id,  2.1 wa,  0.0 hi,  0.0 si,
 0.0 st
%Cpu(s):  5.0 us,  3.0 sy,  0.0 ni, 92.1 id,  0.0 wa,  0.0 hi,  0.0 si,
 0.0 st
%Cpu(s):  8.7 us,  3.0 sy,  0.0 ni, 86.6 id,  1.7 wa,  0.0 hi,  0.0 si,
 0.0 st
%Cpu(s): 25.5 us,  1.5 sy,  0.0 ni, 73.0 id,  0.0 wa,  0.0 hi,  0.0 si,
 0.0 st
%Cpu(s):  7.0 us,  2.2 sy,  0.0 ni, 90.5 id,  0.2 wa,  0.0 hi,  0.0 si,
 0.0 st

If this is something useful for the LibvirtComputingResource, I can open a
Jira ticket and submit a patch.