Bitcoin Core running on Docker with Prometheus and Grafana
- Motivation
- Notes
- Pre Requisites
- Boot Monitoring Stack
- Boot Bitcoin Stack
- Monitoring Screenshots
- Bitcoin RPC
- Access Grafana
- Resources
The idea of this project is to spin up a bitcoin core node on a docker container, with container metrics as well as prometheus metrics and visualised with Grafana.
This is a bitcoin testnet and has been setup with weak authentication and allows public access should the node be in a public subnet.
The bitcoin stack has a dependency on the monitoring network, so you would need to boot the monitoring stack:
cd observability
docker-compose up -d
Change back to the root project:
cd ../
Build the project:
docker-compose build
Start the project:
docker-compose up -d
Bitcoin Exporter Dashboard:
Bitcoin Container Dashboard:
Bitcoin Container Logs:
getblockchaininfo
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getblockchaininfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/
listwallets
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "listwallets", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/
createwallet
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "createwallet", "params": ["test-wallet"]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/
loadwallet
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "loadwallet", "params": ["test-wallet"]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/
getwalletinfo
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getwalletinfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet
getnewaddress
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getnewaddress", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet
getaddressesbylabel
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getaddressesbylabel","params": [""]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet
getaddressinfo
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getaddressinfo", "params": ["_address_"]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet
getbalance
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getbalance", "params": ["*", 6]}' -H 'content-type: text/plain;’' http://127.0.0.1:18332/wallet/test-wallet
getbalances
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getbalances", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet
listtransactions
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "listtransactions", "params": ["*"]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet
sendtoaddress
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "sendtoaddress", "params":["_to_address_", 0.01]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/wallet
To see if a node is out of sync, you can look at blocks vs headers in getblockchaininfo
but to see how long its out of sync:
median=$(curl -s -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getblockchaininfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.result.mediantime')
seconds=$(echo $(date +%s) - $median | bc )
echo $((seconds/86400))" days "$(date -d "1970-01-01 + $seconds seconds" "+%H hours %M minutes %S seconds")
1525 days 10 hours 41 minutes 27 seconds
To view the latest blockinfo:
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getblockcount", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet | jq -r '.result'
1384738
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getblockhash", "params": [1384738]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet | jq -r '.result'
00000000000000485f3ab8524134f079b472456a182c22917647abcd04532893
curl -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getblock", "params": ["00000000000000485f3ab8524134f079b472456a182c22917647abcd04532893"]}' -H 'content-type: text/plain;' http://127.0.0.1:18332/wallet/test-wallet | jq .
{
"result": {
"hash": "00000000000000485f3ab8524134f079b472456a182c22917647abcd04532893",
"confirmations": 9299,
"strippedsize": 998027,
"size": 998606,
"weight": 3992687,
"height": 1384738,
"version": 536870912,
"versionHex": "20000000",
"merkleroot": "2bd00b9b1ad746256414fcdb6ebeb4e872a2175cf2cda9986aeacef7e793cd8d",
"tx": [
"af319e276e33123f62980b43eb0265772384f433f49dcdbeeef8e6319c806a70",
"68c26ce2ad7389a71a21d4d037436d73f9dce125488edf85451fda1100a9eb29",
...
To see how many blocks still have to sync:
headers=$(curl -s -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getblockchaininfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.result.headers')
blocks=$(curl -s -u "bitcoinrpc:bitcoinpass" -d '{"jsonrpc": "1.0", "id": "docker-bitcoind", "method": "getblockchaininfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.result.blocks')
echo "blocks=$blocks / headers=$headers"
echo "blocks to sync:"
echo "$headers - $blocks" | bc
More info:
Access grafana on http://localhost:3000
Documentation:
Testnet Faucet:
Testnet Blockexplorers: