From 66d6d91bff3ccc091621cde09ed7d60c4c10d756 Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Mon, 20 May 2013 11:20:49 +0200 Subject: [PATCH] Add WriteDelay configuration directive (default to 3600 - stores one hour of statistics from log file) to be able to save ressources on huge log file. On small log file it is not a good idea to set a lower value as SquidAnalyzer will spend his time to write and read from disk. --- SquidAnalyzer.pm | 5 +++-- etc/squidanalyzer.conf | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/SquidAnalyzer.pm b/SquidAnalyzer.pm index cae6396..4216755 100644 --- a/SquidAnalyzer.pm +++ b/SquidAnalyzer.pm @@ -416,6 +416,7 @@ sub _init $self->{SiblingHit} = $options{SiblingHit} || 1; $self->{ImgFormat} = $options{ImgFormat} || 'png'; $self->{Locale} = $options{Locale} || ''; + $self->{WriteDelay} = $options{WriteDelay} || 3600; if ($self->{Lang}) { open(IN, "$self->{Lang}") or die "ERROR: can't open translation file $self->{Lang}, $!\n"; while (my $l = ) { @@ -605,7 +606,7 @@ sub _parseData } # Store data when hour change to save memory - if ($self->{tmp_saving} && ($self->{tmp_saving} ne $hour) ) { + if ($self->{tmp_saving} && ($time > ($self->{tmp_saving} + $self->{WriteDelay})) ) { $date =~ /^(\d{4})(\d{2})(\d{2})$/; # If the day has changed then we want to save stats of the previous one $self->_save_data("$1", "$2", "$3"); @@ -617,7 +618,7 @@ sub _parseData $self->{first_year} ||= $self->{last_year}; $self->{first_month} ||= $self->{last_month}; - $self->{tmp_saving} = $hour; + $self->{tmp_saving} = $time; #### Store client statistics $self->{stat_user_hour}{$id}{$hour}{hits}++; diff --git a/etc/squidanalyzer.conf b/etc/squidanalyzer.conf index b628451..8a8a803 100644 --- a/etc/squidanalyzer.conf +++ b/etc/squidanalyzer.conf @@ -84,7 +84,15 @@ TransfertUnit BYTES MinPie 2 # Set this to your locale to display generated date in your language. Default -# is to use the current locale of the system. If you want date in German for -# example, set it to de_DE. For french, fr_FR should do the work. +# is to use strftime. If you want date in German for example, set it to de_DE. +# For french, fr_FR should do the work. #Locale en_US +# By default SquidAnalyzer is saving current collected statistics each time +# a new hour is found in log file. Most of the time this is enough but if +# you have huge log file and don't have enough memory this will slow down the +# parser by forcing Perl to use temporaries files. Use lower value following +# your memory and the size of your log file, on very huge log file with lot of +# requests/seconde a value of 30 minutes (1800) or less should help. +WriteDelay 3600 +