add logs
This commit is contained in:
parent
43ff2e9ef3
commit
d30a80eda0
41
checker.py
41
checker.py
@ -88,7 +88,7 @@ class GRIST:
|
|||||||
raise ValueError(f"Setting {key} not found")
|
raise ValueError(f"Setting {key} not found")
|
||||||
|
|
||||||
|
|
||||||
def check_logs():
|
def check_logs(logger):
|
||||||
# Initialize counters
|
# Initialize counters
|
||||||
error_count = 0
|
error_count = 0
|
||||||
sync_count = 0
|
sync_count = 0
|
||||||
@ -96,7 +96,9 @@ def check_logs():
|
|||||||
|
|
||||||
# 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)
|
||||||
@ -111,19 +113,28 @@ def check_logs():
|
|||||||
|
|
||||||
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: error_count += 1
|
if "Error from tendermint rpc" in line:
|
||||||
if "Synced with network" in line: sync_count += 1
|
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)
|
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,
|
"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("Impact updater")
|
logger = logging.getLogger("Impact updater")
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
@ -134,17 +145,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()
|
result = check_logs(logger)
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user