Change in vdsm[master]: net stats: expose sample timestamp

danken at redhat.com danken at redhat.com
Tue Dec 30 16:44:26 UTC 2014


Dan Kenigsberg has uploaded a new change for review.

Change subject: net stats: expose sample timestamp
......................................................................

net stats: expose sample timestamp

Change-Id: I8e996cc1dcdf8f8223e83e36092949e4951c5d1d
Signed-off-by: Dan Kenigsberg <danken at redhat.com>
---
M tests/functional/networkTests.py
M tests/vmTests.py
M vdsm/rpc/vdsmapi-schema.json
M vdsm/virt/sampling.py
M vdsm/virt/vm.py
5 files changed, 25 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/83/36483/1

diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 1a557a6..482fd0f 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -428,14 +428,16 @@
             self.assertIn(
                 left, hostStats['network'], 'couldn''t find veth')
 
-        def getTxStatsFromInterface(iface):
+        def getStatsFromInterface(iface):
             status, msg, hostStats = self.vdsm_net.getVdsStats()
             self.assertEqual(status, SUCCESS, msg)
             self.assertIn('network', hostStats)
             self.assertIn(iface, hostStats['network'])
             self.assertIn('tx', hostStats['network'][iface])
             self.assertIn('rx', hostStats['network'][iface])
-            return int(hostStats['network'][iface]['tx'])
+            self.assertIn('sampleTime', hostStats['network'][iface])
+            return (int(hostStats['network'][iface]['tx']),
+                    hostStats['network'][iface]['sampleTime'])
 
         with vethIf() as (left, right):
             # disabling IPv6 on Interface for removal of Router Solicitation
@@ -446,7 +448,7 @@
             # Vdsm scans for new devices every 15 seconds
             self.retryAssert(
                 assertTestDevStatsReported, timeout=20)
-            prevTxStat = getTxStatsFromInterface(left)
+            prevTxStat, prevTime = getStatsFromInterface(left)
             # running ARP from the interface
             rc, out, err = execCmd([_ARPPING_COMMAND.cmd, '-D', '-I', left,
                                     '-c', '1', IP_ADDRESS_IN_NETWORK])
@@ -454,7 +456,10 @@
                 raise SkipTest('Could not run sysctl command', out, err)
             # Sleep 2 seconds for the statistics to be updated
             time.sleep(2)
-            curTxStat = getTxStatsFromInterface(left)
+            curTxStat, curTime = getStatsFromInterface(left)
+            self.assertTrue(
+                curTime > prevTime,
+                'sampleTime is not monotonically invreasing')
             diff = (curTxStat - prevTxStat)
             self.assertTrue(ARP_REQUEST_SIZE <= diff
                             <= (ARP_REQUEST_SIZE + DHCP_PACKET_SIZE),
diff --git a/tests/vmTests.py b/tests/vmTests.py
index 41fe8d0..a24ee81 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -1480,11 +1480,17 @@
         MAC = '52:54:00:59:F5:3F'
         with fake.VM() as testvm:
             mock_stats_thread = vm.VmStatsThread(testvm)
+            pretime = utils.monotonic_time()
             res = mock_stats_thread._getNicStats(
                 name='vnettest', model='virtio', mac=MAC,
                 start_sample=(2 ** 64 - 15 * GBPS, 1, 2, 3, 0, 4, 5, 6),
                 end_sample=(0, 7, 8, 9, 5 * GBPS, 10, 11, 12),
                 interval=15.0)
+            posttime = utils.monotonic_time()
+            self.assertIn('sampleTime', res)
+            self.assertTrue(pretime <= res['sampleTime'] <= posttime,
+                            'sampleTime not in [%s..%s]' % (pretime, posttime))
+            del res['sampleTime']
             self.assertEqual(res, {
                 'rxErrors': '8', 'rxDropped': '9',
                 'txErrors': '11', 'txDropped': '12',
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index e1849e1..b20b2d6 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -1706,6 +1706,8 @@
 #
 # @tx:         The number of outgoing bytes in total (new in version 4.17)
 #
+# @sampleTime: Time stamp of the sample (new in version 4.17)
+#
 # @macAddr:    The hardware address
 #
 # Since: 4.10.0
@@ -1714,7 +1716,8 @@
  'data': {'name': 'str', 'speed': 'uint', 'rxDropped': 'uint',
           'txDropped': 'uint', 'rxErrors': 'uint', 'txErrors': 'uint',
           'state': 'NetworkInterfaceState', 'rxRate': 'float',
-          'txRate': 'float', 'rx': 'uint', 'tx': 'uint', 'macAddr': 'str'}}
+          'txRate': 'float', 'rx': 'uint', 'tx': 'uint', 'sampleTime': 'float',
+          'macAddr': 'str'}}
 ##
 # @HostNetworkInterfaceStats:
 #
@@ -1742,13 +1745,16 @@
 #
 # @tx:         The number of outgoing bytes in total (new in version 4.17)
 #
+# @sampleTime: Time stamp of the sample (new in version 4.17)
+#
 # Since: 4.11.1
 ##
 {'type': 'HostNetworkInterfaceStats',
  'data': {'name': 'str', 'speed': 'uint', 'rxDropped': 'uint',
           'txDropped': 'uint', 'rxErrors': 'uint', 'txErrors': 'uint',
           'state': 'NetworkInterfaceState', 'rxRate': 'float',
-          'txRate': 'float', 'rx': 'uint', 'tx': 'uint'}}
+          'txRate': 'float', 'rx': 'uint', 'tx': 'uint', 'sampleTime': 'float',
+         }}
 
 ##
 # @StorageDomainVitals:
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 86071c6..73943df 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -692,6 +692,7 @@
                                       'txRate': '%.1f' % txRate,
                                       'rx': str(iface.rx),
                                       'tx': str(iface.tx),
+                                      'sampleTime': hs1.timestamp,
                                       }
             rx += thisRx
             tx += thisTx
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 767f9b9..8fa7872 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -599,6 +599,7 @@
 
         ifStats['rx'] = str(end_sample[0])
         ifStats['tx'] = str(end_sample[4])
+        ifStats['sampleTime'] = utils.monotonic_time()
 
         return ifStats
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e996cc1dcdf8f8223e83e36092949e4951c5d1d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>


More information about the vdsm-patches mailing list