Skip to content

Instantly share code, notes, and snippets.

@enijkamp
Created July 14, 2018 22:20
Show Gist options
  • Save enijkamp/bc7a7fa927b7f6363ba4ccad8a937f60 to your computer and use it in GitHub Desktop.
Save enijkamp/bc7a7fa927b7f6363ba4ccad8a937f60 to your computer and use it in GitHub Desktop.
nvidia-smi temps
from subprocess import Popen, PIPE
import os
import datetime
import threading
import pygsheets
def fetch_temps():
p = Popen(["nvidia-smi", "--query-gpu=index,uuid,temperature.gpu,utilization.gpu,memory.total,memory.used,memory.free,driver_version,name,gpu_serial,display_active,display_mode", "--format=csv,noheader,nounits"], stdout=PIPE)
output = p.stdout.read().decode('UTF-8')
lines = output.split(os.linesep)
print(lines)
to_int = lambda line, index: int(line.split(', ')[index])
temps = [to_int(lines[i], 2) for i in range(len(lines)-1)]
return temps
def write_sheep(temps):
time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
print('{} {}'.format(time, temps))
gc = pygsheets.authorize(service_file='creds.json')
sh = gc.open('gputemp')
wks = sh[0]
row = wks.rows
wks.insert_rows(row-1, number=1, values=[[time]+temps])
def loop():
threading.Timer(5*60.0, loop).start()
write_sheep(fetch_temps())
loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment