Laszlo Hornyak has uploaded a new change for review.
Change subject: report cpuUser and cpuSys separately (#800367)
......................................................................
report cpuUser and cpuSys separately (#800367)
Uses virDomainGetCPUStats to get the CPU information instead of info()
The content of the exported 'cpuSys' and 'cpuUser' changes:
- cpuSys is the sum of system_time and user_time reported by libvirt
since none of these include the guest time
- cpuUser is the time consumed only by the guest VM without the
system_time and the user_time
Change-Id: I663ad25ff3ff5ce426b5159b6c9a65b7f5167605
Bug-Url:
https://bugzilla.redhat.com/800367
Signed-off-by: Laszlo Hornyak <lhornyak(a)redhat.com>
---
M vdsm/libvirtvm.py
1 file changed, 20 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/33/8633/1
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
index 1b45cb2..6ab0756 100644
--- a/vdsm/libvirtvm.py
+++ b/vdsm/libvirtvm.py
@@ -106,8 +106,8 @@
vmDrive.apparentsize = int(volSize['apparentsize'])
def _sampleCpu(self):
- state, maxMem, memory, nrVirtCpu, cpuTime = self._vm._dom.info()
- return cpuTime / 1000**3
+ cpuStats = self._vm._dom.getCPUStats(True, 0)
+ return cpuStats[0]
def _sampleDisk(self):
if not self._vm._volumesPrepared:
@@ -179,17 +179,32 @@
netSamples[nic.name] = self._vm._dom.interfaceStats(nic.name)
return netSamples
+ def _diff(self, prev, curr, val):
+ return prev[val] - curr[val]
+
+ def _usagePercentage(self, val, sampleInterval):
+ return 100 * val / sampleInterval / 1000 ** 3
+
def _getCpuStats(self, stats):
- stats['cpuSys'] = 0.0
sInfo, eInfo, sampleInterval = self.sampleCpu.getStats()
try:
- stats['cpuUser'] = 100.0 * (eInfo - sInfo) / sampleInterval
+ stats['cpuSys'] = self._usagePercentage(
+ self._diff(eInfo, sInfo, 'user_time')
+ + self._diff(eInfo, sInfo, 'system_time'),
+ sampleInterval)
+ stats['cpuUser'] = self._usagePercentage(
+ self._diff(eInfo, sInfo, 'cpu_time')
+ - self._diff(eInfo, sInfo, 'user_time')
+ - self._diff(eInfo, sInfo, 'system_time'),
+ sampleInterval)
except (TypeError, ZeroDivisionError):
self._log.debug("CPU stats not available")
stats['cpuUser'] = 0.0
+ stats['cpuSys'] = 0.0
- stats['cpuIdle'] = max(0.0, 100.0 - stats['cpuUser'])
+ stats['cpuIdle'] = max(0.0,
+ 100.0 - (stats['cpuUser'] + stats['cpuSys']))
def _getNetworkStats(self, stats):
stats['network'] = {}
--
To view, visit
http://gerrit.ovirt.org/8633
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I663ad25ff3ff5ce426b5159b6c9a65b7f5167605
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.1
Gerrit-Owner: Laszlo Hornyak <lhornyak(a)redhat.com>