Change in vdsm[master]: sampling: remove HostStatsThread.get()
fromani at redhat.com
fromani at redhat.com
Mon Jun 8 10:17:12 UTC 2015
Francesco Romani has uploaded a new change for review.
Change subject: sampling: remove HostStatsThread.get()
......................................................................
sampling: remove HostStatsThread.get()
Remove the get() operation of HostStatsThread,
decouple sample storage and stats production,
Change-Id: I80d919b0adb48a40d41f387543f14be265610405
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/samplingTests.py
M vdsm/API.py
M vdsm/clientIF.py
M vdsm/virt/sampling.py
4 files changed, 22 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/36/42036/1
diff --git a/tests/samplingTests.py b/tests/samplingTests.py
index ab85834..0b0bd2b 100644
--- a/tests/samplingTests.py
+++ b/tests/samplingTests.py
@@ -262,11 +262,13 @@
'rxRate': 0.0,
'txRate': 0.0,
}
- self._hs = sampling.HostStatsThread(self.log)
- self.assertEquals(self._hs.get(), expected)
+ self.assertEquals(hoststats.produce(None, None), expected)
def testSamplesWraparound(self):
- NUM = sampling.HostStatsThread.AVERAGING_WINDOW + 1
+ NUM = sampling.HOST_STATS_AVERAGING_WINDOW + 1
+
+ samples = sampling.SampleWindow(
+ sampling.HOST_STATS_AVERAGING_WINDOW)
class FakeEvent(object):
def __init__(self, *args):
@@ -299,16 +301,16 @@
pass
with MonkeyPatchScope([(sampling, 'HostSample', FakeHostSample)]):
- self._hs = sampling.HostStatsThread(self.log)
+ self._hs = sampling.HostStatsThread(self.log, samples)
self._hs._sampleInterval = 0
# we cannot monkey patch, it will interfer on threading internals
self._hs._stopEvent = FakeEvent()
self._hs.start()
self._hs.join()
- first, last, _ = self._hs._samples.stats()
+ first, last, _ = samples.stats()
self.assertEqual(first.id,
FakeHostSample.counter -
- sampling.HostStatsThread.AVERAGING_WINDOW)
+ sampling.HOST_STATS_AVERAGING_WINDOW)
self.assertEqual(last.id,
FakeHostSample.counter - 1)
diff --git a/vdsm/API.py b/vdsm/API.py
index 397f87e..e05a939 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -43,6 +43,8 @@
import storage.volume
import storage.sd
import storage.image
+from virt import hoststats
+from virt import sampling
from virt import vmstatus
from virt.vmdevices import graphics
from virt.vmdevices import hwclass
@@ -1318,7 +1320,8 @@
hooks.before_get_stats()
stats = {}
decStats = {'elapsedTime': self._cif.elapsed_time}
- decStats.update(self._cif._hostStats.get())
+ first_sample, last_sample, _ = sampling.host_samples.stats()
+ decStats.update(hoststats.produce(first_sample, last_sample))
if self._cif.irs:
decStats['storageDomains'] = self._cif.irs.repoStats()
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index c8ef6f6..6cd5e7f 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -94,7 +94,8 @@
self.gluster = None
try:
self.vmContainer = {}
- self._hostStats = sampling.HostStatsThread(log=log)
+ self._hostStats = sampling.HostStatsThread(
+ log, sampling.host_samples)
self._hostStats.start()
self._startTime = time.time()
self.lastRemoteAccess = 0
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 401bae9..40cb3ee 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -37,7 +37,6 @@
from vdsm.config import config
from .utils import ExpiringCache
-from . import hoststats
import caps
@@ -524,19 +523,24 @@
return doms
+HOST_STATS_AVERAGING_WINDOW = 5
+
+
+host_samples = SampleWindow(size=HOST_STATS_AVERAGING_WINDOW)
+
+
class HostStatsThread(threading.Thread):
"""
A thread that periodically samples host statistics.
"""
- AVERAGING_WINDOW = 5
_CONNLOG = logging.getLogger('connectivity')
- def __init__(self, log):
+ def __init__(self, log, samples):
threading.Thread.__init__(self)
self.daemon = True
self._log = log
self._stopEvent = threading.Event()
- self._samples = SampleWindow(size=self.AVERAGING_WINDOW)
+ self._samples = samples
self._pid = os.getpid()
self._ncpus = max(os.sysconf('SC_NPROCESSORS_ONLN'), 1)
@@ -569,10 +573,6 @@
except:
if not self._stopEvent.isSet():
self._log.exception("Error while sampling stats")
-
- def get(self):
- first_sample, last_sample, _ = self._samples.stats()
- return hoststats.produce(first_sample, last_sample)
def _getLinkSpeed(dev):
--
To view, visit https://gerrit.ovirt.org/42036
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I80d919b0adb48a40d41f387543f14be265610405
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list