-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsutil_pract.py
More file actions
62 lines (51 loc) · 1.28 KB
/
psutil_pract.py
File metadata and controls
62 lines (51 loc) · 1.28 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
import psutil
# Get overall CPU usage as a percentage
print(psutil.cpu_percent(interval=1))
# Per-CPU usage
print(psutil.cpu_percent(interval=1, percpu=True))
# Number of physical/logical cores
print(psutil.cpu_count(logical=False))
print(psutil.cpu_count(logical=True))
# Virtual memory
print(psutil.virtual_memory())
# Swap memory
print(psutil.swap_memory())
# Disk partitions
print(psutil.disk_partitions())
print('------------------------')
# Disk usage
print(psutil.disk_usage('/'))
print('------------------------')
# Disk I/O
print(psutil.disk_io_counters())
# Network I/O
print(psutil.net_io_counters())
print('----------------------')
# Network interfaces
print(psutil.net_if_addrs())
print('----------------------')
print(psutil.net_if_stats())
# List all process IDs
print(psutil.pids())
print('-----------------')
# Get a specific process
p=''
for pid in psutil.pids():
p = psutil.Process(pid)
# Common process info
print(p.name())
print('-----------------')
print(p.status())
print('-----------------')
print(p.cpu_percent(interval=1))
print('-----------------')
print(p.memory_info())
print('-----------------')
print(p.open_files())
print('-----------------')
print(p.connections())
# Boot time
print(psutil.boot_time())
print('----------------')
# Logged-in users
print(psutil.users())