Compare commits

...

2 Commits

  1. 20
      nvidia_smi.py
  2. 15
      readme.md

20
nvidia_smi.py

@ -1,4 +1,5 @@
import subprocess import subprocess
import psutil
import time import time
def get_gpu_stats(): def get_gpu_stats():
@ -12,16 +13,27 @@ def get_gpu_stats():
return { return {
"index": int(stats[0]), "index": int(stats[0]),
"name": str(stats[1]), "name": str(stats[1]),
"memory_used": float(stats[2]), # in MB "memory_used": int(stats[2]), # in MB
"memory_free": float(stats[3]), # in MB "memory_free": int(stats[3]), # in MB
"power_draw": float(stats[4]), # in watts "power_draw": float(stats[4]), # in watts
"temperature": float(stats[5]) # in Celsius "temperature": float(stats[5]) # in Celsius
} }
def get_cpu_memory_stats():
cpu_usage = psutil.cpu_percent(interval=1)
memory_info = psutil.virtual_memory()
return {
"cpu_usage": cpu_usage,
"memory_used": memory_info.used // (1024 ** 2), # in MB
"memory_total": memory_info.total // (1024 ** 2) # in MB
}
def main(): def main():
import json
while True: while True:
stats = get_gpu_stats() gpu_stats = get_gpu_stats()
print(f"Power: {stats['power_draw']} W, Memory: {stats['memory_used']} MB, Temp: {stats['temperature']}°C") cpu_stats = get_cpu_memory_stats()
print(json.dumps([gpu_stats, cpu_stats]))
time.sleep(1) # Update every second time.sleep(1) # Update every second
if __name__ == "__main__": if __name__ == "__main__":

15
readme.md

@ -0,0 +1,15 @@
### install on fresh ubuntu
```bash
sudo apt-get install openssh-server htop iotop git python3-pip python3-venv
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txt
```
sudo apt-get install python3-pip python3-venv
Loading…
Cancel
Save