Dan Kenigsberg has uploaded a new change for review.
Change subject: HostStats: stop storing list of host ifids and speeds
......................................................................
HostStats: stop storing list of host ifids and speeds
Current code keeps an almost-up-to-date list of host interface names as
a data member of the HostStatsThread. This information is redundant,
since host ifids are already available in HostSample.interfaces.
With the list of ifids, this patch removes a list of their respective
speed. Each speed is stored, instead with its respective
InterfaceSample.
Change-Id: Iad0605c910564a8a7072484301c51b4b8a325751
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M vdsm/virt/sampling.py
1 file changed, 29 insertions(+), 29 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/70/29470/1
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 4ef9890..841f2f2 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -100,7 +100,20 @@
return '0'
return 'up' if flags & ethtool.IFF_RUNNING else 'down'
- def __init__(self, ifid):
+ @staticmethod
+ def _getLinkSpeed(dev):
+ if dev.isNIC():
+ speed = netinfo.nicSpeed(dev.name)
+ elif dev.isBOND():
+ speed = netinfo.bondSpeed(dev.name)
+ elif dev.isVLAN():
+ speed = netinfo.vlanSpeed(dev.name)
+ else:
+ speed = 0
+ return speed
+
+ def __init__(self, link):
+ ifid = link.name
self.rx = self.readIfaceStat(ifid, 'rx_bytes')
self.tx = self.readIfaceStat(ifid, 'tx_bytes')
self.rxDropped = self.readIfaceStat(ifid, 'rx_dropped')
@@ -108,6 +121,7 @@
self.rxErrors = self.readIfaceStat(ifid, 'rx_errors')
self.txErrors = self.readIfaceStat(ifid, 'tx_errors')
self.operstate = self.readIfaceOperstate(ifid)
+ self.speed = self._getLinkSpeed(link)
class TotalCpuSample:
@@ -192,11 +206,11 @@
"""
A sample of the statistics for a process.
"""
- def __init__(self, pid, ifids):
+ def __init__(self, pid, links):
TimedSample.__init__(self)
self.interfaces = {}
- for ifid in ifids:
- self.interfaces[ifid] = InterfaceSample(ifid)
+ for link in links:
+ self.interfaces[link.name] = InterfaceSample(link)
self.pidcpu = PidCpuSample(pid)
@@ -241,16 +255,17 @@
d[p] = {'free': str(free)}
return d
- def __init__(self, pid, ifids):
+ def __init__(self, pid):
"""
Initialize a HostSample.
:param pid: The PID of this vdsm host.
:type pid: int
- :param ifids: The IDs of the interfaces you want to sample.
- :type: list
"""
- BaseSample.__init__(self, pid, ifids)
+ TimedSample.__init__(self)
+ self.interfaces = dict(
+ (link.name, InterfaceSample(link)) for link in getLinks())
+ self.pidcpu = PidCpuSample(pid)
self.totcpu = TotalCpuSample()
meminfo = utils.readMemInfo()
freeOrCached = (meminfo['MemFree'] +
@@ -449,7 +464,6 @@
self._log = log
self._stopEvent = threading.Event()
self._samples = []
- self._updateIfidsIfrates()
self._lastSampleTime = time.time()
self._pid = os.getpid()
@@ -458,24 +472,8 @@
def stop(self):
self._stopEvent.set()
- def _updateIfidsIfrates(self):
- devices = getLinks()
- self._ifids = [dev.name for dev in devices]
- self._ifrates = []
- for dev in devices:
- if dev.isNIC():
- speed = netinfo.nicSpeed(dev.name)
- elif dev.isBOND():
- speed = netinfo.bondSpeed(dev.name)
- elif dev.isVLAN():
- speed = netinfo.vlanSpeed(dev.name)
- else:
- speed = 0
- self._ifrates.append(speed)
-
def sample(self):
- self._updateIfidsIfrates()
- hs = HostSample(self._pid, self._ifids)
+ hs = HostSample(self._pid, getLinks())
return hs
def run(self):
@@ -593,12 +591,13 @@
rx = tx = rxDropped = txDropped = 0
stats['network'] = {}
- for ifid, ifrate in zip(self._ifids, self._ifrates):
+ total_rate = 0
+ for ifid in hs1.interfaces.keys():
# it skips hot-plugged devices if we haven't enough information
# to count stats from it
if ifid not in hs0.interfaces:
continue
- ifrate = ifrate or 1000
+ ifrate = hs1.interfaces[ifid].speed or 1000
Mbps2Bps = (10 ** 6) / 8
thisRx = (hs1.interfaces[ifid].rx - hs0.interfaces[ifid].rx) % \
(2 ** 32)
@@ -629,8 +628,9 @@
tx += thisTx
rxDropped += hs1.interfaces[ifid].rxDropped
txDropped += hs1.interfaces[ifid].txDropped
+ total_rate += ifrate
- total_bytes_per_sec = (sum(self._ifrates) or 1000) * (10 ** 6) / 8
+ total_bytes_per_sec = (total_rate or 1000) * (10 ** 6) / 8
stats['rxRate'] = 100.0 * rx / interval / total_bytes_per_sec
stats['txRate'] = 100.0 * tx / interval / total_bytes_per_sec
if stats['txRate'] > 100 or stats['rxRate'] > 100:
--
To view, visit
http://gerrit.ovirt.org/29470
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad0605c910564a8a7072484301c51b4b8a325751
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>