def test_state(self): with namedTemporaryDir() as src: # A list of 3 file names, where the files are temporary. sizes = [os.path.basename(f.name) for f in [ tempfile.NamedTemporaryFile( dir=src, delete=False ) for _ in range(3) ]] with mock.patch('{}.open'.format(hugepages.__name__), mock.mock_open(read_data='1234'), create=True): self.assertEqual(len(hugepages.state(src)), len(sizes)) for value in hugepages.state(src).values(): self.assertEqual(value, _STATE)
def test_state(self): with namedTemporaryDir() as src: # A list of 3 file names, where the files are temporary. sizes = [os.path.basename(f.name) for f in [ tempfile.NamedTemporaryFile( dir=src, delete=False ) for _ in range(3) ]] with mock.patch('{}.open'.format(hugepages.__name__), mock.mock_open(read_data='1234'), create=True): self.assertEqual(len(hugepages.state(src)), len(sizes)) for value in hugepages.state(src).values(): self.assertEqual(value, _STATE)
def __init__(self, pid): """ Initialize a HostSample. :param pid: The PID of this vdsm host. :type pid: int """ self.timestamp = time.time() self.pidcpu = PidCpuSample(pid) self.ncpus = os.sysconf('SC_NPROCESSORS_ONLN') self.totcpu = TotalCpuSample() meminfo = utils.readMemInfo() freeOrCached = (meminfo['MemFree'] + meminfo['Cached'] + meminfo['Buffers']) self.memUsed = 100 - int(100.0 * (freeOrCached) / meminfo['MemTotal']) self.anonHugePages = meminfo.get('AnonHugePages', 0) // KiB try: with open('/proc/loadavg') as loadavg: self.cpuLoad = loadavg.read().split()[1] except: self.cpuLoad = '0.0' self.diskStats = self._getDiskStats() try: with open(_THP_STATE_PATH) as f: s = f.read() self.thpState = s[s.index('[') + 1:s.index(']')] except: self.thpState = 'never' self.hugepages = hugepages.state() self.cpuCores = CpuCoreSample() self.numaNodeMem = NumaNodeMemorySample()
def __init__(self, pid): """ Initialize a HostSample. :param pid: The PID of this vdsm host. :type pid: int """ self.timestamp = time.time() self.pidcpu = PidCpuSample(pid) self.ncpus = os.sysconf('SC_NPROCESSORS_ONLN') self.totcpu = TotalCpuSample() meminfo = utils.readMemInfo() freeOrCached = (meminfo['MemFree'] + meminfo['Cached'] + meminfo['Buffers']) self.memUsed = 100 - int(100.0 * (freeOrCached) / meminfo['MemTotal']) self.anonHugePages = meminfo.get('AnonHugePages', 0) // 1024 try: with open('/proc/loadavg') as loadavg: self.cpuLoad = loadavg.read().split()[1] except: self.cpuLoad = '0.0' self.diskStats = self._getDiskStats() try: with open(_THP_STATE_PATH) as f: s = f.read() self.thpState = s[s.index('[') + 1:s.index(']')] except: self.thpState = 'never' self.hugepages = hugepages.state() self.cpuCores = CpuCoreSample() self.numaNodeMem = NumaNodeMemorySample()
def __init__(self, pid): """ Initialize a HostSample. :param pid: The PID of this vdsm host. :type pid: int """ super(HostSample, self).__init__() self.interfaces = _get_interfaces_and_samples() self.pidcpu = PidCpuSample(pid) self.ncpus = os.sysconf('SC_NPROCESSORS_ONLN') self.totcpu = TotalCpuSample() meminfo = utils.readMemInfo() freeOrCached = (meminfo['MemFree'] + meminfo['Cached'] + meminfo['Buffers']) self.memUsed = 100 - int(100.0 * (freeOrCached) / meminfo['MemTotal']) self.anonHugePages = meminfo.get('AnonHugePages', 0) / 1024 try: with open('/proc/loadavg') as loadavg: self.cpuLoad = loadavg.read().split()[1] except: self.cpuLoad = '0.0' self.diskStats = self._getDiskStats() try: with open(_THP_STATE_PATH) as f: s = f.read() self.thpState = s[s.index('[') + 1:s.index(']')] except: self.thpState = 'never' self.hugepages = hugepages.state() self.cpuCores = CpuCoreSample() self.numaNodeMem = NumaNodeMemorySample() ENGINE_DEFAULT_POLL_INTERVAL = 15 try: self.recentClient = ( self.timestamp - os.stat(P_VDSM_CLIENT_LOG).st_mtime < 2 * ENGINE_DEFAULT_POLL_INTERVAL) except OSError as e: if e.errno == errno.ENOENT: self.recentClient = False else: raise