I discovered that vnstat had had a major release when I was trying to run some commands listed in the online man page, and they weren't working. Turns out version 2 came out last month, and I was still on the old Ubuntu version 1.14 from erm … 3 years ago.
The new version uses an sqlite3 database to keep the data, so it imports this from the old files when the new version first runs. One of the reasons why I wanted to upgrade is that the new "count" parameter lets you specify how many days, months, weeks of data to display.
Took me a few goes to get this to work. We're compiling this so install the dependencies first.
# install the dependencies first as root or sudo apt install sqlite3 libsqlite3-dev # find somewhere to put it mkdir code cd code wget https://humdi.net/vnstat/vnstat-latest.tar.gz tar -zxf vnstat-latest.tar.gz cd vnstat-2.0 # now configure. Specifying these dirs makes it work with # the same config as the previous version ./configure --prefix=/usr --sysconfdir=/etc make # Then now uninstall the old version, and build and # install the new version (as root or sudo) apt remove vnstat make install
OK if you didn't get any errors, then you should be good to test it out. If you did get errors, try installing the dependencies listed. You can test to see if it works with 'vnstatd -d'. This starts the daemon. It should at this point give you a message that its imported the database. NB vnstatd not vnstat to start the daemon. Now vnstat should work to give you stats.
One final thing is to get it running with systemctl. When you uninstalled vnstat with apt it 'masked' the service file. You need to perform the following to get it back.
systemctl unmask vnstat.service systemctl enable vnstat.service #If that doesn't work, then you might need to copy the example file over. # But on my system they were the same apart from the name (vnstatd.service vs vnstat.service) cd code/vnstat-2.0/examples/systemd # where you untarred the source cp vnstat.service /etc/systemd/system/ systemctl enable vnstat.service