How to get some nice statistics for your RasPi (or BananaPi) Bitcoin Full Node:
Assumptions:
- bitcoind is installed and running
- HDD (or SSD) is mounted at /hdd
- logged in as user "pi"
update your package lists
sudo apt-get update
install webserver (in this case, nginx)
sudo apt-get install nginx php5-fpm
open nginx config
sudo nano /etc/nginx/nginx.conf
edit the following parts
access_log /hdd/www/log/access.log;
error_log /hdd/www/log/error.log;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
create a webserver root-directory on your HDD
mkdir /hdd/www/html
create default virtual host config
sudo nano /etc/nginx/conf.d/pinode.conf
#Default Server Configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
root /hdd/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
autoindex off;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
#Deny access to .htaccess files
location ~ /\.ht {
deny all;
}
}
restart nginx
sudo service nginx restart
install vnstat
sudo apt-get install vnstat vnstati php5-gd
create image-directory on your HDD
mkdir /hdd/www/html/images
create vnstat script
nano ~/vnstati.sh
#!/bin/bash
vnstati -vs -ne -nh -i eth0 -o /hdd/www/html/images/summary.png -ru 0
vnstati -d -ne -nh -i eth0 -o /hdd/www/html/images/daily.png -ru 0
vnstati -t -ne -nh -i eth0 -o /hdd/www/html/images/top10.png -ru 0
vnstati -m -ne -nh -i eth0 -o /hdd/www/html/images/monthly.png -ru 0
make it executable
chmod +x ~/vnstati.sh
open your crontab
crontab -e
and add this at the bottom
# updating every 5 minutes
*/5 * * * * nice /home/pi/vnstati.sh >/dev/null 2>&1
install rrdtool
sudo apt-get install rrdtool
create directory for rrd databases
mkdir /hdd/rrd
install jq (a command-line JSON processor)
sudo apt-get install jq
create some scripts to draw pretty graphs using rrdtool
nano ~/connections.sh
#!/bin/bash
# connections.sh - Bitcoin connection stats
rrdtool=/usr/bin/rrdtool
db=/hdd/rrd/connections.rrd
img=/hdd/www/html/images
if [ ! -e $db ]
then
$rrdtool create $db \
--step 300 \
DS:connections:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:3:672 \
RRA:AVERAGE:0.5:12:744 \
RRA:AVERAGE:0.5:72:1480
fi
n=`/usr/local/bin/bitcoin-cli getconnectioncount`
$rrdtool update $db -t connections N:"$n"
for period in day week month year
do
$rrdtool graph $img/connections-$period.png -s -1$period \
-t "Connections last $period" -z \
-c "BACK#FFFFFF" -c "SHADEA#FFFFFF" -c "SHADEB#FFFFFF" \
-c "MGRID#AAAAAA" -c "GRID#CCCCCC" -c "ARROW#333333" \
-c "FONT#333333" -c "AXIS#333333" -c "FRAME#333333" \
-h 134 -w 543 -l 0 -a PNG -v "#" \
DEF:connections=$db:connections:AVERAGE \
VDEF:max=connections,MAXIMUM \
VDEF:avg=connections,AVERAGE \
VDEF:lst=connections,LAST \
"COMMENT: \l" \
"COMMENT: " \
"COMMENT: " \
"COMMENT:Last " \
"COMMENT:Average " \
"COMMENT:Maximum " \
"COMMENT: \l" \
"COMMENT: " \
"AREA:connections#92CF00:Connections " \
"LINE1:connections#3F5A00" \
"GPRINT:lst:%2.0lf " \
"GPRINT:avg:%2.0lf " \
"GPRINT:max:%2.0lf \l" > /dev/null
done
nano ~/mempool.sh
#!/bin/bash
# mempool.sh - Bitcoin mempool stats
rrdtool=/usr/bin/rrdtool
db=/hdd/rrd/mempool.rrd
img=/hdd/www/html/images
if [ ! -e $db ]
then
$rrdtool create $db \
--step 300 \
DS:mempool:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:3:672 \
RRA:AVERAGE:0.5:12:744 \
RRA:AVERAGE:0.5:72:1480
fi
#n=`/usr/local/bin/bitcoin-cli getrawmempool | jq length`
n=`/usr/local/bin/bitcoin-cli getmempoolinfo | jq '.size'`
$rrdtool update $db -t mempool N:"$n"
for period in day week month year
do
$rrdtool graph $img/mempool-$period.png -s -1$period \
-t "Mempool Tx last $period" -z \
-c "BACK#FFFFFF" -c "SHADEA#FFFFFF" -c "SHADEB#FFFFFF" \
-c "MGRID#AAAAAA" -c "GRID#CCCCCC" -c "ARROW#333333" \
-c "FONT#333333" -c "AXIS#333333" -c "FRAME#333333" \
-h 134 -w 543 -l 0 -a PNG -v "TX" \
DEF:mempool=$db:mempool:AVERAGE \
VDEF:max=mempool,MAXIMUM \
VDEF:avg=mempool,AVERAGE \
VDEF:lst=mempool,LAST \
"COMMENT: \l" \
"COMMENT: " \
"COMMENT: " \
"COMMENT:Last " \
"COMMENT:Average " \
"COMMENT:Maximum " \
"COMMENT: \l" \
"COMMENT: " \
"AREA:mempool#92CF00:Mempool Tx " \
"LINE1:mempool#3F5A00" \
"GPRINT:lst:%2.0lf " \
"GPRINT:avg:%2.0lf " \
"GPRINT:max:%2.0lf \l" > /dev/null
done
nano ~/memory.sh
#!/bin/bash
# memory.sh - Memory usage stats
rrdtool=/usr/bin/rrdtool
db=/hdd/rrd/memory.rrd
# mempool-ram db added
mpdb=/hdd/rrd/mempool-ram.rrd
img=/hdd/www/html/images
if [ ! -e $db ]
then
$rrdtool create $db \
--step 300 \
DS:usage:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:3:672 \
RRA:AVERAGE:0.5:12:744 \
RRA:AVERAGE:0.5:72:1480
fi
# mempool db creation added
if [ ! -e $mpdb ]
then
$rrdtool create $mpdb \
--step 300 \
DS:mempoolmb:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:3:672 \
RRA:AVERAGE:0.5:12:744 \
RRA:AVERAGE:0.5:72:1480
fi
$rrdtool update $db -t usage N:`free -b |grep cache:|cut -d":" -f2|awk '{print $1}'`
# mempool db update added
n=`/usr/local/bin/bitcoin-cli getmempoolinfo | jq '.usage'`
$rrdtool update $mpdb -t mempoolmb N:"$n"
# mempool added to graph
for period in day week month year
do
$rrdtool graph $img/memory-$period.png -s -1$period \
-t "Memory usage last $period" -z \
-c "BACK#FFFFFF" -c "SHADEA#FFFFFF" -c "SHADEB#FFFFFF" \
-c "MGRID#AAAAAA" -c "GRID#CCCCCC" -c "ARROW#333333" \
-c "FONT#333333" -c "AXIS#333333" -c "FRAME#333333" \
-h 134 -w 543 -l 0 -a PNG -v "RAM" \
DEF:usage=$db:usage:AVERAGE \
DEF:mempoolmb=$mpdb:mempoolmb:AVERAGE \
VDEF:min=usage,MINIMUM \
VDEF:max=usage,MAXIMUM \
VDEF:avg=usage,AVERAGE \
VDEF:lst=usage,LAST \
VDEF:mpmin=mempoolmb,MINIMUM \
VDEF:mpmax=mempoolmb,MAXIMUM \
VDEF:mpavg=mempoolmb,AVERAGE \
VDEF:mplst=mempoolmb,LAST \
"COMMENT: \l" \
"COMMENT: " \
"COMMENT: " \
"COMMENT:Minimum " \
"COMMENT:Maximum " \
"COMMENT:Average " \
"COMMENT:Last \l" \
"COMMENT: " \
"AREA:usage#92CF00:Usage " \
"LINE1:usage#3F5A00" \
"GPRINT:min:%5.1lf %sB " \
"GPRINT:max:%5.1lf %sB " \
"GPRINT:avg:%5.1lf %sB " \
"GPRINT:lst:%5.1lf %sB \l" \
"COMMENT: " \
"AREA:mempoolmb#8AD3F1:Mempool " \
"LINE1:mempoolmb#49BEEF" \
"GPRINT:mpmin:%5.1lf %sB " \
"GPRINT:mpmax:%5.1lf %sB " \
"GPRINT:mpavg:%5.1lf %sB " \
"GPRINT:mplst:%5.1lf %sB \l" > /dev/null
done
nano ~/network.sh
#!/bin/bash
# network.sh - Network usage stats
rrdtool=/usr/bin/rrdtool
db=/hdd/rrd/network.rrd
img=/hdd/www/html/images
if=eth0
if [ ! -e $db ]
then
$rrdtool create $db \
--step 300 \
DS:in:DERIVE:600:0:U \
DS:out:DERIVE:600:0:U \
RRA:AVERAGE:0.5:1:576 \
RRA:AVERAGE:0.5:6:672 \
RRA:AVERAGE:0.5:24:732 \
RRA:AVERAGE:0.5:144:1460
fi
n=`/sbin/ifconfig $if |grep bytes|cut -d":" -f2|cut -d" " -f1`:`/sbin/ifconfig $if |grep bytes|cut -d":" -f3|cut -d" " -f1`
$rrdtool update $db -t in:out N:"$n"
for period in day week month year
do
$rrdtool graph $img/network-$period.png -s -1$period \
-t "eth0 traffic last $period" -z \
-c "BACK#FFFFFF" -c "SHADEA#FFFFFF" -c "SHADEB#FFFFFF" \
-c "MGRID#AAAAAA" -c "GRID#CCCCCC" -c "ARROW#333333" \
-c "FONT#333333" -c "AXIS#333333" -c "FRAME#333333" \
-h 134 -w 543 -l 0 -a PNG -v "B/s" \
DEF:in=$db:in:AVERAGE \
DEF:out=$db:out:AVERAGE \
VDEF:minin=in,MINIMUM \
VDEF:minout=out,MINIMUM \
VDEF:maxin=in,MAXIMUM \
VDEF:maxout=out,MAXIMUM \
VDEF:avgin=in,AVERAGE \
VDEF:avgout=out,AVERAGE \
VDEF:lstin=in,LAST \
VDEF:lstout=out,LAST \
VDEF:totin=in,TOTAL \
VDEF:totout=out,TOTAL \
"COMMENT: \l" \
"COMMENT: " \
"COMMENT:Minimum " \
"COMMENT:Maximum " \
"COMMENT:Average " \
"COMMENT:Last " \
"COMMENT:Total \l" \
"COMMENT: " \
"AREA:out#92CF00:Out " \
"LINE1:out#3F5A00" \
"GPRINT:minout:%5.1lf %sB/s " \
"GPRINT:maxout:%5.1lf %sB/s " \
"GPRINT:avgout:%5.1lf %sB/s " \
"GPRINT:lstout:%5.1lf %sB/s " \
"GPRINT:totout:%5.1lf %sB \l" \
"COMMENT: " \
"AREA:in#8AD3F1:In " \
"LINE1:in#49BEEF" \
"GPRINT:minin:%5.1lf %sB/s " \
"GPRINT:maxin:%5.1lf %sB/s " \
"GPRINT:avgin:%5.1lf %sB/s " \
"GPRINT:lstin:%5.1lf %sB/s " \
"GPRINT:totin:%5.1lf %sB \l" > /dev/null
done
nano ~/cpuload.sh
#!/bin/bash
# cpuload.sh - CPU Load stats
rrdtool=/usr/bin/rrdtool
db=/hdd/rrd/cpuload.rrd
img=/hdd/www/html/images
if [ ! -e $db ]
then
$rrdtool create $db \
--step 300 \
DS:load1:GAUGE:600:0:U \
DS:load5:GAUGE:600:0:U \
DS:load15:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:576 \
RRA:AVERAGE:0.5:6:672 \
RRA:AVERAGE:0.5:24:732 \
RRA:AVERAGE:0.5:144:1460
fi
LOAD=$(awk '{print $1":"$2":"$3}' < /proc/loadavg)
$rrdtool update $db -t load1:load5:load15 N:$LOAD
for period in day week month year
do
$rrdtool graph $img/cpuload-$period.png -s -1$period \
-t "CPU Load last $period" -z \
-c "BACK#FFFFFF" -c "SHADEA#FFFFFF" -c "SHADEB#FFFFFF" \
-c "MGRID#AAAAAA" -c "GRID#CCCCCC" -c "ARROW#333333" \
-c "FONT#333333" -c "AXIS#333333" -c "FRAME#333333" \
-h 134 -w 543 -l 0 -a PNG -v "CPU" \
DEF:load1=$db:load1:AVERAGE \
DEF:load5=$db:load5:AVERAGE \
DEF:load15=$db:load15:AVERAGE \
VDEF:lst1=load1,LAST \
VDEF:lst5=load5,LAST \
VDEF:lst15=load15,LAST \
VDEF:avg1=load1,AVERAGE \
VDEF:avg5=load5,AVERAGE \
VDEF:avg15=load15,AVERAGE \
VDEF:max1=load1,MAXIMUM \
VDEF:max5=load5,MAXIMUM \
VDEF:max15=load15,MAXIMUM \
"COMMENT: " \
"COMMENT: " \
"COMMENT: " \
"COMMENT:Last " \
"COMMENT:Average " \
"COMMENT:Maximum \l" \
"COMMENT: " \
"COMMENT: " \
"AREA:load1#92CF00:1m " \
"LINE1:load1#3F5A00BB" \
"GPRINT:lst1: %1.2lf " \
"GPRINT:avg1: %1.2lf " \
"GPRINT:max1: %1.2lf \l" \
"COMMENT: " \
"COMMENT: " \
"LINE3:load5#49BEEFBB:5m " \
"GPRINT:lst5: %1.2lf " \
"GPRINT:avg5: %1.2lf " \
"GPRINT:max5: %1.2lf \l" \
"COMMENT: " \
"COMMENT: " \
"LINE2:load15#C3E9FA:15m " \
"GPRINT:lst15: %1.2lf " \
"GPRINT:avg15: %1.2lf " \
"GPRINT:max15: %1.2lf \l" > /dev/null
done
don't forget to make them executable and to create some cronjobs to run those scripts (just like you did for vnstati.sh)
and finally
create a website in your webservers root-directory to show your pretty graphs
nano /hdd/www/html/index.html
<!doctype html>
<html>
<head>
<title>Bitcoin Full Node Statistics</title>
</head>
<body>
<center>
<font size="4">Summary</font></br>
<img src="images/summary.png" alt="summary"/></br>
<font size="4">Daily Traffic</font></br>
<img src="images/daily.png" alt="daily traffic"/></br>
<font size="4">Monthly Traffic</font></br>
<img src="images/monthly.png" alt="monthly traffic"/></br>
<font size="4">Top 10</font></br>
<img src="images/top10.png" alt="top 10 traffic days"/></br>
</br>
<img src="images/connections-day.png" alt="connections 24h"/></br>
<img src="images/mempool-day.png" alt="mempool tx 24h"/></br>
<img src="images/memory-day.png" alt="memory 24h"/></br>
<img src="images/network-day.png" alt="network 24h"/></br>
<img src="images/cpuload-day.png" alt="cpu load 24h"/></br>
</br>
</center>
</body>
</html>
that's it, you're done
now check out your stats at http://ip-of-your-node/
back to stats