Compare commits

..

2 Commits

Author SHA1 Message Date
vvzvlad
90aa23cf63 log 24h update logic 2024-11-24 02:45:59 +03:00
vvzvlad
e6f24496a8 update 2024-11-24 02:42:23 +03:00

View File

@ -94,28 +94,19 @@ def check_logs(logger):
sync_count = 0 sync_count = 0
total_challenges = 0 total_challenges = 0
# Get current time and 24 hours ago
current_time = datetime.now()
logger.info(f"Current time: {current_time}")
day_ago = current_time - timedelta(days=1)
logger.info(f"Max logs timestamp: {day_ago}")
try: try:
result = subprocess.run(['docker', 'compose', 'logs'], cwd='/root/node/', capture_output=True, text=True) result = subprocess.run(['docker', 'compose', 'logs', '--since', '24h'], cwd='/root/node/', capture_output=True, text=True)
log_content = result.stdout log_content = result.stdout
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
raise Exception(f"Error running docker compose logs: {e}") raise Exception(f"Error running docker compose logs: {e}")
for line in log_content.split('\n'): for line in log_content.split('\n'):
timestamp_match = re.search(r'(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})', line)
if timestamp_match: timestamp = datetime.strptime(timestamp_match.group(1), '%Y-%m-%dT%H:%M:%S')
else: timestamp = None
if not timestamp: continue
if timestamp < day_ago: continue
if "Error from tendermint rpc" in line: if "Error from tendermint rpc" in line:
error_count += 1 error_count += 1
logger.error(f"RPC error: {line}") logger.error(f"RPC error: {line}")
if "Is your verifier's account funded" in line:
logger.error(f"Verifier account not funded: {line}")
error_count += 1
if "Synced with network" in line: if "Synced with network" in line:
sync_count += 1 sync_count += 1
logger.info(f"Synced with network: {line}") logger.info(f"Synced with network: {line}")
@ -124,9 +115,8 @@ def check_logs(logger):
if challenge_match: if challenge_match:
total_challenges += int(challenge_match.group(1)) total_challenges += int(challenge_match.group(1))
logger.info(f"Made {total_challenges} secret challenges: {line}") logger.info(f"Made {total_challenges} secret challenges: {line}")
result = { result = {
"rpc_errors": error_count, "errors": error_count,
"sync_events": sync_count, "sync_events": sync_count,
"total_challenges": total_challenges "total_challenges": total_challenges
} }
@ -154,12 +144,16 @@ if __name__ == "__main__":
current_vm = grist.find_record(name=GRIST_ROW_NAME, table=NODES_TABLE)[0] current_vm = grist.find_record(name=GRIST_ROW_NAME, table=NODES_TABLE)[0]
def grist_callback(msg): grist.update(current_vm.id, msg, NODES_TABLE) def grist_callback(msg): grist.update(current_vm.id, msg, NODES_TABLE)
try: for attempt in range(3):
result = check_logs(logger) try:
data = f"{result['sync_events']}/{result['total_challenges']}/{result['rpc_errors']}" # Syncs/Challenges/RPC errors result = check_logs(logger)
grist_callback({ "Health": data }) data = f"{result['sync_events']}/{result['total_challenges']}/{result['errors']}" # Syncs/Challenges/Errors
print(result) grist_callback({ "Health": data })
except Exception as e: print(result)
logger.error(f"Error: {e}") break
grist_callback({ "Health": f"Error: {e}" }) except Exception as e:
logger.error(f"Error on attempt {attempt+1}/3: {e}")
if attempt == 2:
grist_callback({ "Health": f"Error: {e}" })
if attempt < 2:
time.sleep(5)