vortex-5 / ddwrt-bwmon

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

Resetting counters automatically #57

Closed oubcat96 closed 6 years ago

oubcat96 commented 6 years ago

I am looking to setup an automated reset of the counters each month when my data cap resets with my internet provider. I have set it up a few different ways with putty and I am successful executing the clean and the startup script. What I am noticing though is that it when I do it automatically, the total usage counters all stay at zero. I can then ssh in and run the startup script again and it fixes it. So basically, if I run the commands manually from a putty session it works. But if I send them via a plink command or putty shortcut within a profile, the total usage counters stay at zero. The one thing I do see is that when I run them manually, "autobackup started" and "monitor with cycle time of 60" displays in the putty session. I do not see those if I send a command.

As a side note, this monitor has been great and I have been using it for a long time. It has helped me monitor the connections in my house that I have set QoS on and to watch how we are tracking month to month against our data cap.

vortex-5 commented 6 years ago

Well yes you are suppose to run them in this order

./stop.sh ./clean.sh ./start.sh

I guess I can make clean.sh handle this for you if it detects the service is running I can make it shutdown and restart the service that as an improvement in the next version.

if you wish to make the improvement yourself the detection for if things are running can be found in lighttpd-running.sh

you can add the same lines in clean.sh but change the grep value to 'bwmon-running.sh'

that should let you know if it's currently running or not and then you can terminate the service run the clean operation and start again.

Alternatively you can just run startup.sh at the end which will automatically terminate and restart the service after cleaning. You will still need to detect if the service is already active since you don't need to start the service if it's already terminated.

Actually come to think of it that's a simpler solution I'll probably build my solution around that later method.

oubcat96 commented 6 years ago

Thanks so much for the quick response. That is actually how I have my batch file ordered (stop,clean,start). I have scheduled the task on Win 10 running the batch file. It completes all three steps but for some reason the total usage (and last seen) stop working. If I just ssh in and manually run startup again it works. Unfortunately I am not a Linux expert so going much further will be a challenge for me. Either way, I appreciate the suggestions and I can do it manually. Thanks again!

vortex-5 commented 6 years ago

I've put in a pre-release version that handles this for you automatically. I guess I should've warned you I started working on this before you written your batch script.

https://github.com/vortex-5/ddwrt-bwmon/releases/tag/1.9.2

You can test this if you like. It should detect the state of the bandwidth monitoring and will terminate and restart the service if required.

It's pre-release because I tend to hold a version back for a few days so I can put it through more robust testing.

oubcat96 commented 6 years ago

Thanks! I will give it a try.

oubcat96 commented 6 years ago

So if I just run the clean script in this release it should make sure the total usage counters will be in a proper state?

vortex-5 commented 6 years ago

running clean.sh from this release will stop the service if required clean the counters then automatically restart the service.

basically it does the job your batch script does for you.

It is also smart enough to detect if other users have run stop.sh first so it won't restart the service.

oubcat96 commented 6 years ago

Just tested it 3 times just using clean.sh and it worked. Thanks so much!

oubcat96 commented 6 years ago

I apologize for posting agin in this thread but is there a setting that can be changed to only total internet traffic? I noticed that when someone is streaming on the local network (like from Plex) that is totaling that bandwidth. For some reason thought that the version I have been using for a while didn’t “count” that traffic.

vortex-5 commented 6 years ago

In my tests this script shouldn't "count" internal traffic as it only counts the traffic passing from LAN to WAN and WAN to LAN.

It doesn't monitor anything that's passing through the LAN iptables as the filter rule sits in between the two (the filter rule is for counting up the traffic).

This could be specific to how your particular brand of router works.

Potentially you can try tinkering around with wireless isolation maybe that does something to the firewall rules that pass them through the WAN interface?

oubcat96 commented 6 years ago

Thanks. I will take a look into that. I verified on a few devices that it is counting LAN to LAN traffic.

vortex-5 commented 6 years ago

Hmm not entirely sure how that can be fixed then I'm think the internals of my router are a bit different than yours and I have a switch hooked up to it so the only time the router really sees traffic is across the internet.

Maybe ask people at DDWRT if they are experiencing this too? I haven't heard anyone else report this.

oubcat96 commented 6 years ago

I actually found the issue. Not sure if you are familiar with Plex but they have a setting to prefer secured connections. This causes the traffic to be routed to the public IP even it is LAN to LAN traffic. The traffic actually never leaves the network. I enabled this at one point because it was a fix to help people streaming remotely from a Chromecast. I just disabled and verified bwmon is no longer counting that traffic.

vortex-5 commented 6 years ago

Interresting I'm not quite sure what plex is doing in that context I haven't played with that software but you are correct having traffic reach the wan interface without it actually passing onto the internet would still tick up the counters there's not a good way around this unfortunately the router and traffic counter is working correctly basically your traffic goes on the internet as far as the router is concerned and makes a u-turn back.

Just marked the original issue as closed since your original issue was addressed