国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python中psutil模塊使用匯總

Python中psutil模塊使用匯總

2022-03-11 00:18三爺帶你飛 Python

psutil模塊是一個跨平臺庫,用于檢索Python中運行進程和系統利用率(CPU、內存、磁盤、網絡、傳感器)的信息。它主要用于系統監視、分析和限制進程資源以及管理正在運行的進程,本文給大家介紹Python中psutil模塊使用匯總,感興

簡介:psutil(進程和系統實用程序)是一個跨平臺庫,用于檢索Python中運行進程和系統利用率(CPU、內存、磁盤、網絡、傳感器)的信息。它主要用于系統監視、分析和限制進程資源以及管理正在運行的進程。它實現了經典UNIX命令行工具提供的許多功能,如ps、top、iotop、lsof、netstat、ifconfig、free等。

支持的平臺:Linux、Windows、macOS、FreeBSD, OpenBSD, NetBSD、Sun Solaris、AIX等平臺。

安裝:

?
1
pip install psutil

用戶系統信息:

?
1
2
3
4
5
6
import psutil
import datetime
 
print("當前用戶:", psutil.users())
print("當前系統時間:", psutil.boot_time())  # 以時間戳格式返回)
print(datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H: %M: %S"))  # 轉換成自然時間格式

內存信息:

?
1
2
3
4
5
6
7
8
9
10
11
mem = psutil.virtual_memory()
print("系統內存全部信息:", mem)
mem_total = float(mem.total)
mem_used = float(mem.used)
mem_free = float(mem.free)
mem_percent = float(mem.percent)
 
print(f"系統總計內存:{mem_total}")
print(f"系統已經使用內存:{mem_used}")
print(f"系統空閑內存:{mem_free}")
print(f"系統內存使用率:{mem_percent}")

CPU信息:

?
1
2
3
print("CPU匯總信息:", psutil.cpu_times())
print("cpu邏輯個數:", psutil.cpu_count())
print("swap內存信息:", psutil.swap_memory())

磁盤信息:

?
1
2
3
4
print("獲取磁盤的完整信息:", psutil.disk_partitions())
print("獲取分區表的參數:", psutil.disk_usage('/'))  # 獲取/分區的狀態
print("獲取硬盤IO總個數:", psutil.disk_io_counters())
print("獲取單個分區IO個數:", psutil.disk_io_counters(perdisk=True))  # perdisk=True參數獲取單個分區IO個數

網絡信息:

?
1
print("獲取網絡總IO信息:", psutil.net_io_counters())

系統進程管理信息:

?
1
print("查看系統全部進程:", psutil.pids())

單個進程的詳細信息:

?
1
2
3
4
5
6
7
8
9
10
pid_info = psutil.Process(1200)
print(pid_info.name())  # 進程名
print(pid_info.exe())  # 進程的bin路徑
print(pid_info.status())  # 進程狀態
print(pid_info.create_time())  # 進程創建時間
print(pid_info.cpu_times())  # 進程的cpu時間信息,包括user,system兩個cpu信息
print(pid_info.memory_percent())  # 進程內存利用率
print(pid_info.memory_info())  # 進程內存rss,vms信息
print(pid_info.io_counters())  # 進程的IO信息,包括讀寫IO數字及參數
print(pid_info.num_threads())  # 進程開啟的線程數

源碼:

?
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
40
41
42
43
44
45
46
47
48
49
import psutil
import datetime
 
# 用戶,系統相關:
print("當前用戶:", psutil.users())
print("當前系統時間:", psutil.boot_time())  # 以linux時間格式返回)
print(datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H: %M: %S"))  # 轉換成自然時間格式
 
# 內存相關:
mem = psutil.virtual_memory()
print("系統內存全部信息:", mem)
mem_total = float(mem.total)
mem_used = float(mem.used)
mem_free = float(mem.free)
mem_percent = float(mem.percent)
 
print(f"系統總計內存:{mem_total}")
print(f"系統已經使用內存:{mem_used}")
print(f"系統空閑內存:{mem_free}")
print(f"系統內存使用率:{mem_percent}")
 
# CPU相關:
print("CPU匯總信息:", psutil.cpu_times())
print("cpu邏輯個數:", psutil.cpu_count())
print("swap內存信息:", psutil.swap_memory())
 
# 磁盤相關:
print("獲取磁盤的完整信息:", psutil.disk_partitions())
print("獲取分區表的參數:", psutil.disk_usage('/'))  # 獲取/分區的狀態
print("獲取硬盤IO總個數:", psutil.disk_io_counters())
print("獲取單個分區IO個數:", psutil.disk_io_counters(perdisk=True))  # perdisk=True參數獲取單個分區IO個數
 
# 網絡相關:
print("獲取網絡總IO信息:", psutil.net_io_counters())
 
# 系統進程管理:
print("查看系統全部進程:", psutil.pids())
 
# 單個進程的詳細信息:
pid_info = psutil.Process(1200)
print(pid_info.name())  # 進程名
print(pid_info.exe())  # 進程的bin路徑
print(pid_info.status())  # 進程狀態
print(pid_info.create_time())  # 進程創建時間
print(pid_info.cpu_times())  # 進程的cpu時間信息,包括user,system兩個cpu信息
print(pid_info.memory_percent())  # 進程內存利用率
print(pid_info.memory_info())  # 進程內存rss,vms信息
print(pid_info.io_counters())  # 進程的IO信息,包括讀寫IO數字及參數
print(pid_info.num_threads())  # 進程開啟的線程數

運行結果:

Python中psutil模塊使用匯總

到此這篇關于Python中psutil模塊使用的文章就介紹到這了,更多相關Python psutil模塊內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/hzblucky1314/article/details/121645575

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲激情精品 | 久久久久久久久99精品 | 中文字幕精品视频 | 99这里只有精品视频 | 欧美成人综合在线 | 欧美日本在线观看 | 99久久久精品国产一区二区 | av瑟瑟| 欧美国产精品 | 一级片在线观看 | 欧美在线观看一区 | 日韩在线免费电影 | 久久久青草婷婷精品综合日韩 | 精品国产欧美 | 国产精品久久一区 | 精品免费一区二区 | 精品久久久久久久久久久 | 国产精品久久久久久久久 | 正在播放国产精品 | 欧美精品国产精品 | 欧美在线操 | 999一个人免费看ww | 欧美日韩一区二区三区在线观看 | 中文av一区二区三区 | www.亚洲成人 | 狠狠操夜夜爱 | 亚洲三区视频 | 在线a人片免费观看视频 | 伊人伊人网 | 色偷偷888欧美精品久久久 | 黄网站在线播放 | 久久久久久久免费观看 | 国产精品久久国产精品 | 91在线看| av网站免费 | 国产成人精品免费视频大全最热 | 欧美日韩在线免费 | 日韩精品一区二区三区精品av | 亚洲欧美日韩精品久久亚洲区 | 99精品久久久 | 日韩欧美国产一区二区 |