import psutil
def get_CPU_state(time_count=1): return {'cpu_count': str(psutil.cpu_count(logical=False)), 'cpu_percent': str(psutil.cpu_percent(time_count, 0)) + "%"}
def get_memory_state(): phymem = psutil.virtual_memory() memory = dict() memory['total'] = str(int(phymem.total / 1024 / 1024)) + "M" memory['used'] = str(int(phymem.used / 1024 / 1024)) + "M" memory['free'] = str(int(phymem.free / 1024 / 1024)) + "M" memory['sum_mem'] = str(int(phymem.used / 1024 / 1024) / int(phymem.total / 1024 / 1024) * 100)[0:5] + "%" return memory
def get_disk_satate(): diskinfo = psutil.disk_usage('/') disk = { 'total': str(int(diskinfo.total / 1024 / 1024 / 1024)) + "G", 'used': str(int(diskinfo.used / 1024 / 1024 / 1024)) + "G", 'free': str(int(diskinfo.free / 1024 / 1024 / 1024)) + "G", 'sum_disk': str(int(diskinfo.used / 1024 / 1024 / 1024) / int(diskinfo.total / 1024 / 1024 / 1024) * 100)[0:5] + "%" } return disk