def get_system_info(self, hostname=None): du = DshUtils() # getting RAM size in gb mem_info = du.cat(hostname, "/proc/meminfo") if mem_info['rc'] != 0: _msg = 'failed to get content of /proc/meminfo of host: ' self.logger.error(_msg + hostname) else: got_mem_available = False for i in mem_info['out']: if "MemTotal" in i: self.system_total_ram = float(i.split()[1]) / (2**20) elif "MemAvailable" in i: mem_available = float(i.split()[1]) / (2**20) got_mem_available = True break elif "MemFree" in i: mem_free = float(i.split()[1]) / (2**20) elif "Buffers" in i: buffers = float(i.split()[1]) / (2**20) elif i.startswith("Cached"): cached = float(i.split()[1]) / (2**20) if got_mem_available: self.system_ram = mem_available else: self.system_ram = mem_free + buffers + cached # getting disk size in gb pbs_conf = du.parse_pbs_config(hostname) pbs_home_info = du.run_cmd(hostname, cmd=['df', '-k', pbs_conf['PBS_HOME']]) if pbs_home_info['rc'] != 0: _msg = 'failed to get output of df -k command of host: ' self.logger.error(_msg + hostname) else: disk_info = pbs_home_info['out'] disk_size = disk_info[1].split() self.system_disk = float(disk_size[3]) / (2**20) self.system_disk_used_percent = float(disk_size[4].rstrip('%'))
def get_system_info(self, hostname=None): du = DshUtils() # getting RAM size in gb mem_info = du.cat(hostname, "/proc/meminfo") if mem_info['rc'] != 0: _msg = 'failed to get content of /proc/meminfo of host: ' self.logger.error(_msg + hostname) else: for i in mem_info['out']: if "MemAvailable" in i: self.system_ram = float(i.split()[1]) / (2**20) break # getting disk size in gb pbs_conf = du.parse_pbs_config(hostname) pbs_home_info = du.run_cmd(hostname, cmd=['df', '-k', pbs_conf['PBS_HOME']]) if pbs_home_info['rc'] != 0: _msg = 'failed to get output of df -k command of host: ' self.logger.error(_msg + hostname) else: disk_info = pbs_home_info['out'] disk_size = disk_info[1].split() self.system_disk = float(disk_size[3]) / (2**20)