Posted: Sun Aug 08, 2010 17:32 Post subject: Negative Download And Upload Rate
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.
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:
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.
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.
Last edited by RobotBanana on Mon Oct 04, 2010 0:50; edited 1 time in total
# 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
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.
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:
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 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.