Skip to content

Instantly share code, notes, and snippets.

@duck1123
Last active December 24, 2018 11:42
Show Gist options
  • Save duck1123/27cd3d4e1a89894ca55f6e6a287f5540 to your computer and use it in GitHub Desktop.
Save duck1123/27cd3d4e1a89894ca55f6e6a287f5540 to your computer and use it in GitHub Desktop.
BTCD restart script and graphing
# Output W3C Scalable Vector Graphics
set terminal svg
# Read comma-delimited data from file
set datafile separator comma
# Set graph title
set title 'Block Download Progress'
# Set label of x-axis
set xlabel 'Date'
set xdata time
set timefmt '%Y-%m-%dT%H:%M:%S-05:00'
# Set label of y-axis
set ylabel 'Block Height'
# Use a line graph
set style data line
set format x '%H:%M'
set autoscale y
set samples 200
# unset xtics
# Plot data from a file, with extra notes below:
#
# for [i=2:5] Loop for values of i between 2 and 5 (inclusive)
# using i:xtic(1) Plot column i using tick labels from column 1
# title columnheader Use the column headers (first row) as titles
# linewidth 4 Use a wider line width
#
plot '/keybase/public/duck1123/blocks.csv' using 1:2 title 'Blocks' linewidth 4
#!/bin/bash
# set -x
POST_INIT_SYNC_DELAY=120
POLL_DELAY=60
STALL_THRESHOLD=5
if [ -z `pidof btcd` ]; then
echo "Starting btcd"
nohup btcd &
sleep $POST_INIT_SYNC_DELAY
fi
stalls=0
while true; do
start=`btcctl getinfo | jq -r .blocks`
sleep $POLL_DELAY
end=`btcctl getinfo | jq -r .blocks`
echo "Processed $((end - start)) blocks in the last $POLL_DELAY seconds"
echo "$(date -Iseconds),${end}" >> /keybase/public/duck1123/blocks.csv
gnuplot /keybase/public/duck1123/blocks.plot > /keybase/public/duck1123/blocks.svg
if [[ "$start" == "$end" ]]; then
if (( stalls > STALL_THRESHOLD )); then
echo "Too many stalls detected. Restarting btcd..."
kill `pidof btcd`
sleep 10
nohup btcd &
stalls=0
else
syncnode=`btcctl getpeerinfo | jq -r '.[] | select(.syncnode == true) | .addr' | cut -f1 -d:`
if [ -z "$syncnode" ]; then
echo "Stall detected, but no syncnode found. Restarting btcd..."
kill `pidof btcd`
sleep 10
nohup btcd &
stalls=0
else
echo "Stall detected! Evicting potentially bad node $syncnode"
btcctl node disconnect $syncnode
stalls=$(( stalls + 1 ))
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment