First setup Debian system package repo (Ubiquiti Support and Help Center). For EdgeOS 2.x this will be the repo for Debian 9 "Stretch".
$ configure
# set system package repository stretch components 'main contrib non-free'
# set system package repository stretch distribution stretch
# set system package repository stretch url http://http.us.debian.org/debian
# commit ; save
Run apt-get update and install vnstat:
$ sudo apt-get update
$ sudo apt-get install vnstat vnstati
DO NOT UNDER ANY CIRCUMSTANCES USE apt-get upgrade
: IT WILL BREAK THINGS!
Modify /etc/vnstat.conf as necessary. In Debian "Stretch" vnstat is a systemd service.
Restart the service:
$ sudo systemctl restart vnstat
Let the vnstat service run for a few hours and then do:
$ vnstat -h
This should show stats for that last few hours.
Create a folder "~/vnstat" in admin's home and then backup the vnstat db with:
$ vnstat --exportdb > ~/vnstat/vnstat.txt
I run this in the admin user's cron every night, and also reguarly download it to my home backup server (along with the router /config/config.boot file).
During the upgrade of an Edgerouter's firmware all added packages are removed, and all home directories wiped clean. As a result, the vnstat package will need to be installed after an update. I also take regular backups of the vnstat.txt file so I can re-import its data after a firmware upgrade (sudo vnstat --importdb ./vnstat.txt -i eth0 --force
).
"EdgeRouter - Add Debian Packages to EdgeOS". Ubiquiti Support and Help Center, https://help.ui.com/hc/en-us/articles/205202560-EdgeRouter-Add-Debian-Packages-to-EdgeOS.
Stanislav Khoromov. "vnstat on EdgeRouter". Useful Snippets, 14 July 2019, https://snippets.khromov.se/vnstat-on-edgerouter-historical-bandwidth-monitoring-and-graphical-dashboard-tutorial/.
Brian Wilson (bdwilson). "vnstat-edgerouter". GitHub, 18 April 2021, https://github.com/bdwilson/vnstat-edgerouter.