#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #@auhor by ruiy # # # #pip install paramiko -i https://pypi.tuna.tsinghua.edu.cn/simple # #pip install psutil -i https://pypi.tuna.tsinghua.edu.cn/simple # # #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import paramiko import datetime import time import os import psutil dt = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) print(dt) #psutil def get_cpu_infos(): cpu_count = psutil.cpu_count(logical=False) xc_count = psutil.cpu_count() cpu_percent = round((psutil.cpu_percent(1)),2) cpu_info = (cpu_count,xc_count,cpu_percent) return cpu_info def get_mem_infos(): memory = psutil.virtual_memory() total_mem = round((float(memory.total) / 1024 / 1024 / 1024),2) used_mem = round((float(memory.used) / 1024 / 1024 / 1024),2) free_mem = round((float(memory.free) / 1024 / 1024 / 1024),2) percent_mem = round((float(memory.used) / float(memory.total) * 100),2) mem_info = (total_mem,used_mem,free_mem,percent_mem) return mem_info def get_disk_infos(): list = psutil.disk_partitions() ilen = len(list) i = 0 retlist1 = [] retlist2 = [] disk_info_list = [] while i < ilen: diskinfo = psutil.disk_usage(list[i].device) total_disk = round((float(diskinfo.total) / 1024 / 1024 / 1024),2) used_disk = round((float(diskinfo.used) / 1024 / 1024 / 1024),2) free_disk = round((float(diskinfo.free) / 1024 / 1024 / 1024),2) #percent_disk = diskinfo.percent() retlist1 = [i,list[i].device,total_disk,used_disk,free_disk] disk_info_list.append(retlist1) i = i + 1 return disk_info_list if __name__ == '__main__': hosts = [ 'hostname="127.0.0.1",port=3389,username="administrator",password=""', ] for i in hosts: print(i) cpuInfos = get_cpu_infos() print(cpuInfos) memInfos = get_mem_infos() print(memInfos) diskInfos = get_disk_infos() print(diskInfos)