);
close DNSFILE;
if ($savetohash) {
@@ -3317,7 +3352,18 @@ sub Lock_Update {
return;
}
-
+#--------------------------------------------------------------------
+# Function: Signal handler to call Lock_Update to remove lock file
+# Parameters: None
+# Input: None
+# Output: None
+# Return: None
+#--------------------------------------------------------------------
+sub SigHandler {
+ #my $signame = shift;
+ &Lock_Update(0);
+ sleep 10;
+}
#--------------------------------------------------------------------
@@ -3645,8 +3691,6 @@ for (my $ix=1; $ix<=12; $ix++) {
if ($Debug) { debug("UpdateStats is $UpdateStats",2); }
if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Update only on index page or when not framed to avoid update twice
- &Lock_Update(1);
-
my $lastprocessedyear=$lastyearbeforeupdate;
my $lastprocessedmonth=$ListOfYears{$lastyearbeforeupdate}||0;
my $lastprocessedyearmonth=sprintf("%04i%02i",$lastprocessedyear,$lastprocessedmonth);
@@ -3775,55 +3819,44 @@ if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Updat
$PerlParsingFormat .= "([^$LogSeparator]+)";
}
elsif ($f =~ /%time1b$/) {
- $pos_date = $i;
- $i++;
+ $pos_date = $i; $i++;
$PerlParsingFormat .= "\\[([^$LogSeparator]+)\\]";
}
elsif ($f =~ /%time1$/) {
- $pos_date = $i;
- $i++;
+ $pos_date = $i; $i++;
#$pos_zone = $i;
#$i++;
#$PerlParsingFormat .= "\\[([^$LogSeparator]+) ([^$LogSeparator]+)\\]";
$PerlParsingFormat .= "\\[([^$LogSeparator]+) [^$LogSeparator]+\\]";
}
elsif ($f =~ /%time2$/) {
- $pos_date = $i;
- $i++;
+ $pos_date = $i; $i++;
$PerlParsingFormat .= "([^$LogSeparator]+ [^$LogSeparator]+)";
}
elsif ($f =~ /%methodurl$/) {
- $pos_method = $i;
- $i++;
- $pos_url = $i;
- $i++;
+ $pos_method = $i; $i++;
+ $pos_url = $i; $i++;
$PerlParsingFormat .= "\\\"([^$LogSeparator]+) ([^$LogSeparator]+) [^\\\"]+\\\"";
}
elsif ($f =~ /%methodurlnoprot$/) {
- $pos_method = $i;
- $i++;
- $pos_url = $i;
- $i++;
+ $pos_method = $i; $i++;
+ $pos_url = $i; $i++;
$PerlParsingFormat .= "\\\"([^$LogSeparator]+) ([^$LogSeparator]+)\\\"";
}
elsif ($f =~ /%method$/) {
- $pos_method = $i;
- $i++;
+ $pos_method = $i; $i++;
$PerlParsingFormat .= "([^$LogSeparator]+)";
}
elsif ($f =~ /%url$/) {
- $pos_url = $i;
- $i++;
+ $pos_url = $i; $i++;
$PerlParsingFormat .= "([^$LogSeparator]+)";
}
elsif ($f =~ /%query$/) {
- $pos_query = $i;
- $i++;
+ $pos_query = $i; $i++;
$PerlParsingFormat .= "([^$LogSeparator]+)";
}
elsif ($f =~ /%code$/) {
- $pos_code = $i;
- $i++;
+ $pos_code = $i; $i++;
$PerlParsingFormat .= "([\\d|-]+)";
}
elsif ($f =~ /%bytesd$/) {
@@ -3888,6 +3921,14 @@ if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Updat
# Processing log
#------------------------------------------
+
+ # Trap signals to remove lock
+ $SIG{INT} = \&SigHandler; # 2
+ #$SIG{KILL} = \&SigHandler; # 9
+ #$SIG{TERM} = \&SigHandler; # 15
+
+ &Lock_Update(1);
+
if ($Debug) { debug("Start Update process (lastprocessedmonth=$lastprocessedmonth, lastprocessedyear=$lastprocessedyear)"); }
$NbOfLinesRead=$NbOfLinesDropped=$NbOfLinesCorrupted=$NbOfOldLines=$NbOfNewLines=0;
@@ -3908,16 +3949,15 @@ if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Updat
if ($ShowSteps && ($NbOfLinesRead % $NBOFLINESFORBENCHMARK == 0)) {
my $delay=GetDelaySinceStart(0);
print "$NbOfLinesRead lines processed ($delay ms, ".int(1000*$NbOfLinesRead/($delay>0?$delay:1))." lines/second)\n";
-# if ($Debug) {
-# print " _host_p:".(scalar keys %_host_p)." _host_h:".(scalar keys %_host_h)." _host_k:".(scalar keys %_host_k)." _host_l:".(scalar keys %_host_l)." _host_s:".(scalar keys %_host_s)." _host_u:".(scalar keys %_host_u)."\n";
-# print " _url_p:".(scalar keys %_url_p)." _url_k:".(scalar keys %_url_k)." _url_e:".(scalar keys %_url_e)." _url_x:".(scalar keys %_url_x)."\n";
-# print " _waithost_e:".(scalar keys %_waithost_e)." _waithost_l:".(scalar keys %_waithost_l)." _waithost_s:".(scalar keys %_waithost_s)." _waithost_u:".(scalar keys %_waithost_u)."\n";
-# }
+ #if ($Debug) {
+ # print " _host_p:".(scalar keys %_host_p)." _host_h:".(scalar keys %_host_h)." _host_k:".(scalar keys %_host_k)." _host_l:".(scalar keys %_host_l)." _host_s:".(scalar keys %_host_s)." _host_u:".(scalar keys %_host_u)."\n";
+ # print " _url_p:".(scalar keys %_url_p)." _url_k:".(scalar keys %_url_k)." _url_e:".(scalar keys %_url_e)." _url_x:".(scalar keys %_url_x)."\n";
+ # print " _waithost_e:".(scalar keys %_waithost_e)." _waithost_l:".(scalar keys %_waithost_l)." _waithost_s:".(scalar keys %_waithost_s)." _waithost_u:".(scalar keys %_waithost_u)."\n";
+ #}
}
# Parse line record to get all required fields
- @field=map(/^$PerlParsingFormat/,$_);
- if (! @field) {
+ if (! (@field=map(/^$PerlParsingFormat/,$_))) {
$NbOfLinesCorrupted++;
if ($ShowCorrupted) {
if ($_ =~ /^#/ || $_ =~ /^!/) {
@@ -3935,7 +3975,6 @@ if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Updat
next;
}
-
if ($Debug) { debug(" Correct format line $NbOfLinesRead : host=\"$field[$pos_rc]\", logname=\"$field[$pos_logname]\", date=\"$field[$pos_date]\", method=\"$field[$pos_method]\", url=\"$field[$pos_url]\", code=\"$field[$pos_code]\", size=\"$field[$pos_size]\", referer=\"$field[$pos_referer]\", agent=\"$field[$pos_agent]\"",4); }
#if ($Debug) { debug("$field[$pos_vh] - $field[$pos_gzipin] - $field[$pos_gzipout] - $field[$pos_gzipratio]\n",4); }
@@ -3966,7 +4005,6 @@ if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Updat
}
# Split DD/Month/YYYY:HH:MM:SS or YYYY-MM-DD HH:MM:SS or MM/DD/YY\tHH:MM:SS
- #if ($LogFormat == 3) { $field[$pos_date] =~ tr/-\/ \t/::::/; }
$field[$pos_date] =~ tr/-\/ \t/::::/; # " \t" is used instead of "\s" not known with tr
my @dateparts=split(/:/,$field[$pos_date]); # tr and split faster than @dateparts=split(/[\/\-:\s]/,$field[$pos_date])
if ($dateparts[0] =~ /^....$/) { my $tmp=$dateparts[0]; $dateparts[0]=$dateparts[2]; $dateparts[2]=$tmp; }
@@ -4555,12 +4593,12 @@ if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Updat
}
- # Every 100,000 approved lines we test to clean too large hash arrays to free memory when possible
- if ($counter++ > 100000) {
+ # Every 200,000 approved lines we test to clean too large hash arrays to free memory when possible
+ if ($counter++ > 200000) {
$counter=0;
if ($Debug) { debug("We clean some hash arrays",2); }
#%TmpDNSLookup=(); # Do we clean this one ?
-# %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser =();
+ #%TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser =();
# TODO Add a warning
# warning("Try to made AWStats update more frequently to process log files with less than 1 000 000 records.");
}
@@ -4673,6 +4711,11 @@ if ($UpdateStats && $FrameName ne "index" && $FrameName ne "mainleft") { # Updat
&Lock_Update(0);
+ # Restore signals handler
+ $SIG{INT} = 'DEFAULT'; # 2
+ #$SIG{KILL} = 'DEFAULT'; # 9
+ #$SIG{TERM} = 'DEFAULT'; # 15
+
}
# End of log processing if ($UPdateStats)
@@ -5128,10 +5171,10 @@ EOF
}
else { print "$Message[102]: ".(scalar keys %_url_p)." $Message[28]"; }
print "";
- print "| $Message[29] | ";
- print " $Message[106] | ";
- print " $Message[104] | ";
- print " $Message[116] | ";
+ print " $Message[29] | ";
+ print " $Message[106] | ";
+ print " $Message[104] | ";
+ print " $Message[116] | ";
if ($Plugin_etf1) { AddOn_ShowFields(""); }
print " | \n";
$total_p=$total_k=$total_e=$total_x=0;
@@ -5194,7 +5237,7 @@ EOF
$rest_x=$TotalExits-$total_x;
$rest_k=$TotalBytesPages-$total_k;
if ($rest_p > 0 || $rest_e > 0 || $rest_k) {
- print "| $Message[2] | $rest_p | ".($rest_k?Format_Bytes($rest_k/$rest_p||1):" ")." | ".($rest_e?$rest_e:" ")." | ".($rest_x?$rest_x:" ")." | |
\n";
+ print "| $Message[2] | ".($rest_p?$rest_p:" ")." | ".($rest_k?Format_Bytes($rest_k/$rest_p||1):" ")." | ".($rest_e?$rest_e:" ")." | ".($rest_x?$rest_x:" ")." | |
\n";
}
&tab_end;
&html_end;
@@ -5832,11 +5875,11 @@ EOF
print "$_login_p{$key} | $_login_h{$key} | ".Format_Bytes($_login_k{$key})." | ";
if ($_login_l{$key}) { print "".Format_Date($_login_l{$key},1)." | "; }
else { print "- | "; }
-# print "";
-# print "![\"$Message[56]: \"$Message[56]:](\"$DirIcons\/other\/$BarImageHorizontal_p\") \n";
-# print "![\"$Message[57]: \"$Message[57]:](\"$DirIcons\/other\/$BarImageHorizontal_h\") \n";
-# print " ";
-# print " | ";
+ #print "";
+ #print "![\"$Message[56]: \"$Message[56]:](\"$DirIcons\/other\/$BarImageHorizontal_p\") \n";
+ #print "![\"$Message[57]: \"$Message[57]:](\"$DirIcons\/other\/$BarImageHorizontal_h\") \n";
+ #print " ";
+ #print " | ";
print "\n";
$total_p += $_login_p{$key};
$total_h += $_login_h{$key};
@@ -5999,7 +6042,7 @@ EOF
printf("%s | %s | %s | %s (%s%) | ",Format_Bytes($_filetypes_k{$key}),Format_Bytes($_filetypes_gz_in{$key}),Format_Bytes($_filetypes_gz_out{$key}),Format_Bytes($_filetypes_gz_in{$key}-$_filetypes_gz_out{$key}),$percent);
}
else {
- printf("%s | | | ",Format_Bytes($_filetypes_k{$key}));
+ printf("%s | | | | ",Format_Bytes($_filetypes_k{$key}));
}
}
else {