日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

系统性能信息模块--psutil

發布時間:2025/3/15 windows 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 系统性能信息模块--psutil 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#安裝psutil模塊
#pip install psutil -i https://pypi.doubanio.com/simple


#導入psutil模塊
import psutil
import datetime
#將虛擬內存寫入變量
mem=psutil.virtual_memory()
#默認單位是字節,將單位換算成GB,這里按照1000來換算,理論上應該按照1024來計算
mem_total=mem.total / 1000000000
mem_userd=mem.used / 1000000000
mem_free=mem.free / 1000000000
mem_swap=psutil.swap_memory()
print('內存總數' + str(mem_total) + 'G')
print('內存剩余' + str(mem_userd) + 'G')
print(mem_swap)

#cpu相關信息
cpu_info=psutil.cpu_times()
cpu_user=psutil.cpu_times().user
cpu_count=psutil.cpu_count()
print(cpu_user)
print(cpu_info)
print('cpu核數:' + str(cpu_count) + '核')

#磁盤信息
disk_info=psutil.disk_partitions()
print('硬盤信息:' + str(disk_info))
disk_info_usage=psutil.disk_usage('/')
print('硬盤分區信息:' + str(disk_info_usage))

#網絡信息:流量監控,指接收和發送流量的相關信息
net_info=psutil.net_io_counters()
print('網絡信息:' + str(net_info))

#用戶登錄
user=psutil.users()
print(user)

#系統開機時間
host_boot_time=psutil.boot_time()
boot_time=datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%F %H:%M:%S")
print('開機時間:' + str(boot_time))

#進程信息
pro_pid=psutil.pids()#進程id
pro_name=psutil.Process(40)
print(pro_name)
print(pro_pid)

=====================================================================
輸出結果:

內存總數17.179869184G
內存剩余8.441253888G
sswap(total=0, used=0, free=0, percent=0, sin=19010850816, sout=0)
7659.97
scputimes(user=7659.97, nice=0.0, system=3262.39, idle=166041.86)
cpu核數:8核
硬盤信息:[sdiskpart(device='/dev/disk0s2', mountpoint='/', fstype='hfs', opts='rw,local,rootfs,dovolfs,journaled,multilabel')]
硬盤分區信息:sdiskusage(total=250656219136, used=213723643904, free=36670431232, percent=85.4)
網絡信息:snetio(bytes_sent=60475392, bytes_recv=779055104, packets_sent=618839, packets_recv=1389501, errin=0, errout=4, dropin=0, dropout=0)
[suser(name='admin', terminal='console', host=None, started=1561511424.0, pid=92), suser(name='admin', terminal='ttys001', host=None, started=1561539712.0, pid=2887)]
開機時間:2019-06-26 09:10:24
psutil.Process(pid=40, name='UserEventAgent', started='09:09:22')
[0, 1, 40, 41, 44, 45, 46, 48, 51, 53, 54, 55, 56, 58, 59, 63, 68, 69, 71, 72, 75, 77, 78, 79, 80, 81, 82, 85, 86, 88, 91, 92, 93, 94, 96, 97, 98, 99, 100, 101, 102, 104, 119, 123, 124, 128, 130, 132, 133, 135, 136, 137, 138, 139, 140, 141, 144, 145, 149, 150, 163, 164, 166, 167, 168, 173, 175, 176, 177, 180, 181, 182, 183, 184, 185, 194, 195, 201, 204, 205, 206, 211, 212, 213, 215, 216, 217, 218, 219, 220, 222, 223, 225, 229, 230, 231, 233, 235, 236, 237, 238, 239, 240, 241, 242, 245, 246, 247, 248, 250, 252, 254, 256, 258, 259, 260, 262, 263, 264, 265, 266, 267, 268, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 301, 302, 304, 308, 309, 310, 311, 312, 313, 315, 318, 319, 320, 323, 324, 325, 328, 329, 332, 335, 336, 337, 338, 339, 341, 342, 343, 344, 345, 346, 348, 349, 351, 352, 353, 355, 356, 357, 374, 375, 376, 378, 379, 387, 388, 389, 391, 392, 393, 394, 400, 401, 402, 404, 408, 409, 413, 423, 428, 429, 430, 436, 438, 487, 488, 490, 493, 494, 495, 496, 497, 502, 506, 507, 509, 510, 511, 513, 514, 515, 578, 579, 580, 581, 582, 590, 591, 593, 594, 595, 598, 603, 606, 607, 609, 610, 662, 788, 884, 1263, 1918, 1927, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1953, 1954, 1973, 2046, 2054, 2058, 2059, 2062, 2066, 2082, 2083, 2097, 2098, 2102, 2103, 2106, 2109, 2119, 2120, 2136, 2140, 2141, 2157, 2158, 2164, 2174, 2175, 2318, 2343, 2349, 2366, 2375, 2378, 2379, 2384, 2386, 2387, 2390, 2392, 2394, 2400, 2412, 2415, 2445, 2487, 2489, 2491, 2650, 2714, 2715, 2717, 2831, 2887, 2888, 2897, 2904, 2951]

進程已結束,退出代碼0

轉載于:https://www.cnblogs.com/python-cat/p/11091091.html

總結

以上是生活随笔為你收集整理的系统性能信息模块--psutil的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。