def get_stats(cif, sample, multipath=False): """ Retreive host internal statistics """ hooks.before_get_stats() ret = {} first_sample, last_sample, _ = sample decStats = stats.produce(first_sample, last_sample) if cif.irs: decStats['storageDomains'] = cif.irs.repoStats() del decStats['storageDomains']['status'] if multipath: decStats['multipathHealth'] = cif.irs.multipath_health() del decStats['multipathHealth']['status'] else: decStats['storageDomains'] = {} for var in decStats: ret[var] = utils.convertToStr(decStats[var]) avail, commit = _memUsageInfo(cif) ret['memAvailable'] = avail // Mbytes ret['memCommitted'] = commit // Mbytes ret['memFree'] = _memFree() // Mbytes ret['swapTotal'], ret['swapFree'] = _readSwapTotalFree() (ret['vmCount'], ret['vmActive'], ret['vmMigrating'], ret['incomingVmMigrations'], ret['outgoingVmMigrations']) = \ _countVms(cif) (tm_year, tm_mon, tm_day, tm_hour, tm_min, tm_sec, dummy, dummy, dummy) = time.gmtime(time.time()) ret['dateTime'] = '%02d-%02d-%02dT%02d:%02d:%02d GMT' % ( tm_year, tm_mon, tm_day, tm_hour, tm_min, tm_sec) ret['momStatus'] = cif.mom.getStatus() ret.update(cif.mom.getKsmStats()) ret['netConfigDirty'] = str(cif._netConfigDirty) ret['haStats'] = _getHaInfo() if ret['haStats']['configured']: # For backwards compatibility, will be removed in the future ret['haScore'] = ret['haStats']['score'] ret = hooks.after_get_stats(ret) return ret