dd-wrt - Bandwidth Usage Monitor

Post new topic   This topic is locked: you cannot edit posts or make replies.    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page Previous  1, 2, 3 ... 24, 25, 26 ... 40, 41, 42  Next
Author Message
FezJay
DD-WRT User


Joined: 11 Sep 2010
Posts: 178

PostPosted: Sat Oct 22, 2011 10:55    Post subject: Reply with quote
Ah yep

I forgot to escape the bloody *'s.

Ive amended the script and checked it in.

Here is that method again with escaped *

Code:

checkReset()
{
   #(24 Hours * 60 * 60)-1 = 86400
   #(Hour * 60 * 60) + (Minute * 60) + Seconds
   secondsUntilNextDay=`expr $(expr $(date +%H) '*' 60 '*' 60) + $(expr $(date +%M) '*' 60) + $(expr $(date +%S))`
   secondsUntilNextDay=`expr 86400 - $secondsUntilNextDay`
   #Determine next day number and force to numeric
   nextDay=`expr $(date --date='next day' +"%d") '*' 1`
   #Determine if next day will be reached before or after update (allow 20 second buffer)
   secondsWithUpdateUntilNextDay=`expr $(expr $secondsUntilNextDay - $_intervalUpdate) - 20`
   #force reset day to numeric
   resetDay=`expr $_resetDay '*' 1`

   if [ $nextDay -eq $_resetDay ] && [ $secondsWithUpdateUntilNextDay -le 0 ]; then
      #wait until next day
      currentDay=`expr $(date +%d) '*' 1`
      while [ $currentDay -ne $_resetDay ]; do
         sleep 1
         currentDay=`expr $(date +%d) '*' 1`
      done
      sleep 5
      resetUsage
   fi
}

_________________
dd-wrt eko/V24-K26 15508
Belkin F7D4301
8MB Flash
64MB RAM

Optware (jffs/mnt) 4GB Flash Drive
Sponsor
bpsmicro
DD-WRT User


Joined: 07 Oct 2010
Posts: 180

PostPosted: Sat Oct 22, 2011 17:40    Post subject: Reply with quote
The only other change I made, which may or may not be required, is in lines
Code:
 if [ $nextDay -eq $_resetDay ]
and
Code:
while [ $currentDay -ne $_resetDay ]
you may want to use the non-underscored variant of resetDay.

Other than that, my version worked! Laughing
Dark_Shadow
DD-WRT Guru


Joined: 31 Aug 2009
Posts: 2448
Location: Third Rock from the Sun

PostPosted: Sat Oct 22, 2011 18:16    Post subject: Reply with quote
Are there basic instructions for installing this?
_________________
Peacock Thread-FAQ -- dd-wrt Wiki

Testing Multiple Routers -- Bootloader Collection Project -- My Wiki
bpsmicro
DD-WRT User


Joined: 07 Oct 2010
Posts: 180

PostPosted: Sat Oct 22, 2011 18:18    Post subject: Reply with quote
Way up at the top of the thread.
FezJay
DD-WRT User


Joined: 11 Sep 2010
Posts: 178

PostPosted: Sat Oct 22, 2011 22:05    Post subject: Reply with quote
bpsmicro wrote:
The only other change I made, which may or may not be required, is in lines
Code:
 if [ $nextDay -eq $_resetDay ]
and
Code:
while [ $currentDay -ne $_resetDay ]
you may want to use the non-underscored variant of resetDay.

Other than that, my version worked! Laughing


You know, in an ideal world, I would also use the non-underscored variable. Thats basically why I put it in there.

Yep, going to make that fix also Wink

Cheers bp

A

_________________
dd-wrt eko/V24-K26 15508
Belkin F7D4301
8MB Flash
64MB RAM

Optware (jffs/mnt) 4GB Flash Drive
FezJay
DD-WRT User


Joined: 11 Sep 2010
Posts: 178

PostPosted: Sat Oct 22, 2011 22:14    Post subject: Reply with quote
Alright, hopefully this is the one Smile

I have made all the fixes and changes that have been discussed recently.

I have put both commands in to determine the next day. What the following does is attempt the first command, if that fails, then the next command will be executed.

If they both fail, well, find a language that eloquently says your fucked lol (jks Smile). You may need to get a package down.

Code Snippet
Code:

   nextDay=`expr $(date --date='next day' +"%d") '*' 1`
   if [ $? -ne 0 ]; then
      #Attempt another way to determine the next day
      nextDay=`expr $(TZ=MST-24 date +%d) '*' 1`
   fi


