Add --no-year-stat to disable year statistics, reports will start at month level.

This commit is contained in:
Darold Gilles 2013-05-29 01:03:58 +02:00
parent 7a8e2b7bea
commit 1e609e8b5c
2 changed files with 120 additions and 28 deletions

View File

@ -356,6 +356,7 @@ sub parseFile
} }
# Compute year statistics # Compute year statistics
if (!$self->{no_year_stat}) {
if (!$self->{QuietMode}) { if (!$self->{QuietMode}) {
print STDERR "Compute and dump year statistics for $self->{first_year} to $self->{last_year}\n"; print STDERR "Compute and dump year statistics for $self->{first_year} to $self->{last_year}\n";
} }
@ -365,6 +366,7 @@ sub parseFile
} }
} }
} }
}
} }
@ -446,6 +448,7 @@ sub _init
$self->{Locale} = $options{Locale} || ''; $self->{Locale} = $options{Locale} || '';
$self->{WriteDelay} = $options{WriteDelay} || 3600; $self->{WriteDelay} = $options{WriteDelay} || 3600;
$self->{TopUrlUser} = $options{TopUrlUser} || 0; $self->{TopUrlUser} = $options{TopUrlUser} || 0;
$self->{no_year_stat} = 0;
if ($self->{Lang}) { if ($self->{Lang}) {
open(IN, "$self->{Lang}") or die "ERROR: can't open translation file $self->{Lang}, $!\n"; open(IN, "$self->{Lang}") or die "ERROR: can't open translation file $self->{Lang}, $!\n";
@ -587,6 +590,14 @@ sub _init
<li><a href="../../mime_type.html"><span class="iconMime">$Translate{'Mime_link'}</span></a></li> <li><a href="../../mime_type.html"><span class="iconMime">$Translate{'Mime_link'}</span></a></li>
</ul> </ul>
</div> </div>
};
$self->{menu3} = qq{
<div id="menu">
<ul>
<li><a href="../index.html"><span class="iconArrow">$Translate{'Back_link'}</span></a></li>
</ul>
</div>
}; };
} }
@ -1306,7 +1317,11 @@ sub buildHTML
$self->gen_html_output($outdir, $y); $self->gen_html_output($outdir, $y);
} }
if (!$self->{no_year_stat}) {
$self->_gen_summary($outdir); $self->_gen_summary($outdir);
} else {
$self->_gen_year_summary($outdir);
}
} }
sub gen_html_output sub gen_html_output
@ -1376,10 +1391,10 @@ sub _print_cache_stat
} }
# Load code statistics # Load code statistics
my $infile = new IO::File;
$infile->open("$outdir/stat_code.dat") || return;
my %code_stat = (); my %code_stat = ();
my %detail_code_stat = (); my %detail_code_stat = ();
my $infile = new IO::File;
if ($infile->open("$outdir/stat_code.dat")) {
while (my $l = <$infile>) { while (my $l = <$infile>) {
chomp($l); chomp($l);
my ($code, $data) = split(/\s/, $l); my ($code, $data) = split(/\s/, $l);
@ -1400,6 +1415,7 @@ sub _print_cache_stat
} }
} }
$infile->close(); $infile->close();
}
my $total_request = $code_stat{HIT}{request} + $code_stat{MISS}{request}; my $total_request = $code_stat{HIT}{request} + $code_stat{MISS}{request};
my $total_bytes = $code_stat{HIT}{bytes} + $code_stat{MISS}{bytes}; my $total_bytes = $code_stat{HIT}{bytes} + $code_stat{MISS}{bytes};
@ -1408,11 +1424,22 @@ sub _print_cache_stat
$out->open(">$file") || die "ERROR: Unable to open $file. $!\n"; $out->open(">$file") || die "ERROR: Unable to open $file. $!\n";
# Print the HTML header # Print the HTML header
my $cal = $self->_get_calendar($stat_date, $type, $outdir); my $cal = $self->_get_calendar($stat_date, $type, $outdir);
if ( $self->{no_year_stat} && ($type eq 'month') ) {
$self->_print_header(\$out, $self->{menu3}, $cal);
} else {
$self->_print_header(\$out, $self->{menu}, $cal); $self->_print_header(\$out, $self->{menu}, $cal);
}
# Print title and calendar view # Print title and calendar view
print $out $self->_print_title($Translate{'Cache_title'}, $stat_date); print $out $self->_print_title($Translate{'Cache_title'}, $stat_date);
if ( $self->{no_year_stat} && ($type eq 'month') ) {
%code_stat = ();
$self->_print_footer(\$out);
$out->close();
return;
}
my $total_cost = sprintf("%2.2f", int($total_bytes/1000000) * $self->{CostPrice}); my $total_cost = sprintf("%2.2f", int($total_bytes/1000000) * $self->{CostPrice});
my $comma_bytes = $self->format_bytes($total_bytes); my $comma_bytes = $self->format_bytes($total_bytes);
my $hit_bytes = $self->format_bytes($code_stat{HIT}{bytes}); my $hit_bytes = $self->format_bytes($code_stat{HIT}{bytes});
@ -3471,6 +3498,67 @@ sub check_ip
return 0; return 0;
} }
sub _gen_year_summary
{
my ($self, $outdir) = @_;
# Get all day subdirectory
opendir(DIR, "$outdir") or die "ERROR: Can't read directory $outdir, $!\n";
my @dirs = grep { /^\d{4}$/ && -d "$outdir/$_" } readdir(DIR);
closedir DIR;
my %code_stat = ();
my %total_request = ();
my %total_bytes = ();
foreach my $d (@dirs) {
$code_stat{$d} = 1;
}
my $file = $outdir . '/index.html';
my $out = new IO::File;
$out->open(">$file") || die "ERROR: Unable to open $file. $!\n";
# Print the HTML header
$self->_print_header(\$out);
my $colspn = 2;
$colspn = 3 if ($self->{CostPrice});
print $out qq{
<h4>$Translate{'Globals_Statistics'}</h4>
<div class="line-separator"></div>
<table class="stata">
<thead>
<tr>
<th scope="col">$Translate{'Years'}</th>
</tr>
</thead>
<tbody>
};
foreach my $year (sort {$b <=> $a} keys %code_stat) {
print $out qq{
<tr>
<td><a href="$year/index.html">$Translate{'Stat_label'} $year *</a></td>
</tr>
};
}
print $out qq{
</tbody>
</table>
<blockquote class="notification">(*) $Translate{'Click_year_stat'}</blockquote>
<h4>$Translate{'Legend'}</h4>
<div class="line-separator"></div>
<div class="displayLegend">
<span class="legendeTitle">$Translate{'Hit'}</span>: <span class="descLegend">$Translate{'Hit_help'}</span><br/>
<span class="legendeTitle">$Translate{'Miss'}</span>: <span class="descLegend">$Translate{'Miss_help'}</span><br/>
};
print $out qq{<span class="legendeTitle">$Translate{'Cost'}</span>: <span class="descLegend">$Translate{'Cost_help'} $self->{CostPrice} $self->{Currency}</span><br/>} if ($self->{CostPrice});
print $out qq{
</div>
};
$self->_print_footer(\$out);
$out->close();
}
1; 1;
__END__ __END__

