public inbox for ipfire-scm@lists.ipfire.org
 help / color / mirror / Atom feed
From: git@ipfire.org
To: ipfire-scm@lists.ipfire.org
Subject: [git.ipfire.org] IPFire 2.x development tree branch, next, updated. 0fa8d28e8fe5f6a9a04b8d13b4dc6bb6b1f54c8f
Date: Tue, 21 Apr 2015 20:47:39 +0200	[thread overview]
Message-ID: <20150421184740.02CBD21EA6@argus.ipfire.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 8316 bytes --]

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "IPFire 2.x development tree".

The branch, next has been updated
       via  0fa8d28e8fe5f6a9a04b8d13b4dc6bb6b1f54c8f (commit)
      from  a47376207fbce85385dc6086a87d54ec2e6aa0f1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0fa8d28e8fe5f6a9a04b8d13b4dc6bb6b1f54c8f
Author: Alexander Marx <alexander.marx(a)ipfire.org>
Date:   Tue Apr 21 11:25:29 2015 +0200

    Squid-accounting: new Version 1.0.3 (graph updates, movedb update)
    
    New Version. Now the data is correctly moved to hist table when month
    has changed.
    Also the graphs for old month starts by zero. In old version graphdata
    was started by total amount of bytes.

-----------------------------------------------------------------------

Summary of changes:
 lfs/squid-accounting                |  4 ++--
 src/squid-accounting/accounting.cgi | 21 +++++++++++++--------
 src/squid-accounting/acct-lib.pl    | 17 ++++++-----------
 src/squid-accounting/acct.pl        |  2 +-
 4 files changed, 22 insertions(+), 22 deletions(-)

Difference in files:
diff --git a/lfs/squid-accounting b/lfs/squid-accounting
index 7eae4fb..af7b281 100644
--- a/lfs/squid-accounting
+++ b/lfs/squid-accounting
@@ -9,13 +9,13 @@
 
 include Config
 
-VER        = 1.0.2
+VER        = 1.0.3
 
 THISAPP    = squid-accounting-$(VER)
 DIR_APP    = $(DIR_SRC)/$(THISAPP)
 TARGET     = $(DIR_INFO)/$(THISAPP)
 PROG       = squid-accounting
-PAK_VER    = 4
+PAK_VER    = 5
 
 DEPS       = "perl-DBI perl-DBD-SQLite perl-File-ReadBackwards perl-PDF-API2 sendEmail"
 
