vortex-5 / ddwrt-bwmon

An Individual Bandwidth Monitor For DD-WRT
171 stars 37 forks source link

Persistent Storage #15

Closed Deus-Rex closed 8 years ago

Deus-Rex commented 8 years ago

Thanks for the software, comes in real handy at my house. It's nice to be able to detect the data hogs in my family. Anyway...

When the router is rebooted, the bandwidth being monitored is reset. If I have external storage attached, is there an implementation I could use to achieve persistent storage? I'm not sure if this is by design or my fault. Either would make sense. :]

Also, I'd like to change the rates to bytes as well. I changed it a while ago but again, it didn't persist. I have an idea on how to remedy that, though I'd like to bring it up to your attention since I think more people may like this as well.

Again, thanks. If you have bitcoin, I'd love to send you money for a beer.

vortex-5 commented 8 years ago

The backup.sh script is designed to help persist data.

Normally the backup script only backs up once every 15 min the reason for this is because flash drives have limited writes so this is done in effort to extend the write time.

Persistent storage has been available since version 1.1 and is working on the current 1.6.1

Please ensure your flash drive is mounted into /jffs/ and that the bwmon folder is writable. Under normal use the backup script will try and persist backed up data into bwmon/data/usage-stats.js I believe is what it's called.

In terms of changing the bandwidth rates to bytes I don't have that feature built in right now but it should be as simple as modifying the function get rate in the code for bwmon.js if you understand javascript.

You can somewhat simply convert the bandwidth rate from bits to bytes.

The reason bits are used is because for most people their ISP gives their speed in mega bits per second so it's easy to figure out how close to your capacity you are when you use that measurement vs 1.25MB/s = 10Mbps

That said there's no reason I can't include a toggle to show MB/s and KB/s B/s measurements as an alternative but that will have to be included in the next version unless someone forks it and takes it upon themselves to write that routine :-)

Deus-Rex commented 8 years ago

I found that the problem for me is that there is no /bwmon/data/ folder. When I manually run backup.sh, it returns the following error: cp: can't create '/jffs/bwmon/data/usage.js': No such file or directory

I had a look in the code, and this part from start.sh caught my eye:

# Load database
if [ -d $SCRIPT_DIR/data ]
then
    mkdir $SCRIPT_DIR/data
fi

[I think that] This statement creates the data folder only when the data folder already exists, so I changed it to

if [ ! -d $SCRIPT_DIR/data ]
then
    mkdir $SCRIPT_DIR/data
fi

and wham, the folder was created, and then a backup.sh later, I now have a populated usage.js file.

I've never done a pull request or anything before - I'm a noob at Git and programming in general. As cool as it would have been for me to do one, only adding 1 character would be weird, haha. I'm hoping I haven't misunderstood something here and further broken something. I'm awaiting my bricked router any minute now. :p

As for the network speed, I fully understand. It makes sense for it to be in bits, I agree. I was just putting an idea forward just in case anybody else desired it as well. Despite the ISPs marketing in bits, I will always think and speak in bytes, as it's what I see everyday on the net.

I'm busy working on a project for Uni at the moment, but if I get time after that, I would probably try and tackle it. My web dev skills are near non-existent and everything I've managed to glue together has been bloated, so it won't be anything amazing anyway though it would be good to get some experience even if it's ultimately pointless.

Oh, not sure if this would interest you, but I was researching a JS library for inline editing page elements for something I'm working on, and it looks like it could be appropriate for your hostname problem. Source The page talks a lot about using Ajax, but it all implements nicely with just JS as well.

In any case, thanks and enjoy your night.

vortex-5 commented 8 years ago

Install.sh usually creates that folder if I'm not mistaken.

Deus-Rex commented 8 years ago

I'm not at home, but I'm sure when I checked that file all it had were some lines that fixed file permissions.

If it does, then what was the code I mentioned supposed to do?

vortex-5 commented 8 years ago

Your fix does look correct the reason I mention install is that's the process people usually do the code you mention looks to be a bit of redundancy added for robustness unfortunately you may be correct that it was never working.

vortex-5 commented 8 years ago

I have patched the bug and have put up a new release 1.6.2 with your fix. Thanks for contributing.

Deus-Rex commented 8 years ago

Thanks very much. As simple as this was, it was an interesting experience for me. :) I guess this can be marked as closed now.