VnStat corrupt db

When I manually restart the wan-pppoe interface VnStat readings for the day of the restart gets corrupted.
18-17-21-03
it was 350 MB before restarting the wan-pppoe interface and became 4.12 GB after, sometimes it happens to both rx and tx values for that day and sometimes either.
I recreated the db and tested again and same thing happens every time.
I am using vnstat 1.18 with OpenWrt 18.06.2.
Used nlbwmon as well before vnstat but stopped because the cpu usage reachs 100% after few days and the only way to fix it was to kill the nlbwmon process and that was the reason I switched to vnstat.
Now vnstat comes with it's own set of problems.

This is typical issue for most bandwidth monitoring programs.
When vnstat queries the network interface for bytes in and bytes out, it gets a response let's say 100 bytes in and 200 bytes out. Normally the next time vnstat asks, it should get a response higher (150 in, 260 out) than the previous, subtract the previous value from the current and calculate like this the amount to display (50 in, 60 out).
If you restart the interface, the counters get restarted too and start from zero. So the next time vnstat queries the interface for counters and receives a lower value it will assume that the counter reached the maximum value and started from zero again. That is why you see this huge difference.

2 Likes

Seems logical, but this doesn't happen when I restart the whole router not just the interface which resets the counters a swell and still vnstat readings aren't affected by the router restart.
Any ideas on how to fix this?
I see that there is a newer version released of vnstat 2.1 which maybe have a fix for this problem. any idea if we are going to see it included in openwrt packages?

When you restart the router, vnstat does not have any previous reading of the counter.

1 Like

A couple years back, I had the same issue. Always a sudden jump and I think it is about 4Gb. I forgot which version of vnstat. After many attempts, I tried a lazy work around which worked for me at least and hope it helps you as well.

I disabled the vnstat service

/etc/init.d/vnstat stop
/etc/init.d/vnstat disable

Put a script in rc.local to run vntstat (not as daemon) calling your interface before the exit 0 line.

vnstat -i wan-pppoe --enable

Add a crond schedule to do vnstat -u every interval as you desired, so the database gets updated.

Not if you are saving the db to usb flash.

Thank you, will give it a try.

What I mean is that when vnstat boots, it knows it is booting, and does not try to compare the counter from the interface with any previous reading.


According to the above link issue seems to be fixed in vnStat 2.2 beta1
any idea how to convert the vnstat latest git commit branch into a working openwrt package?