Per-user Live Down/Upload Rate Monitoring [No PC needed!]

Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload
Goto page Previous  1, 2, 3, 4 ... 10, 11, 12  Next
Author Message
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Wed Aug 04, 2010 19:54    Post subject: Reply with quote
mojso wrote:
Quote:
Router Password Protect Usage Data



Nicely done


Thanks

_________________


YouTube | Facebook Page
Per-user Live Down/Upload Rate Monitoring [No PC needed!]
Sponsor
mojso
DD-WRT User


Joined: 09 Sep 2007
Posts: 232
Location: Macedonia

PostPosted: Wed Aug 04, 2010 21:20    Post subject: Reply with quote
Would be good to have a new page for each month. something like Traffic by Month, but only for a month not every day
knightmedz
DD-WRT Novice


Joined: 05 Aug 2010
Posts: 3

PostPosted: Sun Aug 08, 2010 17:32    Post subject: Negative Download And Upload Rate Reply with quote
Hi Wolf Kodi. I've just successfully installed your script on my DLink DIR-600 B2 running on DD-WRT v24 pre sp2 std build 14311. At first I had the 'sort:not found' issue in line 174 (the std build doesn't have the command preinstalled) but I was able to fix it by replacing 'sort -n' with 'cat'.

It seems to be running fine up to now until I noticed some workstations started to have their Upload and Download rate negative at times. This causes the traffic data to be subtracted to the Total Download/Upload instead. So in effect the Total Download and Upload is decreasing instead of increasing. Do you have any ideas why this might be happening? Thanks.
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Sat Aug 14, 2010 3:26    Post subject: Reply with quote
I've been playing around with this script for the past little while on a WRT610N v1 running dd-wrt.v24-14853_NEWD-2_K2.6_big.bin which also has Optware set up. I've noticed some quirks and some things worth mentioning in case anyone is interested.

I've also been making all my changes with nano and/or vi directly on the router to avoid the problem I had earlier in this thread.

1) On my WRT610N, if I run my startup script manually at an SSH prompt, I get errors that look like this:
Code:
/tmp/in_3580.tmp: No such file or directory
/tmp/out_3580.tmp: No such file or directory
/tmp/in_3580.tmp: No such file or directory
/tmp/out_3580.tmp: No such file or directory

I get those 4 errors ever few seconds when the wrtbwmon update command is issued, and each set of 4 errors uses a different number in the name. The weird thing is, they don't seem to affect performance of the program... At most, they're a minor annoyance since they make the current SSH session unusable. The only way to stop seeing them is to reconnect.

The errors are obviously related to lines 81-87 of wrtbwmon:
Code:
         [ "${DST}" = "${IP}" ] && echo $((${BYTES}/1000)) > /tmp/in_$$.tmp
         [ "${SRC}" = "${IP}" ] && echo $((${BYTES}/1000)) > /tmp/out_$$.tmp
      done
      IN=$(cat /tmp/in_$$.tmp)
      OUT=$(cat /tmp/out_$$.tmp)
      rm -f /tmp/in_$$.tmp
      rm -f /tmp/out_$$.tmp

By commenting out some lines, I've determined that the two delete commands make up one pair of error messages. Not sure what the other two come from. As long as they don't break anything, I don't mind...

2) When I have QoS enabled, some weird things happen. The script will work fine for a few minutes, and then everything starts to double. Both the indicated upload/download rates and the rate at which the totals increase. For some reason, lines 37-45 mess it up. A quick look at my iptables rules shows that I have two RRDIPT entries under FORWARD and "iptables -D FORWARD -j RRDIPT" is not successfully issued or carried out resulting in everything being counted twice. I've managed to solve this by putting lines 33-45 into my startup script and removing them from wrtbwmon:
Code:
   #Create the RRDIPT CHAIN (it doesn't matter if it already exists).
   iptables -N RRDIPT 2> /dev/null

   #Add the RRDIPT CHAIN to the FORWARD chain (if non existing).
   iptables -L FORWARD --line-numbers -n | grep "RRDIPT" | grep "1" > /dev/null
   if [ $? -ne 0 ]; then
      iptables -L FORWARD -n | grep "RRDIPT" > /dev/null
      if [ $? -eq 0 ]; then
         echo "DEBUG : iptables chain misplaced, recreating it..."
         iptables -D FORWARD -j RRDIPT
      fi
      iptables -I FORWARD -j RRDIPT
   fi

So far, the only time I've run into problems after applying this fix is if you change QoS settings. Doing so gets rid of the FORWARD rule and all counting stops, so I have to run "iptables -I FORWARD -j RRDIPT" to get it running again.

EDIT: A better fix from my later post:
http://www.dd-wrt.com/phpBB2/viewtopic.php?p=490287#490287
That one works without moving any code into another script, and it will work even when you change QoS/firewall rules.