Code:

checkReset()
{
   #(24 Hours * 60 * 60)-1 = 86400
   #(Hour * 60 * 60) + (Minute * 60) + Seconds
   secondsUntilNextDay=`expr $(expr $(date +%H) '*' 60 '*' 60) + $(expr $(date +%M) '*' 60) + $(expr $(date +%S))`
   secondsUntilNextDay=`expr 86400 - $secondsUntilNextDay`
   #Determine next day number and force to numeric
   nextDay=`expr $(date --date='next day' +"%d") '*' 1`
   if [ $? -ne 0 ]; then
      #Attempt another way to determine the next day
      nextDay=`expr $(TZ=MST-24 date +%d) '*' 1`
   fi
   #Determine if next day will be reached before or after update (allow 20 second buffer)
   secondsWithUpdateUntilNextDay=`expr $(expr $secondsUntilNextDay - $_intervalUpdate) - 20`
   #force reset day to numeric
   resetDay=`expr $_resetDay '*' 1`

   if [ $nextDay -eq $resetDay ] && [ $secondsWithUpdateUntilNextDay -le 0 ]; then
      #wait until next day
      currentDay=`expr $(date +%d) '*' 1`
      while [ $currentDay -ne $resetDay ]; do
         sleep 1
         currentDay=`expr $(date +%d) '*' 1`
      done
      sleep 5
      resetUsage
   fi
}


I have checked this into the trunk version ONLY.

Only once it is completely tested, will I create a new major version 1.2 and make that available.

A

_________________
dd-wrt eko/V24-K26 15508
Belkin F7D4301
8MB Flash
64MB RAM

Optware (jffs/mnt) 4GB Flash Drive
barryware
DD-WRT Guru


Joined: 26 Jan 2008
Posts: 13049
Location: Behind The Reset Button

PostPosted: Sat Oct 22, 2011 22:17    Post subject: Reply with quote
Dark_Shadow wrote:
Are there basic instructions for installing this?

Ditto... I've read & printed the documentation..

I have the original version installed and working..

RT-N16 installed on a usb mem stick mounted to /opt. Mypage brings up the bandwidth gui.

Been messing with this (newest version.. 1.1) all day and I can't get the new version to work.

The current (old) version is located in /opt/www/ and works great but it seems that the monitored clients are limited to 10 and the new version (based on screen shots) has much more detail.

The IP of the router is 192.168.254.1. I have edited the files to reflect the host ip..

The needed edits are confusing because of the diff colors in the samples.. What colors can / need to be edited for my (our) config?

I just can't get it to go..

_________________
[Moderator Deleted] Shocked
Dark_Shadow
DD-WRT Guru


Joined: 31 Aug 2009
Posts: 2448
Location: Third Rock from the Sun

PostPosted: Sat Oct 22, 2011 23:02    Post subject: Reply with quote
barryware wrote:
Dark_Shadow wrote:
Are there basic instructions for installing this?

Ditto... I've read & printed the documentation..


Including this?

http://code.google.com/p/lal-projects/wiki/bw_monitor_setup

_________________
Peacock Thread-FAQ -- dd-wrt Wiki

Testing Multiple Routers -- Bootloader Collection Project -- My Wiki
FezJay
DD-WRT User


Joined: 11 Sep 2010
Posts: 178

PostPosted: Sat Oct 22, 2011 23:08    Post subject: Reply with quote
The hard part of the installation is making sure you have the right packages and secondly knowing a little bit about storage (usb or wget etc)

The main setup calls are from the bw_monitor.startup script file.

In this file you indicate where your files are (backups, bw_monitor.sh), and where you configure the actual bw_moinitor.sh script (intervals etc).

This all works fine if you have perm storage (USB etc), but things get a bit tricky but not impossible if you dont have USB.

As I have mentioned online, all you need to do is download the required files (scripts, html, backups) to tmp, rename them and then execute the bw_monitor.startup command pointing to the downloaded files.

This can be achieved by running them as a startup script (copy and past the contents from the bw_mointor.startup file into a startup script).

e.g (pseudo code - nvram (startup script))

1. Download Files (bw_monitor.sh, html, usage.backup etc)

