Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active July 24, 2023 05:20
Show Gist options
  • Save plembo/668de6b83df51dfc2f3d360bfb0750e4 to your computer and use it in GitHub Desktop.
Save plembo/668de6b83df51dfc2f3d360bfb0750e4 to your computer and use it in GitHub Desktop.
vnstat on EdgeRouter 4

vnstat on EdgeRouter 4

Installation

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!

Configuration

Modify /etc/vnstat.conf as necessary. In Debian "Stretch" vnstat is a systemd service.

Restart the service:

$ sudo systemctl restart vnstat

Test

Let the vnstat service run for a few hours and then do:

$ vnstat -h

This should show stats for that last few hours.

Backup

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).

After router firmware updates

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).

References

"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.

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