Skip to content

Commit 39f2ab7

Browse files
committed
monitor eth and chia
1 parent d57eccd commit 39f2ab7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

monitor-chia.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ while true; do
2222
echo "[$(date)] Warning: Could not retrieve a valid height."
2323
fi
2424

25-
sleep 60
25+
sleep 120
2626
done

monitor-eth.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Configuration
4+
MY_ETH_MONITORING_URL="[paste-your-Ethereum-monitoring-URL-here]"
5+
MY_ETH_RPC_URL="http://127.0.0.1:8545" # may need to change this as well; rpc_url is in your config.json!
6+
7+
PREV_HEIGHT=""
8+
echo "Starting Ethereum Height Monitor..."
9+
10+
while true; do
11+
OUTPUT=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' "$MY_ETH_RPC_URL")
12+
CURRENT_HEIGHT=$(echo "$OUTPUT" | python3 -c "import sys, json; print(int(json.load(sys.stdin).get('result', '0'), 16))" 2>/dev/null)
13+
14+
if [[ "$CURRENT_HEIGHT" =~ ^[0-9]+$ ]] && [ "$CURRENT_HEIGHT" -gt 0 ]; then
15+
if [[ "$CURRENT_HEIGHT" != "$PREV_HEIGHT" ]]; then
16+
echo -n "[$(date)] Sending ping for new height $CURRENT_HEIGHT... "
17+
curl -s "$MY_ETH_MONITORING_URL?status=up&ping=&msg=$CURRENT_HEIGHT"
18+
echo
19+
20+
PREV_HEIGHT="$CURRENT_HEIGHT"
21+
fi
22+
else
23+
echo "[$(date)] Warning: Could not retrieve a valid height from $MY_ETH_RPC_URL"
24+
fi
25+
26+
sleep 60
27+
done

0 commit comments

Comments
 (0)