From 0fa8d28e8fe5f6a9a04b8d13b4dc6bb6b1f54c8f Mon Sep 17 00:00:00 2001 From: Alexander Marx Date: Tue, 21 Apr 2015 11:25:29 +0200 Subject: [PATCH] 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. --- 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(-) diff --git a/lfs/squid-accounting b/lfs/squid-accounting index 7eae4fbb62..af7b281e4f 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 eabb0c2956..1ec9849eb7 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< - - + + diff --git a/src/squid-accounting/acct-lib.pl b/src/squid-accounting/acct-lib.pl index 7969a50239..6891235848 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 79fc7bae43..7222689458 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'){ -- 2.39.2