Skip to content

Instantly share code, notes, and snippets.

@tyzbit
Last active January 25, 2018 06:50
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 tyzbit/ee3d07ec5a1c80379dcb2d9ec24c54f5 to your computer and use it in GitHub Desktop.
Save tyzbit/ee3d07ec5a1c80379dcb2d9ec24c54f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# date,wallet_balance,channel_balance,total_capacity,remote_balance,unsettled_balance,sent_balance,received_balance,off_chain_updates,active_nodes,inactive_nodes,pending_channels,limbo_channels,pending_open,pending_close,pending_force_close
lncli="/home/lightning/gocode/bin/lncli"
file="~/lightning-monitor.csv"
# Date
newline="$(date +%s%3N)"
#set the separator to not be space
IFS=""
# Commands that require walletbalance
command="walletbalance"
filters=(".total_balance")
for filter in ${filters[@]}; do
newline=$newline,$($lncli $command | jq -r -c "$filter")
done
# Commands that require channelbalance
command="listchannels"
filters=(
'.channels | map(.capacity|tonumber) | add'
'.channels | map(.remote_balance|tonumber) | add'
'.channels | map(.unsettled_balance|tonumber) | add'
'.channels | map(.total_satoshis_sent|tonumber) | add'
'.channels | map(.total_satoshis_received|tonumber) | add'
'.channels | map(.num_updates|tonumber) | add'
'[ .channels | .[] | select(.active==true) ] | length'
'[ .channels | .[] | select(.active==false) ] | length'
)
for filter in ${filters[@]}; do
newline=$newline,$($lncli $command | jq -r -c "$filter")
done
echo $newline >> $file
@tyzbit
Copy link
Author

tyzbit commented Jan 25, 2018

Before running, adjust the location you want to save the stats at the top of the script, and then create that file with this content:

date,wallet_balance,channel_balance,total_capacity,remote_balance,unsettled_balance,sent_balance,received_balance,off_chain_updates,active_nodes,inactive_nodes,pending_channels,limbo_channels,pending_open,pending_close,pending_force_close

Idea inspired by @bretton 's gist here https://gist.github.com/bretton/3248f76e89cc1579da8ce98dab0f8e92.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment