Compare commits
2 Commits
43ff2e9ef3
...
4de16544a3
Author | SHA1 | Date | |
---|---|---|---|
|
4de16544a3 | ||
|
d30a80eda0 |
43
checker.py
43
checker.py
@ -88,7 +88,7 @@ class GRIST:
|
||||
raise ValueError(f"Setting {key} not found")
|
||||
|
||||
|
||||
def check_logs():
|
||||
def check_logs(logger):
|
||||
# Initialize counters
|
||||
error_count = 0
|
||||
sync_count = 0
|
||||
@ -96,7 +96,9 @@ def check_logs():
|
||||
|
||||
# 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)
|
||||
@ -111,21 +113,30 @@ def check_logs():
|
||||
|
||||
if not timestamp: continue
|
||||
if timestamp < day_ago: continue
|
||||
if "Error from tendermint rpc" in line: error_count += 1
|
||||
if "Synced with network" in line: sync_count += 1
|
||||
|
||||
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}")
|
||||
|
||||
challenge_match = re.search(r'made (\d+) secret challenges', line)
|
||||
if challenge_match: total_challenges += int(challenge_match.group(1))
|
||||
if challenge_match:
|
||||
total_challenges += int(challenge_match.group(1))
|
||||
logger.info(f"Made {total_challenges} secret challenges: {line}")
|
||||
|
||||
return {
|
||||
result = {
|
||||
"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("Impact updater")
|
||||
logger = logging.getLogger("Checker")
|
||||
logger.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
ch = logging.StreamHandler()
|
||||
@ -134,17 +145,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()
|
||||
result = check_logs(logger)
|
||||
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