-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor_monero_sync.py
65 lines (58 loc) · 1.99 KB
/
monitor_monero_sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import time
import os
# Configuration
NODE_URL = "http://192.168.2.124:18081/json_rpc"
CHECK_INTERVAL = 10 # Time in seconds between checks
def get_sync_status():
"""
Fetch synchronization status from Monero node.
"""
try:
response = requests.post(
NODE_URL,
json={
"jsonrpc": "2.0",
"id": "0",
"method": "get_info"
},
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
data = response.json()
if "result" in data:
return data["result"]
else:
return None
else:
return None
except Exception as e:
print(f"Error: {e}")
return None
def monitor_sync():
"""
Monitor and display synchronization progress in a single terminal view.
"""
while True:
os.system('clear') # Clear the terminal for updated output
status = get_sync_status()
if status:
height = status.get("height", 0)
target_height = status.get("target_height", 1)
busy_syncing = status.get("busy_syncing", False)
synchronized = status.get("synchronized", False)
progress = (height / target_height) * 100 if target_height > 0 else 0
print("Monitoring Monero Node Synchronization Progress...\n")
print(f"Current Block Height: {height}")
print(f"Target Block Height: {target_height}")
print(f"Synchronization Progress: {progress:.2f}%")
print(f"Busy Syncing: {busy_syncing}")
print(f"Fully Synchronized: {synchronized}")
if synchronized:
print("\nNode is fully synchronized!")
break
else:
print("Failed to fetch synchronization status. Retrying...\n")
time.sleep(CHECK_INTERVAL)
if __name__ == "__main__":
monitor_sync()