diff --git a/src/squid-accounting/accounting.cgi b/src/squid-accounting/accounting.cgi
index eabb0c2..1ec9849 100755
--- a/src/squid-accounting/accounting.cgi
+++ b/src/squid-accounting/accounting.cgi
@@ -907,7 +907,7 @@ sub generatemonthgraph{
 	my $sth;
 	my $cnt=0;
 	#If we want to show Data from within last 2 months, get DATA from ACCT
-	if ( ! $grmon < ($mon+1) && $gryear == ($year+1900)){
+	if ( $grmon == ($mon)+1 && $gryear == ($year+1900)){
 		$sth=&ACCT::getmonthgraphdata("ACCT",$from,$till,$grhost);
 	}else{
 		#If we want to show data from a date older than last two months, use ACCT_HIST
@@ -1959,9 +1959,9 @@ END
 sub viewtablehosts{
 	$dbh=&ACCT::connectdb;
 	&Header::openbox('100%', 'left', $Lang::tr{'acct hosts'});
-	my $mon=$_[0];
-	my $year=$_[1];
-	my ($from,$till)=&ACCT::getmonth($mon,$year);
+	my $mon1=$_[0];
+	my $year1=$_[1];
+	my ($from,$till)=&ACCT::getmonth($mon1,$year1);
 	$count=0;
 	#Menu to display another month
 	print<<END;
@@ -1986,7 +1986,7 @@ END
 		</select></td>
 		<td style='text-align: center;'><select name='year'>
 END
-	for (my $j=2014;$j<=($year);$j++){
+	for (my $j=2014;$j<=($year1);$j++){
 		if(($_[1]) eq $j){
 			print"<option selected>$j</option>";
 		}else{
@@ -2011,7 +2011,12 @@ END
 		<th></th>
 	</tr>
 END
-	my $res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(TIME_RUN),max(TIME_RUN),NAME from ACCT where TIME_RUN between ".$from." and ".$till." group by NAME;");
+	my $res;
+	if (($mon)+1 == $mon1 && ($year)+1900 == $year1){
+		$res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(TIME_RUN),max(TIME_RUN),NAME from ACCT where TIME_RUN between ".$from." and ".$till." group by NAME;");
+	}else{
+		$res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(strftime('%s',TIME_RUN)),max(strftime('%s',TIME_RUN)),NAME from ACCT_HIST where date(TIME_RUN) > date($from,'unixepoch') and date(TIME_RUN) < date($till,'unixepoch') group by NAME;");
+	}
 	my $sumbytes;
 	my $type;
 	my $lineval;
@@ -2036,8 +2041,8 @@ END
 					<input type='image' src='/images/utilities-system-monitor.png' alt="$Lang::tr{'status'}" title="$Lang::tr{'status'}" />
 					<input type='hidden' name='ACTION' value='viewgraph'>
 					<input type='hidden' name='host' value='$name'>
-					<input type='hidden' name='month' value='$mon'>
-					<input type='hidden' name='year' value='$year'>
+					<input type='hidden' name='month' value='$mon1'>
+					<input type='hidden' name='year' value='$year1'>
 					<input type='hidden' name='traffic' value="$Lang::tr{'acct sum'} $Lang::tr{'acct traffic'} $lineval $type">
 					</form>
 					
diff --git a/src/squid-accounting/acct-lib.pl b/src/squid-accounting/acct-lib.pl
index 7969a50..6891235 100644
--- a/src/squid-accounting/acct-lib.pl
+++ b/src/squid-accounting/acct-lib.pl
@@ -93,8 +93,8 @@ sub delbefore {
 }
 
 sub movedbdata {
-	$dbh->do("insert into ACCT_HIST select datetime(TIME_RUN,'unixepoch'),NAME,SUM(BYTES) from ACCT where  date(TIME_RUN,'unixepoch') < date('now','-2 months') group by NAME,date(TIME_RUN,'unixepoch');");
-	$dbh->do("DELETE FROM ACCT WHERE datetime(TIME_RUN,'unixepoch') < date('now','-2 months');");
+	$dbh->do("insert into ACCT_HIST select datetime(TIME_RUN,'unixepoch'),NAME,SUM(BYTES) from ACCT where datetime(TIME_RUN,'unixepoch') < datetime('now','start of month') group by NAME,datetime(TIME_RUN,'unixepoch');");
+	$dbh->do("DELETE FROM ACCT WHERE datetime(TIME_RUN,'unixepoch') < date('now','start of month');");
 }
 
 sub gethourgraphdata {
@@ -119,10 +119,10 @@ sub getmonthgraphdata {
 	my $name=$_[3];
 	my $res;
 	$dbh=connectdb;
-	if ($table eq 'ACCT'){
-		$res = $dbh->selectall_arrayref( "SELECT  strftime('%d.%m.%Y',xx.tag),(SELECT SUM(BYTES)/1024/1024 FROM ACCT WHERE date(TIME_RUN,'unixepoch') <= xx.tag and NAME = '".$name."') kum_bytes FROM (SELECT date(TIME_RUN,'unixepoch') tag,SUM(BYTES)/1024/1024 sbytes FROM ACCT WHERE NAME='".$name."' and TIME_RUN between ".$from." and ".$till." GROUP by date(TIME_RUN,'unixepoch')) xx;");
+	if ($table eq 'ACCT_HIST'){
+		$res = $dbh->selectall_arrayref( "SELECT strftime('%d.%m.%Y',TIME_RUN),(SELECT SUM(BYTES)/1024/1024 FROM ACCT_HIST WHERE TIME_RUN <= ah.TIME_RUN and TIME_RUN > date($from,'unixepoch') and NAME = '".$name."') kum_bytes FROM ACCT_HIST ah WHERE date(TIME_RUN) > date(".$from.",'unixepoch') AND date(TIME_RUN) < date(".$till.",'unixepoch') AND NAME = '".$name."' group by date(TIME_RUN);");
 	}else{
-		$res = $dbh->selectall_arrayref( "SELECT TIME_RUN, (SELECT SUM(BYTES)/1024/1024 FROM ACCT_HIST WHERE TIME_RUN <= ah.TIME_RUN and NAME = '".$name."') kum_bytes FROM ACCT_HIST ah WHERE TIME_RUN BETWEEN date(".$from.",'unixepoch') AND date(".$till.",'unixepoch') AND NAME = '".$name."' group by TIME_RUN;");
+		$res = $dbh->selectall_arrayref( "SELECT strftime('%d.%m.%Y',xx.tag),(SELECT SUM(BYTES)/1024/1024 FROM ACCT WHERE date(TIME_RUN,'unixepoch') <= xx.tag and TIME_RUN > ".$from." and NAME = '".$name."') kum_bytes FROM (SELECT NAME,date(TIME_RUN,'unixepoch') tag,SUM(BYTES)/1024/1024 sbytes FROM ACCT WHERE NAME='".$name."' and TIME_RUN between ".$from." and ".$till." GROUP by NAME,date(TIME_RUN,'unixepoch')) xx;");
 	}
 	$dbh=closedb;
 	return $res;
@@ -337,12 +337,7 @@ sub getmonth{
 		my $monat=$_[0]-1 if($_[0]);
 		my $tag=1;
 		my $time1=timelocal(0,0,0,$tag,$monat,$jahr);
-		my $time2=0;
-		if (($monat+1) == 12){
-			$time2=timelocal(0,0,0,$tag,0,$jahr+1);
-		}else{
-			$time2=timelocal(0,0,0,$tag,$monat+1,$jahr);
-		}
+		my $time2=timelocal(0,0,0,$tag,($monat+1),$jahr);
 		--$time2;
 		return ($time1,$time2);
 }
diff --git a/src/squid-accounting/acct.pl b/src/squid-accounting/acct.pl
index 79fc7ba..7222689 100755
--- a/src/squid-accounting/acct.pl
+++ b/src/squid-accounting/acct.pl
@@ -100,7 +100,7 @@ if (-f $proxyenabled && $proxylog eq $Lang::tr{'running'}){
 		open (FH,">/var/log/accounting.log");
 		close (FH);
 		chmod 0755, "/var/log/accounting.log";
-		#move all db entries older than 2 months to second table and cumulate them hourly
+		#move all db entries older than this month to second table and cumulate them daily
 		&ACCT::movedbdata;
 		&ACCT::logger($settings{'LOG'},"New Month. Old trafficvalues moved to ACCT_HIST Table\n");
 		if ($settings{'USEMAIL'} eq 'on'){


hooks/post-receive
--
IPFire 2.x development tree

                 reply	other threads:[~2015-04-21 18:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150421184740.02CBD21EA6@argus.ipfire.org \
    --to=git@ipfire.org \
    --cc=ipfire-scm@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox