Add dmesg monitor

This commit is contained in:
Taylor Helsper 2021-02-27 18:03:23 -06:00
parent 0ca94f9b63
commit b89ba07d86
2 changed files with 32 additions and 1 deletions

View File

@ -971,6 +971,9 @@ def start_threads():
public_ip_thread = BackgroundThread(find_public_ip, 60*60*12) # 12-hour repeat public_ip_thread = BackgroundThread(find_public_ip, 60*60*12) # 12-hour repeat
public_ip_thread.start() public_ip_thread.start()
threads.append(public_ip_thread) threads.append(public_ip_thread)
dmesg_thread = BackgroundThread(monitor_dmesg, 60) # Runs forever, restart after 60 if it fails
dmesg_thread.start()
threads.append(dmesg_thread)
app.logger.info("STARTED {} THREADS".format(len(threads))) app.logger.info("STARTED {} THREADS".format(len(threads)))

View File

@ -155,4 +155,32 @@ def find_public_ip():
# Updated: Check ins now happen in different process. This will just restart the service to force a new check in. # Updated: Check ins now happen in different process. This will just restart the service to force a new check in.
def check_in(): def check_in():
os.system("systemctl restart check_in") os.system("systemctl restart check_in")
def dmesg_log_clear():
f = open("/tmp/dmesg", "w")
f.write("")
f.close()
def dmesg_log(msg):
print(msg)
f = open("/tmp/dmesg", "a")
f.write(msg)
f.close()
# This will monitor dmesg for system errors or issues
def monitor_dmesg():
dmesg_log_clear()
cmd = ["dmesg","--follow"]
dmesg = subprocess.Popen(cmd, stdout=subprocess.PIPE)
while True:
l = dmesg.stdout.readline()
try:
l = l.encode('utf-8', 'ignore').decode('utf-8')
#TODO: Check for things like OOM, etc...
dmesg_log(l)
except Exception as e:
dmesg_log("dmesg exception: "+str(e))