-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor-sync.sh
More file actions
executable file
·43 lines (33 loc) · 1.28 KB
/
monitor-sync.sh
File metadata and controls
executable file
·43 lines (33 loc) · 1.28 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
#!/bin/bash
# Ergo Rust Node Sync Monitor
# Logs sync progress every 15 minutes to sync-progress.log
LOG_FILE="sync-progress.log"
API_URL="http://127.0.0.1:9053/info"
INTERVAL=900 # 15 minutes in seconds
echo "Ergo Rust Node Sync Monitor"
echo "Logging to: $LOG_FILE"
echo "Polling every 15 minutes"
echo "Press Ctrl+C to stop"
echo ""
# Write header to log file
echo "timestamp,headers_height,full_height,peer_count,is_synced" > "$LOG_FILE"
while true; do
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
# Call the API
RESPONSE=$(curl -s "$API_URL" 2>/dev/null)
if [ $? -eq 0 ] && [ -n "$RESPONSE" ]; then
# Parse JSON response
HEADERS=$(echo "$RESPONSE" | jq -r '.headersHeight // "N/A"')
FULL=$(echo "$RESPONSE" | jq -r '.fullHeight // "N/A"')
PEERS=$(echo "$RESPONSE" | jq -r '.peerCount // "N/A"')
SYNCED=$(echo "$RESPONSE" | jq -r '.isSynced // "N/A"')
# Log to file
echo "$TIMESTAMP,$HEADERS,$FULL,$PEERS,$SYNCED" >> "$LOG_FILE"
# Print to console
echo "[$TIMESTAMP] Headers: $HEADERS | Full blocks: $FULL | Peers: $PEERS | Synced: $SYNCED"
else
echo "$TIMESTAMP,ERROR,ERROR,ERROR,ERROR" >> "$LOG_FILE"
echo "[$TIMESTAMP] ERROR: Could not reach API at $API_URL"
fi
sleep $INTERVAL
done