Change in vdsm[master]: virt: total rx/tx stats not send to engine

mmirecki at redhat.com mmirecki at redhat.com
Wed Jul 15 12:21:04 UTC 2015


Marcin Mirecki has uploaded a new change for review.

Change subject: virt: total rx/tx stats not send to engine
......................................................................

virt: total rx/tx stats not send to engine

The network interface statistics for vm interfaces
retrieved from libvirt were incorrectly parsed.
The parsing was changed to parse the format in which
the information is returned from libvirt

Change-Id: I702a80f19553372e01ba022afaa07d766258062f
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1227793
Signed-off-by: Marcin Mirecki <mmirecki at redhat.com>
---
M tests/vmTests.py
M vdsm/virt/vmstats.py
2 files changed, 53 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/43672/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index dfaa1bb..b2ede7c 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -1349,6 +1349,35 @@
             testvm._setUnresponsiveIfTimeout(stats, 1)  # any value < timeout
             self.assertEqual(stats['monitorResponse'], '-1')
 
+    def test_nic_sample(self):
+        sts = {'net.1.tx.drop': 0, 'net.3.tx.pkts': 7, 'net.1.rx.drop': 0,
+               'net.1.tx.pkts': 0, 'net.0.tx.bytes': 0, 'net.0.name': 'vnet3',
+               'net.1.rx.bytes': 0, 'net.2.tx.errs': 0, 'net.0.tx.pkts': 0,
+               'net.1.tx.errs': 0, 'net.2.tx.pkts': 0, 'net.1.rx.errs': 0,
+               'net.2.name': 'vnet5', 'net.0.rx.pkts': 0, 'net.3.tx.errs': 8,
+               'net.0.rx.drop': 0, 'net.3.tx.bytes': 9, 'net.2.rx.bytes': 0,
+               'net.2.rx.errs': 0, 'net.2.rx.pkts': 0, 'net.2.tx.drop': 0,
+               'net.1.rx.pkts': 0, 'net.3.rx.drop': 11, 'net.1.name': 'vnet4',
+               'net.1.tx.bytes': 0, 'net.3.rx.errs': 12, 'net.0.rx.errs': 0,
+               'net.0.tx.drop': 0, 'net.0.tx.errs': 0, 'net.3.name': 'vnet6',
+               'net.2.rx.drop': 0, 'net.0.rx.bytes': 0, 'vcpu.current': 1,
+               'net.3.tx.drop': 5, 'net.3.rx.bytes': 3, 'net.3.rx.pkts': 4,
+               'net.2.tx.bytes': 0}
+        result = vmstats.nic_sample(sts, 'vnet6')
+        self.assertEqual(result, {'rx.bytes': 3,
+                                  'rx.pkts': 4,
+                                  'rx.errs': 12,
+                                  'rx.drop': 11,
+                                  'tx.bytes': 9,
+                                  'tx.pkts': 7,
+                                  'tx.errs': 8,
+                                  'tx.drop': 5})
+
+        stats = {'net.0.name': 'vnet3', 'net.1.name': 'vnet4',
+                 'net.3.name': 'vnet6'}
+        result = vmstats.nic_sample(stats, 'no_such_name')
+        self.assertEqual(result, {})
+
 
 class TestLibVirtCallbacks(TestCaseBase):
     FAKE_ERROR = 'EFAKERROR'
diff --git a/vdsm/virt/vmstats.py b/vdsm/virt/vmstats.py
index 53a909f..804efb9 100644
--- a/vdsm/virt/vmstats.py
+++ b/vdsm/virt/vmstats.py
@@ -180,8 +180,8 @@
         if vm_nic.name.startswith('hostdev'):
             continue
 
-        first_nic = first_sample.get('net', {}).get(vm_nic.name, {})
-        last_nic = last_sample.get('net', {}).get(vm_nic.name, {})
+        first_nic = nic_sample(first_sample, vm_nic.name)
+        last_nic = nic_sample(last_sample, vm_nic.name)
         # may happen if nic is a new hot-plugged one
         if not first_nic or not last_nic:
             continue
@@ -190,6 +190,28 @@
             first_nic, last_nic, interval)
 
 
+def nic_sample(stats, vm_nic_name):
+    sample = {}
+    ifc_count = -1
+    while True:
+        ifc_count += 1
+        net_name_key = 'net.' + str(ifc_count) + '.name'
+        if net_name_key not in stats:
+            break
+        net_name = stats[net_name_key]
+        if vm_nic_name != net_name:
+            continue
+        sample['rx.bytes'] = stats['net.' + str(ifc_count) + '.rx.bytes']
+        sample['rx.pkts'] = stats['net.' + str(ifc_count) + '.rx.pkts']
+        sample['rx.errs'] = stats['net.' + str(ifc_count) + '.rx.errs']
+        sample['rx.drop'] = stats['net.' + str(ifc_count) + '.rx.drop']
+        sample['tx.bytes'] = stats['net.' + str(ifc_count) + '.tx.bytes']
+        sample['tx.pkts'] = stats['net.' + str(ifc_count) + '.tx.pkts']
+        sample['tx.errs'] = stats['net.' + str(ifc_count) + '.tx.errs']
+        sample['tx.drop'] = stats['net.' + str(ifc_count) + '.tx.drop']
+    return sample
+
+
 def disks(vm, stats, first_sample, last_sample, interval):
     if first_sample is None or last_sample is None:
         return


-- 
To view, visit https://gerrit.ovirt.org/43672
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I702a80f19553372e01ba022afaa07d766258062f
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Marcin Mirecki <mmirecki at redhat.com>


More information about the vdsm-patches mailing list