1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import time import psutil
print("cpu参数") print("cpu核心数:", psutil.cpu_count(logical=False)) print("cpu线程数:", psutil.cpu_count()) print("cpu在用户进程上花费的时间:", psutil.cpu_times().user) print("cpu在内核上花费的时间:", psutil.cpu_times().system) print("cpu各线程使用率:") print(psutil.cpu_percent(interval=0.5, percpu=True)) print("cpu频率:", psutil.cpu_freq().current)
print("======================================")
print("内存参数") total = psutil.virtual_memory().total / 1024 / 1024 / 1024 available = psutil.virtual_memory().available / 1024 / 1024 / 1024 print("内存总大小(GB):%.2f" % float(total)) print("内存剩余量(GB):%.2f" % float(available))
print("======================================")
print("磁盘参数") for p in psutil.disk_partitions(): print(p.device[0], end=" ") print("磁盘总大小(GB):%.2f" % float(psutil.disk_usage(p.device).total / 1024 / 1024 / 1024), end=" ") print("磁盘剩余量(GB):%.2f" % float(psutil.disk_usage(p.device).free / 1024 / 1024 / 1024))
print("======================================")
print("网络参数") last_io_counters = psutil.net_io_counters() while True: io_counters = psutil.net_io_counters() up_speed = (io_counters.bytes_sent - last_io_counters.bytes_sent) / 1024 / 1024 down_speed = (io_counters.bytes_recv - last_io_counters.bytes_recv) / 1024 / 1024 print(f'上传速度:{up_speed:.2f} MB/s, 下载速度:{down_speed:.2f} MB/s') last_io_counters = io_counters time.sleep(1)
|