# -*- coding:utf-8 -*-
import socket
import os, psutil
def getInfo():
hostname = socket.gethostname() + "\n"
cores = "物理内核数:%s" % psutil.cpu_count(logical=False) + " "
swap = "Swap分区使用率:%0.2f"%(psutil.swap_memory().percent) + "%" + " "
disk = "硬盘使用率:%0.2f"%(psutil.disk_usage('/').percent) + "%" + " "
cpu = "CPU使用率:%0.2f"%psutil.cpu_percent(interval=1)+"%" + " "
memory = "内存使用率:%d"%(int(round(psutil.virtual_memory().percent)))+"%"+" "
loadavg = "系统负载:%s"%(str(os.getloadavg())) + " "
return hostname+cores+swap+disk+cpu+memory+loadavg
if __name__ == "__main__":
info = getInfo()
print(info)
网友评论