okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-1402-w' into f-140253623e56f

main
788 B11 linesraw
1"""Sample host RAM in use (total - available), swap and GPU state once per second (Windows, psutil + nvidia-smi)."""
2import json, subprocess, time, psutil
3while True:
4    vm, sw = psutil.virtual_memory(), psutil.swap_memory()
5    try:
6        g = subprocess.check_output(["nvidia-smi", "--query-gpu=memory.used,memory.total,utilization.gpu,power.draw,temperature.gpu,pcie.link.gen.current,pcie.link.width.current", "--format=csv,noheader,nounits"], text=True, timeout=5).strip()
7    except Exception as e:
8        g = repr(e)
9    print(json.dumps({"epoch_s": time.time(), "host_used_gib": round((vm.total - vm.available) / 2**30, 3),
10                      "host_total_gib": round(vm.total / 2**30, 3), "swap_used_gib": round(sw.used / 2**30, 3), "gpu": g}), flush=True)
11    time.sleep(1)