-
Notifications
You must be signed in to change notification settings - Fork 1
/
bridge_mon.sh
executable file
·73 lines (58 loc) · 1.77 KB
/
bridge_mon.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
pushd `dirname ${0}` >/dev/null || exit 1
# Get node variables
source ./vars.sh
# Set default curl timeout
TO=2
# Get timestamp
now=$(date +%s%N)
logentry="celestia_bridge"
#if [ -n "${COS_VALOPER}" ]; then logentry=$logentry",valoper=${COS_VALOPER}"; fi
ver_string=$(${BRIDGE_BINARY} version | grep "Semantic version")
IFS=' ' read -ra words <<< "$ver_string"
version="${words[-1]}"
if [ -z "${version}" ]; then version="unknown"; fi
logentry="$logentry version=\"$version\""
# health is great by default
health=0
if [ -z "$CELESTIA_NODE_AUTH_TOKEN" ];
then
echo "ERROR: can't find auth token">&2 ;
health=1
echo "$logentry,health=$health $now"
else
if [ -z "$BRIDGE_RPC" ];
then
echo "ERROR: can't find BRIDGE_RPC value">&2 ;
health=2
echo "$logentry,health=$health $now"
else
# Get bridge height
height=$(curl -X POST -s \
--connect-timeout ${TO} \
-H "Authorization: Bearer $CELESTIA_NODE_AUTH_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":0,"method":"header.LocalHead","params":[]}' \
${BRIDGE_RPC} | jq -r .result.header.height)
if [ -z "${height}" ]
then
echo "ERROR: bridge height return empty string">&2 ;
health=3
bridge_height=-1
fi
logentry="$logentry,bridge_height=$height"
status=$(curl --connect-timeout ${TO} -s ${BRIDGE_REF_RPC_NODE}/status)
if [ -z "$status" ];
then
echo "ERROR: can't connect to reference RPC">&2 ;
health=4
else
# Get block height
ref_height=$(jq -r '.result.sync_info.latest_block_height' <<<$status)
let "bridge_lag = $height - $ref_height"
logentry="$logentry,bridge_lag=$bridge_lag"
fi
echo "$logentry,health=$health $now"
fi # rpc var check
fi # token check
popd > /dev/null || exit 1