-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsutil_system_info.py
More file actions
38 lines (27 loc) · 1.17 KB
/
psutil_system_info.py
File metadata and controls
38 lines (27 loc) · 1.17 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
"""Load psutil from an encrypted paker bundle and query system info.
Requires psutil installed for the dump step: pip install psutil
"""
import json
import os
import sys
import paker
KEY = os.urandom(32)
print("Dumping psutil (encrypted)...")
bundle = paker.dumps("psutil", key=KEY)
blob = json.dumps(bundle)
print(f"Bundle: {len(blob):,} bytes\n")
for name in list(sys.modules):
if name.startswith("psutil"):
del sys.modules[name]
with paker.loads(blob, key=KEY) as imp:
import psutil
print(f"CPU cores: {psutil.cpu_count()} logical, {psutil.cpu_count(logical=False)} physical")
print(f"CPU usage: {psutil.cpu_percent(interval=0.5)}%")
mem = psutil.virtual_memory()
print(f"Memory: {mem.total / (1024**3):.1f} GB total, {mem.percent}% used")
disk = psutil.disk_usage("/")
print(f"Disk (/): {disk.total / (1024**3):.0f} GB total, {disk.percent}% used")
net = psutil.net_io_counters()
print(f"Network: {net.bytes_sent / (1024**2):.0f} MB sent, {net.bytes_recv / (1024**2):.0f} MB received")
print(f"Processes: {len(psutil.pids())} running")
print(f"Boot time: {__import__('datetime').datetime.fromtimestamp(psutil.boot_time())}")