-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstuck_monitor.sh
executable file
·46 lines (42 loc) · 1.32 KB
/
stuck_monitor.sh
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
#!/bin/bash
#
# Created by Uruncle @ https://adage.app Cardano Stake Pool
#
# Disclaimer:
#
# The following use of shell script is for demonstration and understanding
# only, it should *NOT* be used at scale or for any sort of serious
# deployment, and is solely used for learning how the node and blockchain
# works, and how to interact with everything.
#
### CONFIGURATION
LAST_BLOCK=""
RESTART_GT=600
START_TIME=$SECONDS
while true
do
TIME=$(date '+%Y-%m-%d %H:%M:%S')
echo ""
echo "${TIME} - Press [CTRL+C] to stop..."
LATEST_BLOCK=$(curl http://127.0.0.1:12789/metrics 2>/dev/null | grep -i cardano_node_ChainDB_metrics_blockNum_int | awk '{print $2}')
if [ "$LATEST_BLOCK" > 0 ]; then
if [ "$LATEST_BLOCK" != "$LAST_BLOCK" ]; then
START_TIME=$(($SECONDS))
echo "New block height: ${LATEST_BLOCK}"
LAST_BLOCK="$LATEST_BLOCK"
else
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Current block height: ${LATEST_BLOCK} - No new block for ${ELAPSED_TIME} sec."
if [ "$ELAPSED_TIME" -gt "$RESTART_GT" ]; then
restart-nodes.sh
LAST_BLOCK="$LATEST_BLOCK"
echo "Sleeping for 60 sec."
sleep 60
fi
fi
else
echo "No block height"
fi
sleep 60
done
exit 0