Created
April 27, 2018 12:25
-
-
Save tookdes/1b9933693cf6f80a55acbdc81ee3afda to your computer and use it in GitHub Desktop.
Use nvidia-smi to get data then send an E-mail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: UTF-8 -*- | |
import subprocess | |
import re | |
import time | |
import smtplib | |
from email.mime.text import MIMEText | |
smiexe = r"C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" | |
badload = 90 # CHANGE IT AS YOU LIKE | |
smtp_server = "smtp.xxx.com" | |
from_mail = "[email protected]" | |
mail_pass = "yourpassword" | |
to_mail = ["[email protected]"] | |
from_name = "MINE MONITOR" | |
subject = u'GPU LOAD: XXX' | |
def sendMail(content): | |
msg = MIMEText(content, 'plain', 'utf-8') | |
msg['Subject'] = subject | |
msg['From'] = "{}".format(from_mail) | |
msg['To'] = ",".join(to_mail) | |
try: | |
s = smtplib.SMTP() | |
s.connect(smtp_server, '25') | |
s.login(from_mail, mail_pass) | |
s.sendmail(from_mail, to_mail, str(msg)) | |
s.quit() | |
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+" MAIL SENT!!") | |
except smtplib.SMTPException as e: | |
print("Error: %s" %e) | |
def checksmi(): | |
smi = subprocess.Popen(smiexe, stdout = subprocess.PIPE, | |
stderr = subprocess.PIPE, shell = True) | |
smidata = smi.stdout.read() | |
rule = r'(.*?)% Default' | |
slotList = re.findall(rule,str(smidata)) | |
for i in range(0,len(slotList)): | |
slotList[i] = int(slotList[i][-3:].strip()) | |
if max(slotList) < badload: | |
sendMail(smidata.decode('utf-8')) | |
else: | |
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+" ALL GPU OK: "+ str(slotList)) | |
while True: | |
checksmi() | |
time.sleep(30) # CHANGE IT AS YOU LIKE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment