Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
monitor lnd wallet and channel balances

Short script to monitor walletbalance and channelbalance for LND, and log to csv file for later graphing. You need a working LND, and jq installed.

first setup by editing balances.txt and add a header line


add the following script, edit

# set a date variable in epoch milliseconds
datelog=`/bin/date +%s%3N`

# read wallet balance and channel balance
read walletbalance <<<$(REPLACE-WITH-GOPATH/bin/lncli walletbalance | jq -r -c .total_balance)
read channelbalance <<<$(REPLACE-WITH-GOPATH/bin/lncli channelbalance | jq -r -c .balance)

# output values to csv file
# make sure you set heading row beforehand
# date,walletbalance,channelbalance
echo $datelog,$walletbalance,$channelbalance >> balances.csv

Make the script executable

chmod +x

Add to crontab

crontab -e

0 * * * * /home/YOURUSERNAME/ >/dev/null 2>&1

And it should run hourly from there.

You can cat/tail the file to monitor, or import to a web-hosted graph using highcharts or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.