import psutil
def cpu_information():
#scputimes(user=26.9, nice=0.1, system=50.27, idle=8551.89, iowait=1.97, irq=0.0, softirq=1.86, steal=0.0, guest=0.0, guest_nice=0.0)
cpu_schemas=[ ("%usertime","%Nice", "%system","%idle" ,"%iowait","irq","softirq","steal","guest","guest_nice" )]
cpuinfo_list=psutil.cpu_times(percpu=True)
for cpu in cpuinfo_list:
user=cpu.user
nice=cpu.nice
system=cpu.system
idle=cpu.idle
iowait=cpu.iowait
irq=cpu.irq
softirq=cpu.softirq
steal=cpu.steal
guest=cpu.guest
guest_nice=cpu.guest_nice
info=[user,nice,system,idle,iowait,irq,softirq,steal,guest,guest_nice]
cpu_schemas.append(info)
# cpu_schemas.append(psutil.cpu_percent(percpu=True))
for i in cpu_schemas:
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9]]
b=[str(i) for i in a]
print(b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9])
def disk_info():
# disk=psutil.cpu_percent(percpu=True)
infos=[["r_count","w_count","r_bytes","w_bytes","r_time","w_time","r_merge_count","w_merge_count","busy_time"]]
disks=psutil.disk_io_counters(perdisk=True)
for k,v in disks.items():
read_count=v.read_count
write_count=v.write_count
read_bytes=v.read_bytes
write_bytes=v.write_bytes
read_time=v.read_time
write_time=v.write_time
read_merge_count=v.read_merged_count
write_merge_count=v.write_merged_count
busy_time=v.busy_time
one_disk=[k,read_count,write_count,read_bytes,write_bytes,read_time,write_time,read_merge_count,write_merge_count,busy_time]
infos.append(one_disk)
for i in infos:
#print(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8]]
b = [str(m) for m in a]
print(b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])
def network_info():
nets=psutil.net_io_counters(pernic=True)
nets_info=[["network_card","sent_bytes","recv_bytes","packets_sent","packets_recv","errin","errout","dropin","dropout"]]
for k,v in nets.items():
network=k
bytes_sent=v.bytes_sent
bytes_recv=v.bytes_recv
packets_sent=v.packets_sent
packets_recv=v.packets_recv
errorin=v.errin
errout=v.errout
dropin=v.dropin
dropout=v.dropout
one_net=[network,bytes_sent,bytes_recv,packets_sent,packets_recv,errorin,errout,dropin,dropout]
nets_info.append(one_net)
for i in nets_info:
#print(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8]]
b=[str(m) for m in a]
print(b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8])
def mem_info():
mems=psutil.virtual_memory()
total=mems.total
used=mems.used
free=mems.free
available=mems.available
percent=mems.percent
active=mems.active
inactive=mems.inactive
buffers=mems.buffers
cached=mems.cached
shared=mems.shared
slab=mems.slab
swaps=psutil.swap_memory()
swap_total=swaps.total
# swap_available=swaps.available
swap_used=swaps.used
swap_free=swaps.free
swap_percent = swaps.percent
sin=swaps.sin
sout=swaps.sout
# swap_active=swaps.active
# swap_inactive=swaps.inactive
# swap_buffers=swaps.buffers
# swap_cached=swaps.cached
# swap_shared=swaps.shared
# swap_slab=swaps.slab
virtual_mem_info =[["total","used","free","available","percent","active","inactive","buffers","cached","shared","slab"]]
swaps_mem_info=[["swap_total","swap_used","swap_free","swap_percent","sin","sout"]]
virtual_mem_info.append([total,used,free,available,percent,active,inactive,buffers,cached,shared,slab])
swaps_mem_info.append([swap_total,swap_used,swap_free,swap_percent,sin,sout])
# virtual_mem_info.extend(swaps_mem_info)
for i in virtual_mem_info:
#print(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9],i[10])
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9],i[10]]
b=[str(m) for m in a]
print(b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9],b[10])
for j in swaps_mem_info:
#print(j[0],j[1],j[2],j[3],j[4],j[5])
c=[j[0],j[1],j[2],j[3],j[4],j[5]]
d=[str(y) for y in c]
print(d[0],d[1],d[2],d[3],d[4],d[5])
def unions():
print("=====cpuinfo=======")
cpu_information()
print("======disk info=====")
disk_info()
print("=====meminfo========")
mem_info()
print("======netioinfo=====")
network_info()
if __name__ == '__main__':
unions()