Kiougar / luci-wrtbwmon

Bandwidth tracker for OpenWRT that uses wrtbwmon
https://github.com/pyrovski/wrtbwmon
MIT License
319 stars 56 forks source link

Handling accidental shutdowns #3

Closed captn3m0 closed 7 years ago

captn3m0 commented 7 years ago

I haven't setup a cron yet (as recommended), but I was wondering if the router goes down accidentally (say, on power loss) and I haven't checked the web-interface in a while, then the update/publish cycle won't get called.

Which means that the graphs would be inaccurate on the next reboot.

I think the wrtbmon code already has a lockfile, so running update/publish on a cron shouldn't have any adverse affects either.

Kiougar commented 7 years ago

The /etc/init.d/wrtbwmon enable command enables the wrtbwmon service to run every time the router boots. This basically means the wrtbwmon setup command is run after every startup. This is the only thing needed by the update/publish cycle to work properly.

The update/publish cycle gets called every time you access the Usage page in your router. This ensures that the graphs you will see are the latest ones. AFAIK wrtbwmon uses iptables rules to track bandwidth so you shouldn't see any inaccurate data (whenever you run update the db file used by wrtbwmon is updated to the latest total bandwidth usage).

You are probably right that a cron job would not have adverse effects; however it is not needed. The interval used in the UI is only needed by the speed columns.

captn3m0 commented 7 years ago

I'm still going through the wrtbmon codebase, but still confused.

Where does wrtbmon persist the data between reboots? Wont the iptables rules get reset on a reboot?

captn3m0 commented 7 years ago

Ok, so looks like a reboot doesn't persist.

Yesterday (I had some data for sure):

image

Today:

image

  1. The data clearly reset between the 2 days, so persistence doesn't seem to be working. I'll likely add a cron for this.
  2. I'm still skeptical of the numbers though. Everything started from 0 as soon as I opened the Usage tab. Since the service is enabled, shouldn't it have just dumped whatever was the usage since last boot?
Kiougar commented 7 years ago

I see now what you are trying to do. I don't think the cron job will be able to persist the data. This is because wrtbwmon setup (and subsequently luci-wrtbwmon) uses /tmp/usage.db as the location of the database file. Everything under the /tmp folder will be deleted after every reboot.

In my opinion the above is the correct way of handling data for your router. Storing a db file in any other place than the /tmp directory can quickly fill the memory of your router (making it unresponsive).

However, I'm open to suggestions if you have something in your mind that can "solve" your problem, without adding installation overhead (i.e. tricky configuration steps).

captn3m0 commented 7 years ago

Maybe just having a configurable option on the location of the file. The usage.htm can continue to stay on /tmp.