Francesco Romani has uploaded a new change for review.

Change subject: virt: sampling: extract disk rate calculation
......................................................................

virt: sampling: extract disk rate calculation

This is a preparation patch for the merge
of sampleDisk and sampleDiskLatency

Change-Id: I9623b1b4ecbbe4726b7642e91e3c45ef743d9dfe
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm/virt/vm.py
1 file changed, 15 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/51/29951/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 3fde1f7..4a3f629 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -515,15 +515,26 @@
                     dStats['lunGUID'] = vmDrive.GUID
                 if sInfo is not None:
                     # will be None if sampled during recovery
-                    dStats['readRate'] = (
-                        (eInfo[dName][1] - sInfo[dName][1]) / sampleInterval)
-                    dStats['writeRate'] = (
-                        (eInfo[dName][3] - sInfo[dName][3]) / sampleInterval)
+                    dStats.update(self._calcDiskRate(vmDrive, sInfo, eInfo,
+                                                     sampleInterval))
             except (AttributeError, KeyError, TypeError, ZeroDivisionError):
                 self._log.exception("Disk %s stats not available", dName)
 
             stats[dName] = dStats
 
+    def _calcDiskRate(self, vmDrive, sInfo, eInfo, sampleInterval):
+        try:
+            return {
+                'readRate': (
+                    (eInfo[vmDrive.name][1] - sInfo[vmDrive.name][1])
+                     / sampleInterval),
+                'writeRate': (
+                    (eInfo[vmDrive.name][3] - sInfo[vmDrive.name][3])
+                     / sampleInterval) }
+        except (AttributeError, KeyError, TypeError, ZeroDivisionError):
+            self._log.exception("Disk %s stats not available", vmDrive.name)
+            return { 'readRate': '0', 'writeRate': '0' }
+
     def _getDiskLatency(self, stats):
         sInfo, eInfo, sampleInterval = self.sampleDiskLatency.getStats()
 


-- 
To view, visit http://gerrit.ovirt.org/29951
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9623b1b4ecbbe4726b7642e91e3c45ef743d9dfe
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to