Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Last active September 7, 2022 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WietseWind/6a362298041660dcd7363de869351378 to your computer and use it in GitHub Desktop.
Save WietseWind/6a362298041660dcd7363de869351378 to your computer and use it in GitHub Desktop.
xrpld monitor
echo 'Install xrpld monitoring'
echo ''
echo 'Please provide some info, if you need to change this, you can do so later in /etc/crontab'
echo ''
echo 'Local host + port with xrpld websocket, e.g. "localhost:6006"'
read host
echo ''
echo 'API Key, e.g. "99b6814ccfb074ad6acb28ae47e5db1a"'
read cred
echo ''
echo 'Host identifier (a-zA-Z0-9), e.g. "FHABCD01"'
read name
echo ''
if command -v apt-get >/dev/null; then
echo 'Detected apt-get, installing dependencies'
apt install -y jq curl
elif command -v yum >/dev/null; then
echo 'Detected yum, installing dependencies'
yum install -y jq curl
else
echo 'Could not detect apt-get or yum, not able to install dependencies "jq" or "curl"'
fi
echo ''
curl -fsSL https://github.com/vi/websocat/releases/download/v1.10.0/websocat.x86_64-unknown-linux-musl > /usr/bin/websocat
chown root:root /usr/bin/websocat
chmod 700 /usr/bin/websocat
echo ''
curl -fsSL https://gist.githubusercontent.com/WietseWind/6a362298041660dcd7363de869351378/raw/9c66f5c37f664c2b50429b2e302e9c2b00092e84/xrpld-monitor.sh > /usr/bin/xrpld-monitor
chown root:root /usr/bin/xrpld-monitor
chmod 700 /usr/bin/xrpld-monitor
echo '' >> /etc/crontab
echo '## xrpld monitoring' >> /etc/crontab
echo '*/3 * * * * root /bin/bash /usr/bin/xrpld-monitor "'$host'" "'$cred'" "'$name'" > /var/log/xrpld-monitor.txt' >> /etc/crontab
echo 'Installed, now running for the first time:'
echo ''
/usr/bin/xrpld-monitor "$host" "$cred" "$name"
echo ''
echo 'Installed. Change config in /etc/crontab if needed.'
echo ''
Run this:
/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/WietseWind/6a362298041660dcd7363de869351378/raw/1d5aeaafeadf05c89c1f817d0af5b0d2b4d0f914/setup.sh)"
#!/bin/bash
## Monitor xrpld, send results to monitoring platform
## Requires `wscat` and `jq`
if [[ $(which jq|wc -l) -lt "1" ]]; then
echo "jq not installed, install with e.g. 'apt install jq'"
exit 1
fi
if [[ $(which curl|wc -l) -lt "1" ]]; then
echo "curl not installed, install with e.g. 'apt install curl'"
exit 1
fi
if [[ "$1" =~ ^.+:[0-9]+$ ]]; then
host=$(echo $1 |sed s/localhost/127.0.0.1/g)
else
echo "Invalid first argument, should be host:port with xrpld websocket"
exit 1
fi
if [[ "$2" =~ ^[a-f0-9]{32}$ ]]; then
cred=$2
else
echo "Invalid second argument, requires: API credential"
exit 1
fi
if [[ "$3" =~ ^[a-zA-Z0-9_.-]{3,30}$ ]]; then
name=$3
else
echo "Invalid third argument, requires: machine name (identification, hostname, ...)"
exit 1
fi
echo "Host: $host"
echo "Cred: $cred"
echo "Name: $name"
echo ""
ret=$(echo '{"command":"server_info"}' | /usr/bin/websocat ws://$host)
echo $ret|jq .result.info.build_version
sleep $(( $RANDOM % 15 ))
curl -X POST -H "x-host: $host" -H "x-cred: $cred" -H "x-name: $name" -H "content-type: application/json" -d "$ret" https://xrpl.ws-stats.com/json/xrpldmon
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment