import
psutil
import
os
import
time
import
datetime
def
net_monitor():
while
True
:
print
(
'='
*
50
)
print
(datetime.datetime.now())
print
(f
'磁盘使用率为{psutil.disk_usage("/").percent}%'
)
print
(f
'内存使用率为{psutil.virtual_memory().percent}%'
)
print
(f
'CPU使用率为{psutil.cpu_percent(interval=1)}%'
)
print
(f
'磁盘总量为{psutil.disk_usage("/").total/1024/1024/1024}GB'
)
print
(f
'磁盘剩仙量为{psutil.disk_usage("/").free/1024/1024/1024}GB'
)
print
(f
'磁盘可含量为{psutil.disk_usage("/").used/1024/1024/1024}GB'
)
print
(f
'磁盘空间量为{psutil.disk_usage("/").free/1024/1024/1024}GB'
)
net_info
=
psutil.net_io_counters()
recv
=
net_info.bytes_recv
send
=
net_info.bytes_sent
time.sleep(
1
)
net_info2
=
psutil.net_io_counters()
recv2
=
net_info2.bytes_recv
send2
=
net_info2.bytes_sent
recv_delta
=
recv2
-
recv
send_delta
=
send2
-
send
print
(datetime.datetime.now())
print
(f
'接收的数据量为{recv_delta/1024/1024}MB'
)
print
(f
'反馈的数据量为{send_delta/1024/1024}MB'
)
print
(
'='
*
50
)
net_monitor()