Compare commits

..

No commits in common. "4de16544a3a6ea772903a1a7486e2ffe732c6f10" and "43ff2e9ef3ff4c6e83ab7497f0ae209286c9373b" have entirely different histories.

View File

@ -88,7 +88,7 @@ class GRIST:
raise ValueError(f"Setting {key} not found") raise ValueError(f"Setting {key} not found")
def check_logs(logger): def check_logs():
# Initialize counters # Initialize counters
error_count = 0 error_count = 0
sync_count = 0 sync_count = 0
@ -96,9 +96,7 @@ def check_logs(logger):
# Get current time and 24 hours ago # Get current time and 24 hours ago
current_time = datetime.now() current_time = datetime.now()
logger.info(f"Current time: {current_time}")
day_ago = current_time - timedelta(days=1) 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'], cwd='/root/node/', capture_output=True, text=True)
@ -113,30 +111,21 @@ def check_logs(logger):
if not timestamp: continue if not timestamp: continue
if timestamp < day_ago: 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 if "Synced with network" in line: sync_count += 1
logger.error(f"RPC error: {line}")
if "Synced with network" in line:
sync_count += 1
logger.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}")
result = { return {
"rpc_errors": error_count, "rpc_errors": error_count,
"sync_events": sync_count, "sync_events": sync_count,
"total_challenges": total_challenges "total_challenges": total_challenges
} }
logger.info(f"Result: {result}")
return result
if __name__ == "__main__": if __name__ == "__main__":
print("Checker started")
colorama.init(autoreset=True) colorama.init(autoreset=True)
logger = logging.getLogger("Checker") logger = logging.getLogger("Impact updater")
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch = logging.StreamHandler() ch = logging.StreamHandler()
@ -145,17 +134,17 @@ if __name__ == "__main__":
time.sleep(random.randint(1, 600)) time.sleep(random.randint(1, 600))
GRIST_SERVER = "###GRIST_SERVER###" grist_server = "###GRIST_SERVER###"
GRIST_DOC_ID = "###GRIST_DOC_ID###" grist_doc_id = "###GRIST_DOC_ID###"
GRIST_API_KEY = "###GRIST_API_KEY###" grist_api_key = "###GRIST_API_KEY###"
GRIST_ROW_NAME = socket.gethostname() grist_row_name = socket.gethostname()
NODES_TABLE = "Nodes" nodes_table = "Nodes"
grist = GRIST(GRIST_SERVER, GRIST_DOC_ID, GRIST_API_KEY, logger) grist = GRIST(grist_server, grist_doc_id, grist_api_key, logger)
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: try:
result = check_logs(logger) result = check_logs()
data = f"{result['sync_events']}/{result['total_challenges']}/{result['rpc_errors']}" # Syncs/Challenges/RPC errors data = f"{result['sync_events']}/{result['total_challenges']}/{result['rpc_errors']}" # Syncs/Challenges/RPC errors
grist_callback({ "Health": data }) grist_callback({ "Health": data })
print(result) print(result)