CPU:
print(psutil.cpu_count(logical=False)) #獲取物理CPU數(shù)
print(psutil.cpu_count()) #獲取邏輯cpu數(shù)
print(psutil.cpu_times()) #cpu運行時間
內(nèi)存:
print(psutil.virtual_memory()) #獲取內(nèi)存信息
print(psutil.virtual_memory().total) #獲取內(nèi)存總數(shù)信息
print(psutil.virtual_memory().free) #獲取內(nèi)存剩余信息
print(psutil.swap_memory()) #獲取swap信息
硬盤:
print(psutil.disk_partitions()) #獲取系統(tǒng)硬盤信息
print(psutil.disk_usage("C:\\")) #獲取C盤信息
print(psutil.disk_io_counters()) #查看IO
網(wǎng)絡(luò):
print(psutil.net_if_addrs()) #查看網(wǎng)卡信息
print(psutil.net_connections()) #查看網(wǎng)卡流量信息
用戶信息:
print (psutil.users()) 獲取當(dāng)前用戶狀態(tài)信息
[suser(name='Tommy', terminal=None, host='0.0.0.0', started=1500514516.0)]
print (time.localtime(psutil.boot_time())) 獲取開機(jī)時間
time.struct_time(tm_year=2017, tm_mon=7, tm_mday=20, tm_hour=9, tm_min=35, tm_sec=5, tm_wday=3, tm_yday=201, tm_isdst=0)
進(jìn)程管理:
print(psutil.pids()) #獲取所有進(jìn)程ID
p=psutil.Process(4452) #實例化一個進(jìn)程ID
print(p.name()) #獲取進(jìn)程名
print(p.status()) #獲取進(jìn)程狀態(tài),ruinging
print(p.create_time()) #進(jìn)程創(chuàng)建時間
print(p.exe()) #進(jìn)程程序路徑
print(p.cwd()) #進(jìn)程的絕對路徑
print(p.num_threads()) #進(jìn)程開啟線程數(shù)
print(p.memory_percent()) #進(jìn)程內(nèi)存使用率

1564412959_431375.png
我的網(wǎng)站
愛運維:https://www.iyunw.cn
python粉絲:https://www.pythonfans.cn