def f_print_linux_status(save_as):
###????###################################################################
#scputimes(user=, nice, system, idle, iowait, irq, softirq,steal, guest, guest_nice)
cpu_times = psutil.cpu_times()
#scpustats(ctx_switches, interrupts, soft_interrupts, syscalls)
#cpu_stats = psutil.cpu_stats()
# svmem(total , available, percent, used , free, active, inactive, buffers, cached, shared)
mem = psutil.virtual_memory()
# sswap(total, used, free, percent, sin, sout)
swap = psutil.swap_memory()
#sdiskusage(total, used, free, percent)
#disk_usage = psutil.disk_usage('/')
#sdiskio(read_count, write_count, read_bytes, write_bytes, read_time, write_time)
#disk_io_counters = psutil.disk_io_counters()
#snetio(bytes_sent, bytes_recv, packets_sent, packets_recv, errin, errout, dropin, dropout)
#net = psutil.net_io_counters()
#load
try:
load = os.getloadavg()
except (OSError, AttributeError):
stats = {}
else:
stats = {'min1': load[0], 'min5': load[1], 'min15': load[2]}
#Uptime = datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S")
###????###################################################################
style1 = {1: ' ,6,l', 2: ' ,10,r',3: ' ,6,l', 4: ' ,10,r',5: ' ,6,l', 6: ' ,6,r',7: ' ,8,l',8: ' ,6,r',9: ' ,6,l', 10: ' ,6,r',11: ' ,6,l', 12: ' ,5,r',}
style = {1: ' ,l', 2: ' ,r',3: ' ,l', 4: ' ,r',5: ' ,l', 6: ' ,r',7: ' ,l',8: ' ,r',9: ' ,l', 10: ' ,r',11: ' ,l', 12: ' ,r',}
rows=[
["CPU", str(psutil.cpu_percent(interval=1))+'%',"nice", cpu_times.nice,"MEM", str(mem.percent) + '%',"active", str(mem.active/1024/1024) + 'M',"SWAP", str(swap.percent)+'%',"LOAD", str(psutil.cpu_count())+'core'],
["user", cpu_times.user,"irq", cpu_times.irq,"total", str(mem.total/1024/1024)+'M',"inactive", str(mem.inactive/1024/1024) + 'M',"total", str(swap.total/1024/1024) + 'M',"1 min", stats["min1"]],
["system", cpu_times.system,"iowait", cpu_times.iowait,"used", str(mem.used/1024/1024)+'M',"buffers", str(mem.buffers/1024/1024) + 'M',"used", str(swap.used/1024/1024) + 'M',"5 min", stats["min5"]],
["idle", cpu_times.idle,"steal", cpu_times.steal,"free", str(mem.free/1024/1024) + 'M',"cached", str(mem.cached/1024/1024) + 'M',"free", str(swap.free/1024/1024) + 'M',"15 min", stats["min15"]]
]
title = "Linux Overview"
if save_as == "txt":
f_print_title(title)
f_print_table_body(rows, style1,' ')
elif save_as == "html":
f_print_table_html(rows, title, style)
评论列表
文章目录