Add RefreshTime configuration directive and -R | --refresh command line
options: Insert a html Refresh tag into all index.html files. The value is the refresh intervalle in minutes. Default to 5 minutes. Can be overridden at command line with option -R | --refresh To avoid loading index.html pages with incomplete content when SquidAnalyzer is writing into the file, SquidAnalyzer first write into a index.html.tmp file and once it is written it rename it into index.html. Thanks to Weverton Everaldo Lubask for the feature request.
This commit is contained in:
parent
22cef48251
commit
d5547c50ae
7
README
7
README
|
@ -193,6 +193,8 @@ USAGE
|
|||
Default /tmp/
|
||||
-r | --rebuild : use this option to rebuild all html and graphs
|
||||
output from all data files.
|
||||
-R | --refresh minutes : add a html refresh tag into index.html file
|
||||
with a refresh intervalle in minutes.
|
||||
-s | --start HH:MM : log lines before this time will not be parsed.
|
||||
-S | --stop HH:MM : log lines after this time will not be parsed.
|
||||
-t | --timezone +/-HH : set number of hours from GMT of the timezone.
|
||||
|
@ -551,6 +553,11 @@ CONFIGURATION
|
|||
start and stop time. Log line out of this time range will not be
|
||||
parsed. The format of the value is HH:MM
|
||||
|
||||
RefreshTime
|
||||
Insert a html Refresh tag into all index.html files. The value is
|
||||
the refresh intervalle in minutes. Default to 5 minutes. Can be
|
||||
overridden at command line with option -R | --refresh
|
||||
|
||||
SUPPORT
|
||||
Release announcement
|
||||
Please follow us on twitter to receive release announcement and latest
|
||||
|
|
|
@ -420,14 +420,14 @@ my $ug_format_regex1 = qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) .* (B
|
|||
|
||||
sub new
|
||||
{
|
||||
my ($class, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history) = @_;
|
||||
my ($class, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history, $refresh) = @_;
|
||||
|
||||
# Construct the class
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
# Initialize all variables
|
||||
$self->_init($conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history);
|
||||
$self->_init($conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history, $refresh);
|
||||
|
||||
# Return the instance
|
||||
return($self);
|
||||
|
@ -1543,7 +1543,7 @@ sub _clear_stats
|
|||
|
||||
sub _init
|
||||
{
|
||||
my ($self, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history) = @_;
|
||||
my ($self, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history, $refresh_time) = @_;
|
||||
|
||||
# Set path to pid file
|
||||
$pidfile = $pid_dir . '/' . $pidfile;
|
||||
|
@ -1666,6 +1666,7 @@ sub _init
|
|||
die "ERROR: 'LogFile' configuration directive must be set or a log file given at command line.\n";
|
||||
}
|
||||
}
|
||||
$self->{RefreshTime} = $refresh_time || $options{RefreshTime} || 0;
|
||||
$self->{OrderUser} = lc($options{OrderUser}) || 'bytes';
|
||||
$self->{OrderNetwork} = lc($options{OrderNetwork}) || 'bytes';
|
||||
$self->{OrderUrl} = lc($options{OrderUrl}) || 'bytes';
|
||||
|
@ -3057,9 +3058,16 @@ sub _append_data
|
|||
}
|
||||
|
||||
|
||||
sub _print_main_header
|
||||
{
|
||||
my ($self, $fileout, $menu, $calendar) = @_;
|
||||
|
||||
$self->_print_header($fileout, $menu, $calendar, undef, 1);
|
||||
}
|
||||
|
||||
sub _print_header
|
||||
{
|
||||
my ($self, $fileout, $menu, $calendar, $sortpos) = @_;
|
||||
my ($self, $fileout, $menu, $calendar, $sortpos, $dorefresh) = @_;
|
||||
|
||||
my $now = $self->{start_date} || strftime("%a %b %e %H:%M:%S %Y", CORE::localtime);
|
||||
$sortpos ||= 2;
|
||||
|
@ -3080,6 +3088,11 @@ sub _print_header
|
|||
}
|
||||
$reportrange .= '.';
|
||||
}
|
||||
|
||||
my $refresh_tag = '';
|
||||
if ($self->{RefreshTime}) {
|
||||
$refresh_tag = '<meta HTTP-EQUIV="refresh" CONTENT="' . $self->{RefreshTime}*60 . '">';
|
||||
}
|
||||
print $$fileout qq{
|
||||
<html>
|
||||
<head>
|
||||
|
@ -3090,6 +3103,7 @@ sub _print_header
|
|||
<meta HTTP-EQUIV="Generator" CONTENT="SquidAnalyzer $VERSION" />
|
||||
<meta HTTP-EQUIV="Date" CONTENT="$now" />
|
||||
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=$Translate{'CharSet'}" />
|
||||
$refresh_tag
|
||||
<title>$self->{CustomTitle}</title>
|
||||
<link rel="stylesheet" type="text/css" href="$self->{WebUrl}squidanalyzer.css" media="screen" />
|
||||
<!-- javascript to sort table -->
|
||||
|
@ -3587,14 +3601,14 @@ sub _print_cache_stat
|
|||
}
|
||||
my $file = $outdir . '/index.html';
|
||||
my $out = new IO::File;
|
||||
$out->open(">$file") || $self->localdie("ERROR: Unable to open $file. $!\n");
|
||||
$out->open(">$file.tmp") || $self->localdie("ERROR: Unable to open $file.tmp. $!\n");
|
||||
# Print the HTML header
|
||||
my $cal = 'SA_CALENDAR_SA';
|
||||
$cal = '' if ($week);
|
||||
if ( (!$self->{no_year_stat} || $self->{with_month_stat}) || ($type ne 'month') ) {
|
||||
$self->_print_header(\$out, $self->{menu}, $cal);
|
||||
$self->_print_main_header(\$out, $self->{menu}, $cal);
|
||||
} else {
|
||||
$self->_print_header(\$out, $self->{menu3}, $cal);
|
||||
$self->_print_main_header(\$out, $self->{menu3}, $cal);
|
||||
}
|
||||
print $out $self->_print_title($Translate{'Cache_title'}, $stat_date, $week);
|
||||
|
||||
|
@ -3840,6 +3854,7 @@ $code_bytes
|
|||
%code_stat = ();
|
||||
$self->_print_footer(\$out);
|
||||
$out->close();
|
||||
rename("$file.tmp", "$file");
|
||||
}
|
||||
|
||||
|
||||
|
@ -6007,9 +6022,9 @@ sub _gen_summary
|
|||
}
|
||||
my $file = $outdir . '/index.html';
|
||||
my $out = new IO::File;
|
||||
$out->open(">$file") || $self->localdie("ERROR: Unable to open $file. $!\n");
|
||||
$out->open(">$file.tmp") || $self->localdie("ERROR: Unable to open $file. $!\n");
|
||||
# Print the HTML header
|
||||
$self->_print_header(\$out);
|
||||
$self->_print_main_header(\$out);
|
||||
my $colspn = 3;
|
||||
$colspn = 4 if ($self->{CostPrice});
|
||||
print $out qq{
|
||||
|
@ -6087,6 +6102,7 @@ sub _gen_summary
|
|||
};
|
||||
$self->_print_footer(\$out);
|
||||
$out->close();
|
||||
rename("$file.tmp", "$file");
|
||||
|
||||
}
|
||||
|
||||
|
@ -6740,9 +6756,9 @@ sub _gen_year_summary
|
|||
}
|
||||
my $file = $outdir . '/index.html';
|
||||
my $out = new IO::File;
|
||||
$out->open(">$file") || $self->localdie("ERROR: Unable to open $file. $!\n");
|
||||
$out->open(">$file.tmp") || $self->localdie("ERROR: Unable to open $file. $!\n");
|
||||
# Print the HTML header
|
||||
$self->_print_header(\$out);
|
||||
$self->_print_main_header(\$out);
|
||||
my $colspn = 2;
|
||||
$colspn = 3 if ($self->{CostPrice});
|
||||
print $out qq{
|
||||
|
@ -6780,6 +6796,7 @@ sub _gen_year_summary
|
|||
};
|
||||
$self->_print_footer(\$out);
|
||||
$out->close();
|
||||
rename("$file.tmp", "$file");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -197,6 +197,8 @@ Usage: squid-analyzer [ -c squidanalyzer.conf ] [logfile(s)]
|
|||
Default /tmp/
|
||||
-r | --rebuild : use this option to rebuild all html and graphs
|
||||
output from all data files.
|
||||
-R | --refresh minutes : add a html refresh tag into index.html file
|
||||
with a refresh intervalle in minutes.
|
||||
-s | --start HH:MM : log lines before this time will not be parsed.
|
||||
-S | --stop HH:MM : log lines after this time will not be parsed.
|
||||
-t | --timezone +/-HH : set number of hours from GMT of the timezone.
|
||||
|
@ -585,6 +587,12 @@ The two following configuration directive allow you to specify a start and
|
|||
stop time. Log line out of this time range will not be parsed. The format
|
||||
of the value is HH:MM
|
||||
|
||||
=item RefreshTime
|
||||
|
||||
Insert a html Refresh tag into all index.html files. The value is the
|
||||
refresh intervalle in minutes. Default to 5 minutes. Can be overridden
|
||||
at command line with option -R | --refresh
|
||||
|
||||
=back
|
||||
|
||||
=head1 SUPPORT
|
||||
|
|
|
@ -187,3 +187,8 @@ TopUrlUser 10
|
|||
#TimeStart 00:00
|
||||
#TimeStop 23:59
|
||||
|
||||
# Insert a html Refresh tag into all index.html files. The value is the
|
||||
# refresh intervalle in minutes. Default to 5 minutes. Can be overridden
|
||||
# at command line with option -R | --refresh
|
||||
RefreshTime 5
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ my $stop_date = '';
|
|||
my $outputdir = '';
|
||||
my $skip_history = 0;
|
||||
my $override_history = 0;
|
||||
my $refresh_time = 0;
|
||||
|
||||
# get the command line parameters
|
||||
my $result = GetOptions (
|
||||
|
@ -50,6 +51,7 @@ my $result = GetOptions (
|
|||
"p|preserve=i" => \$preserve,
|
||||
"P|pid_dir=s" => \$pid_dir,
|
||||
"r|rebuild!" => \$rebuild,
|
||||
"R|refresh=i" => \$refresh_time,
|
||||
"s|start=s" => \$start_time,
|
||||
"S|stop=s" => \$stop_time,
|
||||
"t|timezone=s" => \$timezone,
|
||||
|
@ -128,7 +130,7 @@ close(OUT);
|
|||
unlink("$pid_dir/last_parsed.tmp");
|
||||
|
||||
# Instanciate SquidAnalyzer.pm perl module
|
||||
my $sa = new SquidAnalyzer($configfile, join(',', @logfile), $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history);
|
||||
my $sa = new SquidAnalyzer($configfile, join(',', @logfile), $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history, $refresh_time);
|
||||
$sa->{no_year_stat} = $no_year_stat;
|
||||
$sa->{with_month_stat} = $with_month_stat;
|
||||
$sa->{no_week_stat} = $no_week_stat;
|
||||
|
@ -265,6 +267,8 @@ Usage: squid-analyzer [ -c squidanalyzer.conf ] [logfile(s)]
|
|||
Default /tmp/
|
||||
-r | --rebuild : use this option to rebuild all html and graphs
|
||||
output from all data files.
|
||||
-R | --refresh minutes : add a html refresh tag into index.html file
|
||||
with a refresh intervalle in minutes.
|
||||
-s | --start HH:MM : log lines before this time will not be parsed.
|
||||
-S | --stop HH:MM : log lines after this time will not be parsed.
|
||||
-t | --timezone +/-HH : set number of hours from GMT of the timezone.
|
||||
|
|
Loading…
Reference in New Issue