You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

28 lines
884 B

import subprocess
import time
def get_gpu_stats():
command = [
"nvidia-smi",
"--query-gpu=index,name,memory.used,memory.free,power.draw,temperature.gpu",
"--format=csv,noheader,nounits"
]
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
stats = result.stdout.strip().split(", ")
return {
"index": int(stats[0]),
"name": str(stats[1]),
"memory_used": float(stats[2]), # in MB
"memory_free": float(stats[3]), # in MB
"power_draw": float(stats[4]), # in watts
"temperature": float(stats[5]) # in Celsius
}
def main():
while True:
stats = get_gpu_stats()
print(f"Power: {stats['power_draw']} W, Memory: {stats['memory_used']} MB, Temp: {stats['temperature']}°C")
time.sleep(1) # Update every second
if __name__ == "__main__":
main()