Skip to content

Instantly share code, notes, and snippets.

@bretton
Last active January 24, 2018 21:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bretton/3248f76e89cc1579da8ce98dab0f8e92 to your computer and use it in GitHub Desktop.
Save bretton/3248f76e89cc1579da8ce98dab0f8e92 to your computer and use it in GitHub Desktop.
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

date,walletbalance,channelbalance

add the following script, edit lndbalances.sh

#!/bin/bash
# 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 lndbalances.sh

Add to crontab

crontab -e

0 * * * * /home/YOURUSERNAME/lndbalances.sh >/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