-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathhealth-check.py
More file actions
68 lines (59 loc) · 1.75 KB
/
health-check.py
File metadata and controls
68 lines (59 loc) · 1.75 KB
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
66
67
68
#!/usr/bin/env python3
import json
import requests
from tabulate import tabulate
import argparse
NODES = [
"50.28.86.131:8099",
"50.28.86.153:8099",
"76.8.228.245:8099"
]
def query_node(node_addr):
try:
response = requests.get(f"http://{node_addr}/health", timeout=5)
response.raise_for_status()
data = response.json()
return {
"node": node_addr,
"status": "✅ Online",
"version": data.get("version", "N/A"),
"uptime": data.get("uptime", "N/A"),
"db_rw": "✅ RW" if data.get("db_rw", False) else "❌ RO",
"tip_age": f"{data.get('tip_age', 0)}s"
}
except Exception as e:
return {
"node": node_addr,
"status": "❌ Offline",
"version": "N/A",
"uptime": "N/A",
"db_rw": "N/A",
"tip_age": "N/A",
"error": str(e)
}
def main():
parser = argparse.ArgumentParser(description="RustChain Node Health Check CLI")
parser.add_argument("--json", action="store_true", help="Output JSON format")
args = parser.parse_args()
results = [query_node(node) for node in NODES]
if args.json:
print(json.dumps(results, indent=2))
return
headers = ["Node", "Status", "Version", "Uptime", "DB RW", "Tip Age"]
table_data = [
[
res["node"],
res["status"],
res["version"],
res["uptime"],
res["db_rw"],
res["tip_age"]
]
for res in results
]
print("\n🦀 RustChain Node Health Status")
print("=" * 60)
print(tabulate(table_data, headers=headers, tablefmt="grid"))
print("\n")
if __name__ == "__main__":
main()