View File

@ -18,6 +18,7 @@ my $preserve = '';
my $debug = 0; my $debug = 0;
my $version = 0; my $version = 0;
my $build_date = ''; my $build_date = '';
my $no_year_stat = 0;
# get the command line parameters # get the command line parameters
my $result = GetOptions ( my $result = GetOptions (
@ -29,6 +30,7 @@ my $result = GetOptions (
"r|rebuild!" => \$rebuild, "r|rebuild!" => \$rebuild,
"p|preserve=i" => \$preserve, "p|preserve=i" => \$preserve,
"v|version!" => \$version, "v|version!" => \$version,
"no-year-stat!" => \$no_year_stat,
); );
# Show version and exit # Show version and exit
@ -59,6 +61,8 @@ if (!$configfile || $help) {
# Instanciate SquidAnalyzer.pm perl module # Instanciate SquidAnalyzer.pm perl module
my $sa = new SquidAnalyzer($configfile, $logfile, $debug, $rebuild); my $sa = new SquidAnalyzer($configfile, $logfile, $debug, $rebuild);
$sa->{no_year_stat} = $no_year_stat;
# Run parsing only if we have a log file or that we are not in rebuild mode # Run parsing only if we have a log file or that we are not in rebuild mode
$sa->parseFile() if (!$rebuild || $logfile); $sa->parseFile() if (!$rebuild || $logfile);