3) All numbers seem to be inflated by 4-8% or so compared to the typical speed indicator on a PC. Some of this could be attributed to the fact that most applications consider a kB to be 1024 B, an MB to be 1024 kB, etc, while wrtbwmon considers each kB to be 1000 B. Although most ISPs use the 1000 numbers instead of 1024, I don't like it that way. So I changed line 166 from:
Code:
echo "var prefix=new Array(\"\",\"k\",\"M\",\"G\",\"T\",\"P\",\"E\",\"Z\"); var base=1000;" >> ${3}

To:
Code:
echo "var prefix=new Array(\"\",\"k\",\"M\",\"G\",\"T\",\"P\",\"E\",\"Z\"); var base=1024;" >> ${3}

Now the script reports numbers that are a bit closer to what web browsers and things on my PC report, but they're still a little high for some reason. Probably overhead. Downloading a file in Firefox, wrtbwmon reports a steady 415 kBps while Firefox says it's a steady 400 kBps (about a 4% discrepancy).

Just in case anything changes, I've re-uploaded the source script that I've been playing with so you can see what my line numbers actually mean. It's the July 19 2010 copy.

EDIT: Oddly enough, after leaving it running for a few days, the numbers became more accurate. It now reports 100mb of bandwidth to be 100mb... Most of my tests were done shortly after rebooting the router. Not sure if that really makes a difference or it was just a fluke, but whatever. Smile


Last edited by RobotBanana on Mon Oct 04, 2010 0:50; edited 1 time in total
cyang030
DD-WRT Novice


Joined: 24 Aug 2010
Posts: 10

PostPosted: Wed Aug 25, 2010 23:52    Post subject: Reply with quote
Hi everyone,

Would someone tell me if the build "DD-WRT v24-sp2 (10/10/09) std - build 13064 " could work with this script?

The traffic page on my router is a bit weird, it just doesn't display any results.




Thanks
utopian201
DD-WRT Novice


Joined: 26 May 2010
Posts: 5

PostPosted: Thu Aug 26, 2010 5:02    Post subject: Reply with quote
cyang030 wrote:
Hi everyone,

Would someone tell me if the build "DD-WRT v24-sp2 (10/10/09) std - build 13064 " could work with this script?

The traffic page on my router is a bit weird, it just doesn't display any results.

Thanks


Don't use 13064. Despite the router database saying it may be the preferred one, use one of the ones recommended in the peacock thread.
cyang030
DD-WRT Novice


Joined: 24 Aug 2010
Posts: 10

PostPosted: Thu Aug 26, 2010 8:15    Post subject: Reply with quote
Thanks for the information, my DIR-300 is running build 13525 now.
However this problem still exists.

I did tried to run my start-up script line by line, but they give no error messages at all.

Quote:
sleep 10

wget ftp://user:pass@somewhere.com/wrtbwmon -O /tmp/wrtbwmon && chmod +x /tmp/wrtbwmon

# Load database
wget ftp://user:pass@somewhere.com/usage.db -O /tmp/usage.db

# Bandwidth Download/Upload Rate Counter
while :
do
/tmp/wrtbwmon setup
/tmp/wrtbwmon read
sleep 9
/tmp/wrtbwmon update /tmp/usage.db
/tmp/wrtbwmon publish /tmp/usage.db /tmp/www/usage.html
done &

# Backup usage database file
while :
do
sleep 900
cd /tmp && ftpput -u user -p pass somewhere.com usage.db .
done
# If you want to run other codes below this line, use "done &" instead of just "done" on the line above
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Thu Aug 26, 2010 11:11    Post subject: Reply with quote
Let's poke around your router and see where the script stops doing its job.

Pull up an SSH prompt and type:
Code:
iptables -L RRDIPT

The output should look something like:
Code:
Chain RRDIPT (1 references)
target     prot opt source               destination
RETURN     0    --  192.168.1.200        anywhere
RETURN     0    --  anywhere             192.168.1.200

Those last two lines should be repeated using every IP address of devices connected to the router. If that's not what you see, please let me know.


Also try typing:
Code:
iptables -L FORWARD

Somewhere in the output, you should see this line:
Code:
RRDIPT     0    --  anywhere             anywhere

If you don't, let me know.


If all of that is OK, try changing the first line of your script to "sleep 100" instead of "sleep 10". Reboot the router, wait 2-3 minutes, and see if the page starts displaying some real data. That'll guarantee that the router can boot up completely before we start throwing more work at it.
cyang030
DD-WRT Novice


Joined: 24 Aug 2010
Posts: 10

PostPosted: Thu Aug 26, 2010 17:00    Post subject: Reply with quote
Code:
iptables -L RRDIPT
Quote:

Chain RRDIPT (1 references)
target prot opt source destination
RETURN 0 -- MY-PC anywhere
RETURN 0 -- anywhere MY-PC

it gives computer names instead of ip, but I guess this shouldn't really be a problem?

