psutil 运维工作简化

import psutil
import datetime
# cpu
cpu_info = psutil.cpu_times() #使用cpu_times获取cpu的完整信息
cpu_num_l = psutil.cpu_count() #获取cpu的逻辑个数
cpu_num_w= psutil.cpu_count(logical=False) #获取cpu的物理个数
#memory
mem = psutil.virtual_memory()
mem_all = mem.total/1024/1024
mem_use = mem.used/1024/1024
mem_use_bai = mem.used/mem.total
#net
net_info = psutil.net_io_counters(pernic=True) #输出网络每个接口信息 #pernic=True
#wake_time
wake_time = datetime.datetime.fromtimestamp(psutil.boot_time ()).strftime("%Y-%m-%d %H: %M: %S") #转换成自然时间格式


if __name__ == '__main__':
	print(cpu_info)
	print(cpu_num_l)
	print(cpu_num_w)
	print(mem)
	print(mem_all)
	print(mem_use)
	print(mem_use_bai)
	print(net_info)
	print(wake_time)

 

你可能感兴趣的:(psutil 运维工作简化)