So. I know nlbwmon is saving to RAM by default to avoid flash wear. This is not about that.
I connected a USB flash drive to the router, and changed nlbwmon settings to save the file there. Still, whenever the router reboots, all data for the current accounting period gets reset. Older accounting periods are still there, and completely fine.
My main suspicion is that it has to do with system time, i.e because nlbwmon starts before ntp, the database files 'from the future' gets deleted. My question is, how can I prevent that from happening?
ntp has to wait for pppoe link to be up, so even changing nlbwmon to 99, it will still load before ntp sync.
current time gets save to disk on shutdown and loaded on reboot - so the problem will only happen on unexpected power loss.
even pulling the plug now will not help test this... I need to wait a few days until the saved time is older than the current accounting period.
according to the log, vnstat does act to migitate this problem, so why can't nlbwmon do it to?
Wed Jan 4 13:56:17 2023 daemon.info vnstatd[1581]: Info: Latest database update is in the future (db: 2023-01-04 13:57:00 > now: 2023-01-04 13:56:17). Giving the system clock up to 5 minutes to sync before continuing.
Wed Jan 4 13:58:10 2023 daemon.info vnstatd[1581]: Info: Latest database update is no longer in the future (db: 2023-01-04 13:57:00 <= now: 2023-01-04 13:58:10), continuing.
You can use an internal lan ntp if you don't want to wait for pppoe.
You can change the startup sequence to start nlbwmon after ntp.
You can add some sleep XX inside the script to delay it even more.
If there's power loss to the whole house (or the whole neighborhood), the local lan ntp will be down too, and may take longer than openwrt to start up.
Changing the startup sequence won't help, as I mentioned.
adding sleep somewhere might or might not help... but I have no idea where it can be safely added, and to what effect.
Allow me to disagree. Sure, the database entries are not date dependent, but the accounting periods themselves are (and so the separate database files). If the current system time is set to before the latest database file, then nlbwmon will update a previous one. Then when time rights itself (by ntp), nlbwmon will assume a new accounting period had started and create the latest database from scratch - losing all my data.
it's set to 6h for a while now. still I lost 4 days of data after the last power failure.
I have both set for a while too. This is a completely different issue.
Faced this issue . Looking into code to see what could be the reason. First step is to probably add logging and see which part of code decides to delete data for current accounting period.