Code:
iptables -L FORWARD
Quote:
Chain FORWARD (policy ACCEPT)
target prot opt source destination
RRDIPT 0 -- anywhere anywhere
ACCEPT gre -- 192.168.1.0/24 anywhere
ACCEPT tcp -- 192.168.1.0/24 anywhere tcp dpt:1723
ACCEPT 0 -- anywhere anywhere
TCPMSS tcp -- anywhere anywhere tcp flags:SYN,RST/SYN TCPMSS clamp to PMTU
lan2wan 0 -- anywhere anywhere
ACCEPT 0 -- anywhere anywhere state RELATED,ESTABLISHED
TRIGGER 0 -- anywhere anywhere TRIGGER type:in match:0 relate:0
trigger_out 0 -- anywhere anywhere
ACCEPT 0 -- anywhere anywhere state NEW
DROP 0 -- anywhere anywhere



After that, I tried to increase sleep 10 to 100, 200 and 300, but the page still displays nothing. Sad
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Thu Aug 26, 2010 21:00    Post subject: Reply with quote
PC names are fine.

The firewall rules have typically been the culprit with issues I've had while tinkering around with the script.

I guess the next place to check would be the usage.db file and the temp files. Since the firewall rules are present, we know that "/tmp/wrtbwmon setup" is doing its job. 1 command down, 3 to go...

After running your startup script, try this in an SSH prompt:
Code:
ls -a /tmp

You should see the files "traffic_55.tmp", "traffic_66.tmp", and "usage.db" somewhere in there. If all 3 are present, wait a bit to give the script some time to record some bandwidth data. Then try:
Code:
cat /tmp/usage.db

If things were working, you'd see something like:
Code:
root@DD-WRT:/# cat /tmp/usage.db
MY:MA:CA:DR:ES:S1,39,0,39,0,26-08-2010 01:09
cyang030
DD-WRT Novice


Joined: 24 Aug 2010
Posts: 10

PostPosted: Thu Aug 26, 2010 23:42    Post subject: Reply with quote
Code:
ls -a /tmp
Quote:

.
..
.ipt
.rc_startup
.rule
.wanuptime
cron.d
crontab
dnsmasq.conf
dnsmasq.leases
etc
hosts
igmpproxy.conf
loginprompt
nvram
oet
ping.log
resolv.conf
resolv.dnsmasq
root
traffic_55.tmp
traffic_66.tmp
udhcpc
udhcpc.expires
usage.db
var
wrtbwmon
www

looks like they are all here

Code:
cat /tmp/usage.db
Quote:
MY:MA:CA:DR:ES:S1,27804,2657,27804,2657,26-08-2010 20:41

The usage got recorded, but I noticed that there is no usage.db file in the ftp server ever. Thus I typed the following commands out of curiosity .

Code:
cd /tmp && ftpput -u user -p pass somewhere.com usage.db .
Quote:
sh: eval: line 1: ftpput: not found

Then I was trying to make a copy of the db and placed it under the /tmp/www folder

Code:
cp /tmp/usage.db /tmp/www/usage.db

then
Code:
cat /tmp/www/usage.db
Quote:
MY:MA:CA:DR:ES:S1,27804,2657,27804,2657,26-08-2010 20:41

Something shows up, but http://router/user/usage.db is only a blank page. I don't know if it is related or not, but I just feel like asking. Thanks
trickstar
DD-WRT Novice


Joined: 18 Mar 2007
Posts: 24

PostPosted: Fri Aug 27, 2010 13:59    Post subject: Reply with quote
how are you displaying users instead of MAC addresses?

MAC-PCname.txt < whats this files for?
mojso
DD-WRT User


Joined: 09 Sep 2007
Posts: 232
Location: Macedonia

PostPosted: Fri Aug 27, 2010 14:48    Post subject: Reply with quote
trickstar wrote:
how are you displaying users instead of MAC addresses?

MAC-PCname.txt < whats this files for?


to show users by name

00:XX:XX:XX:XX:XX,USER_1
trickstar
DD-WRT Novice


Joined: 18 Mar 2007
Posts: 24

PostPosted: Fri Aug 27, 2010 22:54    Post subject: Reply with quote
thanks.
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Sun Aug 29, 2010 23:09    Post subject: Reply with quote
cyang030: Not sure what could be causing that problem. Since the usage.db has some data filled in for all 4 numerical fields, wrtbwmon is recording the data successfully. So the problem has to be with the
"publish" command. But it's publishing something, since you see the table... It just isn't adding in the data.

The problem has to be somewhere in lines 173 to 192. Maybe the build you're running is missing one of the commands used?

If the sort command works for you, typing
Quote:
sort -n fghdfghfgh

Should yield:
Quote:
sort: open failed: fghdfghfgh: No such file or directory


If the "touch" command works for you, typing
Quote:
touch

Should yield:
Quote:
usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...


If both of those check out, I can take a look at your usage.html file if you'll send the source code to me. Maybe I can see where it stops publishing data.

This one's a tricky little problem...
Goto page Previous  1, 2, 3, 4 ... 10, 11, 12  Next Display posts from previous:    Page 3 of 12
Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum