I recently got a Chumby One, and am loving it. However, the "Network Usage" widget that you can install has a script for the older Chumby, not the newer Chumby One. To make it work with the Chumby One, you need to add a line to the crontab to run the widget every hour, like so:
chumby:~# cat /psp/crontabs/root
0 3 * * * /usr/chumby/scripts/sync_time.sh
* * * * * /usr/chumby/scripts/flashplayer_watchdog
59 * * * * /psp/cgi-bin/ipusage.pl getdata
Here is the file to run the script: (I changed rbusb0 to wlan0, and removed a ^ in line 89)
***************************************************************************************************************************
chumby:~# cat /psp/cgi-bin/ipusage.pl
#! /usr/bin/perl
$argcount = $#ARGV + 1;
$request = uc($ENV{'QUERY_STRING'});
if ($request eq "REPORT") #URL requests data
{
# send the data format as xml
# format is
#
# retrieve ipusage.dat
$lastrec = 0;
$lastsent = 0;
print "Content-type:text/xml\r\n\r\n";
print "\<\?xml version=\"1.0\" encoding=\"utf-8\"\?\>\n";
$file = "/psp/cgi-bin/ipusage.dat" ;
open(INFO, $file) ;
print "\n";
open(INFO, $file) ;
while ($line =
{
$line =~ s/\n// ; # remove linefeed
while ($line =~ " ") # change double spaces to singles
{
$line =~ s/ / / ;
}
@items = split(/ /, $line) ; # get each part of the line
@subitems = split(/:/, @items[3]) ; # get each part of the line
# line data example Tue Apr 14 10:00:01 2009 102307121 4336958
if (@items[6] <= $lastsent)
{ $lastsent = 0; }
if (@items[5] <= $lastrec)
{ $lastrec = 0; }
$diffsent = @items[6] - $lastsent;
$diffrec = @items[5] - $lastrec;
print "print "DayOfWeek = \"@items[0]\" ";
print "DayOfMonth = \"@items[2]\" ";
print "Month = \"@items[1]\" ";
print "Year = \"@items[4]\" ";
print "Hour = \"@subitems[0]\" ";
print "Min = \"@subitems[1]\" ";
print "Sec = \"@subitems[2]\" ";
print "SentBytes = \"$diffsent\" ";
print "RecBytes = \"$diffrec\"\> ";
print "\<\/Measurement\>\n";
$lastrec = @items[5];
$lastsent = @items[6];
}
print "<\/IPUsage>\n";
close(INFO) ;
}
if ($request eq "POLICY") # URL requests policy
{
# send the crossdomain policy file
print "Content-type:text\/xml\r\n\r\n";
print "<\?xml version=\"1.0\"\?>\r\n\r\n";
print "<\!-- my crossdomain file -->\n";
print "\n";
print "\n";
print "<\/cross-domain-policy>\n";
}
if ($argcount == 1) # run from the command line
{
if (uc($ARGV[0]) eq "GETDATA")
{
$mph = 1; # YOU CAN SET THIS TO THE NUMBER OF MEASUREMENT PER HOUR
$tl = ($mph * 7 * 24) + 10; # calculate how many lines in the file.
# run from crontab
# update ipusage.dat
#
# get the sent and rec bytes from dev file
#
$file = "/proc/net/dev" ;
open(INFO, $file) ;
while ($line =
{
if ($line =~ /wlan0:/) # find the line
{
$line =~ s/wlan0:// ;
while ($line =~ " ") # change double spaces to singles
{
$line =~ s/ / / ;
}
while ($line =~ "^ ") # remove spaces at start of line
{
$line =~ s/^ // ;
}
@items = split(/ /, $line) ; # read the values for rec and sent
$rec = @items[0] ;
$sen = @items[8] ;
}
}
close(INFO) ;
#
# get current date time
#
$tdt = localtime(time()) ;
#
# append values to data file
#
$file = "/psp/cgi-bin/ipusage.dat" ;
open(DAT, ">>$file") ;
printf DAT "$tdt $rec $sen\n" ;
close(DAT) ;
#
# truncate the data file
#
system("tail -n $tl /psp/cgi-bin/ipusage.dat > /psp/cgi-bin/ipusage.tmp");
system("mv -f /psp/cgi-bin/ipusage.tmp /psp/cgi-bin/ipusage.dat");
}
}
**************************************************************************************************************************************
chumby:~# cat /psp/crontabs/root
0 3 * * * /usr/chumby/scripts/sync_time.sh
* * * * * /usr/chumby/scripts/flashplayer_watchdog
59 * * * * /psp/cgi-bin/ipusage.pl getdata
Here is the file to run the script: (I changed rbusb0 to wlan0, and removed a ^ in line 89)
***************************************************************************************************************************
chumby:~# cat /psp/cgi-bin/ipusage.pl
#! /usr/bin/perl
$argcount = $#ARGV + 1;
$request = uc($ENV{'QUERY_STRING'});
if ($request eq "REPORT") #URL requests data
{
# send the data format as xml
# format is
#
# retrieve ipusage.dat
$lastrec = 0;
$lastsent = 0;
print "Content-type:text/xml\r\n\r\n";
print "\<\?xml version=\"1.0\" encoding=\"utf-8\"\?\>\n";
$file = "/psp/cgi-bin/ipusage.dat" ;
open(INFO, $file) ;
print "
open(INFO, $file) ;
while ($line =
{
$line =~ s/\n// ; # remove linefeed
while ($line =~ " ") # change double spaces to singles
{
$line =~ s/ / / ;
}
@items = split(/ /, $line) ; # get each part of the line
@subitems = split(/:/, @items[3]) ; # get each part of the line
# line data example Tue Apr 14 10:00:01 2009 102307121 4336958
if (@items[6] <= $lastsent)
{ $lastsent = 0; }
if (@items[5] <= $lastrec)
{ $lastrec = 0; }
$diffsent = @items[6] - $lastsent;
$diffrec = @items[5] - $lastrec;
print "
print "DayOfMonth = \"@items[2]\" ";
print "Month = \"@items[1]\" ";
print "Year = \"@items[4]\" ";
print "Hour = \"@subitems[0]\" ";
print "Min = \"@subitems[1]\" ";
print "Sec = \"@subitems[2]\" ";
print "SentBytes = \"$diffsent\" ";
print "RecBytes = \"$diffrec\"\> ";
print "\<\/Measurement\>\n";
$lastrec = @items[5];
$lastsent = @items[6];
}
print "<\/IPUsage>\n";
close(INFO) ;
}
if ($request eq "POLICY") # URL requests policy
{
# send the crossdomain policy file
print "Content-type:text\/xml\r\n\r\n";
print "<\?xml version=\"1.0\"\?>\r\n\r\n";
print "<\!-- my crossdomain file -->\n";
print "
print "
print "<\/cross-domain-policy>\n";
}
if ($argcount == 1) # run from the command line
{
if (uc($ARGV[0]) eq "GETDATA")
{
$mph = 1; # YOU CAN SET THIS TO THE NUMBER OF MEASUREMENT PER HOUR
$tl = ($mph * 7 * 24) + 10; # calculate how many lines in the file.
# run from crontab
# update ipusage.dat
#
# get the sent and rec bytes from dev file
#
$file = "/proc/net/dev" ;
open(INFO, $file) ;
while ($line =
{
if ($line =~ /wlan0:/) # find the line
{
$line =~ s/wlan0:// ;
while ($line =~ " ") # change double spaces to singles
{
$line =~ s/ / / ;
}
while ($line =~ "^ ") # remove spaces at start of line
{
$line =~ s/^ // ;
}
@items = split(/ /, $line) ; # read the values for rec and sent
$rec = @items[0] ;
$sen = @items[8] ;
}
}
close(INFO) ;
#
# get current date time
#
$tdt = localtime(time()) ;
#
# append values to data file
#
$file = "/psp/cgi-bin/ipusage.dat" ;
open(DAT, ">>$file") ;
printf DAT "$tdt $rec $sen\n" ;
close(DAT) ;
#
# truncate the data file
#
system("tail -n $tl /psp/cgi-bin/ipusage.dat > /psp/cgi-bin/ipusage.tmp");
system("mv -f /psp/cgi-bin/ipusage.tmp /psp/cgi-bin/ipusage.dat");
}
}
**************************************************************************************************************************************
Comments
Post a Comment