2. Save file to /tmp (renamed to with prefix '_stored_[name of file])

3. chmod +x script file (bw_monitor.sh)

4. bw_monitor.starup script contents copied and here (need to modify directories to point to tmp and point at renamed files)

As you can see, things are easier if you have USB storage and optware installed (you can use optwares startup script folders /opt/etc/init.d)

This does mean you need a little bit of linux dd-wrt know how (I had absolutely none when I began this script).

_________________
dd-wrt eko/V24-K26 15508
Belkin F7D4301
8MB Flash
64MB RAM

Optware (jffs/mnt) 4GB Flash Drive
barryware
DD-WRT Guru


Joined: 26 Jan 2008
Posts: 13049
Location: Behind The Reset Button

PostPosted: Sun Oct 23, 2011 0:22    Post subject: Reply with quote
Dark_Shadow wrote:
barryware wrote:
Dark_Shadow wrote:
Are there basic instructions for installing this?

Ditto... I've read & printed the documentation..


Including this?

http://code.google.com/p/lal-projects/wiki/bw_monitor_setup


Well YEA!!!... That is the doc I printed. I think I got the scripts loaded in the wrong folder.. Not wrong as long as you make the necessary edits to point to the correct folder(s).. This I think is my problem.. I'll get it.. Not scared.. Razz

_________________
[Moderator Deleted] Shocked
Dark_Shadow
DD-WRT Guru


Joined: 31 Aug 2009
Posts: 2448
Location: Third Rock from the Sun

PostPosted: Sun Oct 23, 2011 12:49    Post subject: Reply with quote
My biggest problem is that the setup instructions are vague, for example...

Quote:
One way is to use persistant storage, such as flash drive or somthing similar (samba, jffs etc)

Downlaod the bw_monitor.sh script and save it
chmod +x the script. This makes it executable
Download the monitor.html file
Create and modify the below script and save it as a startup or a wanup script (this is described in detail in the Startup/Wanup Scripts section below):

Code:
#!/bin/sh
MONITOR_LOCK_FILE=/tmp/monitor-started.lock
MONITOR_STOP_FILE=/tmp/monitor-stop
MONITOR_STOPPED_FILE=/tmp/monitor-stopped
while [ ! -f $MONITOR_LOCK_FILE ] && [ ! -f $MONITOR_STOP_FILE ]; do
        if [ ! -f /[WWW DIR]/monitor.html ]; then
                sed 's/src=.*>/src="http:\/\/192.168.1.1\/user\/user_details.js"><\/script>/' /[DIR]/monitor.html > /[WWW DIR]/monitor.html
        fi
        /[DIR]/bw_monitor.sh 30 3 30 4 [USER FILE] [DIR]/[USAGE BACKUP FILE] [HISTORY DIR] '' '' 1 0 0 0 1 0 0 [DIR]/[LOG FILE]
        if [ ! -f $MONITOR_LOCK_FILE ]; then
                sleep 10
        fi
done


it says to modify this script. What exactly is supposed to be modified? All in brackets? Only where it say "DIR"?

_________________
Peacock Thread-FAQ -- dd-wrt Wiki

Testing Multiple Routers -- Bootloader Collection Project -- My Wiki
blurp
DD-WRT Novice


Joined: 17 Aug 2011
Posts: 8

PostPosted: Wed Oct 26, 2011 0:30    Post subject: Reply with quote
Take a look @ my startup script. It may point out which areas to modify. Hope it helps. Also read this link : http://code.google.com/p/lal-projects/wiki/bw_monitor_setup

You can see the Script Arguments following the bw_monitor.sh script.

#!/bin/sh
MONITOR_LOCK_FILE=/tmp/monitor-started.lock
MONITOR_STOP_FILE=/tmp/monitor-stop
MONITOR_STOPPED_FILE=/tmp/monitor-stopped
while [ ! -f $MONITOR_LOCK_FILE ] && [ ! -f $MONITOR_STOP_FILE ]; do
if [ ! -f /www/user/monitor.html ]; then
sed 's/src=.*>/src="http:\/\/192.168.2.1\/user\/user_details.js"><\/script>/' /opt/bw_monitor/monitor.html > /www/user/monitor.html
fi
/opt/bw_monitor/bw_monitor.sh 30 3 30 23 /tmp/dnsmasq.conf /opt/bw_monitor/mac_usage.backup /opt/bw_monitor/history/ 1 /tmp/www/ 1 0 0 0 1 0 0
if [ ! -f $MONITOR_LOCK_FILE ]; then
sleep 10
fi
done
barryware
DD-WRT Guru


Joined: 26 Jan 2008
Posts: 13049
Location: Behind The Reset Button

PostPosted: Wed Oct 26, 2011 16:54    Post subject: Reply with quote
@blurp.. That helped.. Thanks.

ok... a couple of assumptions...

My router ip is 192.168.254.1

I have a usb storage device mounted to /opt

I create a folder in opt called /bw_monitor

/opt/bw_monitor

I create a folder in bw_monitor called /history

/opt/bw_monitor/history

I put monitor.html and bw_monitor.sh in /opt/bw_monitor

change permissions of bw_monitor.sh to make it executable.

I do not intend to use dnsmasq for dhcp so I create and populate the user file (user.file) and put it in /opt/bw_monitor

Then plop this into my startup command:

#!/bin/sh
MONITOR_LOCK_FILE=/tmp/monitor-started.lock
MONITOR_STOP_FILE=/tmp/monitor-stop
MONITOR_STOPPED_FILE=/tmp/monitor-stopped
while [ ! -f $MONITOR_LOCK_FILE ] && [ ! -f $MONITOR_STOP_FILE ]; do
if [ ! -f /www/user/monitor.html ]; then
sed 's/src=.*>/src="http:\/\/192.168.254.1\/user\/user_details.js"><\/script>/' /opt/bw_monitor/monitor.html > /www/user/monitor.html
fi
/opt/bw_monitor/bw_monitor.sh 30 3 30 23 /opt/bw_monitor/user.file /opt/bw_monitor/mac_usage.backup /opt/bw_monitor/history/ /tmp/mac_usage.db /tmp/www/ 1 0 0 1 1 0 1
if [ ! -f $MONITOR_LOCK_FILE ]; then
sleep 10
fi
done

This should do it??

I can't test till later but I think I found my problem. (paths)

_________________
[Moderator Deleted] Shocked
FezJay
DD-WRT User


Joined: 11 Sep 2010
Posts: 178

PostPosted: Wed Oct 26, 2011 20:03    Post subject: Reply with quote
Yup, that looks right

This is my startup script (Which I run from optware's init.d folder)

Code:

#!/bin/sh
MONITOR_LOCK_FILE=/tmp/monitor-started.lock
MONITOR_STOP_FILE=/tmp/monitor-stop
MONITOR_STOPPED_FILE=/tmp/monitor-stopped
while [ ! -f $MONITOR_LOCK_FILE ] && [ ! -f $MONITOR_STOP_FILE ]; do
        if [ ! -f /tmp/www/monitor.html ]; then
                sed 's/src=.*>/src="http:\/\/192.168.1.1\/user\/user_details.js"><\/script>/' /mnt/monitor/setup/monitor.html > /tmp/www/monitor.html
        fi
        /mnt/monitor/setup/bw_monitor.sh 30 3 30 4 /tmp/dnsmasq.conf /mnt/monitor/mac_usage.backup /mnt/monitor/history/ /tmp/mac_usage.db '' 1 1 1 1 1 0 1 ''
        if [ ! -f $MONITOR_LOCK_FILE ]; then
                sleep 10
        fi
done &


The one thing that you should add to your script is the last '&' after 'done'.

This will basically allow this part of the script to run without preventing other startup services from running.

e.g.

while []; do
... CODE etc
done &

The reason I bring this up is because some people have noticed that the script will try to run before certain services are ready, like external drives.

The other approach is to put a 10 second sleep before execution.

_________________
dd-wrt eko/V24-K26 15508
Belkin F7D4301
8MB Flash
64MB RAM

Optware (jffs/mnt) 4GB Flash Drive
barryware
DD-WRT Guru


Joined: 26 Jan 2008
Posts: 13049
Location: Behind The Reset Button

PostPosted: Wed Oct 26, 2011 20:21    Post subject: Reply with quote
FezJay wrote:
Yup, that looks right

This is my startup script (Which I run from optware's init.d folder)


Glad you brought that up..

How do you name the file in /opt/init.d?

S99bwmon... something like that.. Give is an Sxx prefix?

I'll put it at the end so everything else is loaded. This would be nice so I can turn it off just by making the Sxx file non-executable

As long as I have your attention..

What is the proper way to format the user.file in regards to devices in which the ip may be unknown, like a dhcp assignment?

mac,ip,user,type.. like so:

01:02:03:04:05:06,,Mypc,Pc

Thanks for the tips..

_________________
[Moderator Deleted] Shocked


Last edited by barryware on Wed Oct 26, 2011 20:31; edited 1 time in total
Goto page Previous  1, 2, 3 ... 24, 25, 26 ... 40, 41, 42  Next Display posts from previous:    Page 25 of 42
Post new topic   This topic is locked: you cannot edit posts or make replies.    DD-WRT Forum Index -> Broadcom SoC based Hardware 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 can attach files in this forum
You can download files in this forum