Skip to content

Instantly share code, notes, and snippets.

@Jacoblightning
Last active October 9, 2025 04:33
Show Gist options
  • Select an option

  • Save Jacoblightning/de555e570ed1a25824a44a61732be3c0 to your computer and use it in GitHub Desktop.

Select an option

Save Jacoblightning/de555e570ed1a25824a44a61732be3c0 to your computer and use it in GitHub Desktop.
Simple monero node sync progress monitor
import argparse
import requests
import time
import tqdm
class Port:
def __init__(self, n: str|int):
if isinstance(n, str):
try:
n = int(n)
except ValueError as e:
raise ValueError(f"Invalid port: {n}") from e
if isinstance(n, int):
if not 0 < n < 65536:
raise ValueError(f"Invalid port: {n}")
self.port = n
else:
raise ValueError(f"Invalid port: {n}")
def __repr__(self):
return f"Port(n={self.port})"
def get_monero_status(address, port):
r = requests.post(
f"http://{address}:{port}/json_rpc",
json={"jsonrpc":"2.0","id":"0","method":"get_info"}
)
if r.status_code == requests.codes.ok:
return r.json()["result"]
raise ConnectionRefusedError("Server (monerod) is not running.")
def main(address, port, wait_time, show_whole_progress):
stats = get_monero_status(address, port)
current_height = stats["height"]
target_height = stats["target_height"]
if current_height == target_height:
print("Not currently syncing...")
return 0
needed_height = target_height - current_height
pbar = tqdm.tqdm(
total=(target_height if show_whole_progress else needed_height),
initial=(current_height if show_whole_progress else 0),
unit="block",
desc="Sync status: "
)
last_height = current_height
try:
while True:
time.sleep(wait_time)
stats = get_monero_status(address, port)
current_height = stats["height"]
target_height = stats["target_height"]
if current_height == target_height:
print("Sync finished!")
break
height_diff = current_height - last_height
last_height = current_height
pbar.update(height_diff)
#print(f"Status (blocks): {current_height}/{target_height} ({percentage}%)")
except KeyboardInterrupt:
pass
finally:
pbar.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Simple monero node sync progress monitor")
parser.add_argument(
"-s", "--whole", "--show-whole-progress",
help="Show progress of the whole sync instead of since the script started",
action="store_true"
)
parser.add_argument(
"-a", "--address",
help="The address of the monero RPC server. (default: localhost)",
default="localhost"
)
parser.add_argument(
"-p", "--port",
help="The port of the monero RPC server. (default: 18081)",
type=Port,
default=Port(18081)
)
parser.add_argument(
"-w", "--wait",
help="The time to wait (in seconds) between RPC calls. (default: 3)",
type=float,
default=3.0
)
args = parser.parse_args()
main(args.address, args.port.port, args.wait, args.whole)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment