mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-09-25 01:58:12 +00:00
Add dmesg monitor
This commit is contained in:
parent
0ca94f9b63
commit
b89ba07d86
|
@ -971,6 +971,9 @@ def start_threads():
|
|||
public_ip_thread = BackgroundThread(find_public_ip, 60*60*12) # 12-hour repeat
|
||||
public_ip_thread.start()
|
||||
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)))
|
||||
|
||||
|
|
|
@ -156,3 +156,31 @@ def find_public_ip():
|
|||
# Updated: Check ins now happen in different process. This will just restart the service to force a new check in.
|
||||
def 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))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user