This commit is contained in:
vvzvlad 2024-11-24 02:51:12 +03:00
parent 90aa23cf63
commit 727e13bbab

View File

@ -1,3 +1,8 @@
# flake8: noqa
# pylint: disable=broad-exception-raised, raise-missing-from, too-many-arguments, redefined-outer-name
# pylance: disable=reportMissingImports, reportMissingModuleSource, reportGeneralTypeIssues
# type: ignore
import re import re
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
import subprocess import subprocess
@ -6,6 +11,7 @@ import time
import random import random
import sys import sys
import pkg_resources import pkg_resources
import requests
required_packages = ['grist-api', 'colorama'] required_packages = ['grist-api', 'colorama']
installed_packages = [pkg.key for pkg in pkg_resources.working_set] installed_packages = [pkg.key for pkg in pkg_resources.working_set]
@ -16,7 +22,7 @@ for package in required_packages:
from grist_api import GristDocAPI from grist_api import GristDocAPI
import colorama import colorama
import requests
import logging import logging
import socket import socket
@ -88,40 +94,40 @@ class GRIST:
raise ValueError(f"Setting {key} not found") raise ValueError(f"Setting {key} not found")
def check_logs(logger): def check_logs(log_handler):
# Initialize counters # Initialize counters
error_count = 0 error_count = 0
sync_count = 0 sync_count = 0
total_challenges = 0 total_challenges = 0
try: try:
result = subprocess.run(['docker', 'compose', 'logs', '--since', '24h'], cwd='/root/node/', capture_output=True, text=True) logs = subprocess.run(['docker', 'compose', 'logs', '--since', '24h'], cwd='/root/node/', capture_output=True, text=True, check=True)
log_content = result.stdout log_content = logs.stdout
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
raise Exception(f"Error running docker compose logs: {e}") raise RuntimeError(f"Error running docker compose logs: {e}") from e
for line in log_content.split('\n'): for line in log_content.split('\n'):
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}") log_handler.error(f"RPC error: {line}")
if "Is your verifier's account funded" in line: if "Is your verifier's account funded" in line:
logger.error(f"Verifier account not funded: {line}") log_handler.error(f"Verifier account not funded: {line}")
error_count += 1 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}") log_handler.info(f"Synced with network: {line}")
challenge_match = re.search(r'made (\d+) secret challenges', line) challenge_match = re.search(r'made (\d+) secret challenges', line)
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}") log_handler.info(f"Made {total_challenges} secret challenges: {line}")
result = { data = {
"errors": error_count, "errors": error_count,
"sync_events": sync_count, "sync_events": sync_count,
"total_challenges": total_challenges "total_challenges": total_challenges
} }
logger.info(f"Result: {result}") log_handler.info(f"Result: {data}")
return result return data
if __name__ == "__main__": if __name__ == "__main__":
print("Checker started") print("Checker started")