Compare commits
No commits in common. "4de16544a3a6ea772903a1a7486e2ffe732c6f10" and "43ff2e9ef3ff4c6e83ab7497f0ae209286c9373b" have entirely different histories.
4de16544a3
...
43ff2e9ef3
43
checker.py
43
checker.py
@ -88,7 +88,7 @@ class GRIST:
|
||||
raise ValueError(f"Setting {key} not found")
|
||||
|
||||
|
||||
def check_logs(logger):
|
||||
def check_logs():
|
||||
# Initialize counters
|
||||
error_count = 0
|
||||
sync_count = 0
|
||||
@ -96,9 +96,7 @@ def check_logs(logger):
|
||||
|
||||
# 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:
|
||||
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 timestamp < day_ago: continue
|
||||
if "Error from tendermint rpc" in line:
|
||||
error_count += 1
|
||||
logger.error(f"RPC error: {line}")
|
||||
if "Synced with network" in line:
|
||||
sync_count += 1
|
||||
logger.info(f"Synced with network: {line}")
|
||||
|
||||
if "Error from tendermint rpc" in line: error_count += 1
|
||||
if "Synced with network" in line: sync_count += 1
|
||||
|
||||
challenge_match = re.search(r'made (\d+) secret challenges', line)
|
||||
if challenge_match:
|
||||
total_challenges += int(challenge_match.group(1))
|
||||
logger.info(f"Made {total_challenges} secret challenges: {line}")
|
||||
if challenge_match: total_challenges += int(challenge_match.group(1))
|
||||
|
||||
result = {
|
||||
return {
|
||||
"rpc_errors": error_count,
|
||||
"sync_events": sync_count,
|
||||
"total_challenges": total_challenges
|
||||
}
|
||||
logger.info(f"Result: {result}")
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Checker started")
|
||||
colorama.init(autoreset=True)
|
||||
logger = logging.getLogger("Checker")
|
||||
logger = logging.getLogger("Impact updater")
|
||||
logger.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
ch = logging.StreamHandler()
|
||||
@ -145,17 +134,17 @@ if __name__ == "__main__":
|
||||
|
||||
time.sleep(random.randint(1, 600))
|
||||
|
||||
GRIST_SERVER = "###GRIST_SERVER###"
|
||||
GRIST_DOC_ID = "###GRIST_DOC_ID###"
|
||||
GRIST_API_KEY = "###GRIST_API_KEY###"
|
||||
GRIST_ROW_NAME = socket.gethostname()
|
||||
NODES_TABLE = "Nodes"
|
||||
grist = GRIST(GRIST_SERVER, GRIST_DOC_ID, GRIST_API_KEY, logger)
|
||||
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)
|
||||
grist_server = "###GRIST_SERVER###"
|
||||
grist_doc_id = "###GRIST_DOC_ID###"
|
||||
grist_api_key = "###GRIST_API_KEY###"
|
||||
grist_row_name = socket.gethostname()
|
||||
nodes_table = "Nodes"
|
||||
grist = GRIST(grist_server, grist_doc_id, grist_api_key, logger)
|
||||
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)
|
||||
|
||||
try:
|
||||
result = check_logs(logger)
|
||||
result = check_logs()
|
||||
data = f"{result['sync_events']}/{result['total_challenges']}/{result['rpc_errors']}" # Syncs/Challenges/RPC errors
|
||||
grist_callback({ "Health": data })
|
||||
print(result)
|
||||
|
Loading…
Reference in New Issue
Block a user