From 22886a423b32b2c6ac5875f3b5744c011f9381f8 Mon Sep 17 00:00:00 2001 From: Darold Date: Thu, 20 Dec 2012 20:16:20 +0100 Subject: [PATCH] Add MinPie configuration directive to set the percentage of pie graph data which under item will be stored in others label --- SquidAnalyzer.pm | 208 ++++++++++++++++++++++------------------- etc/squidanalyzer.conf | 3 + 2 files changed, 117 insertions(+), 94 deletions(-) diff --git a/SquidAnalyzer.pm b/SquidAnalyzer.pm index 75ba0b8..48c02f8 100644 --- a/SquidAnalyzer.pm +++ b/SquidAnalyzer.pm @@ -399,6 +399,7 @@ sub _init $options{LogFile} = $log_file if ($log_file); # Configuration options + $self->{MinPie} = $options{MinPie} || 2; $self->{QuietMode} = $options{QuietMode} || 0; $self->{UrlReport} = $options{UrlReport} || 0; $self->{Output} = $options{Output} || ''; @@ -1644,46 +1645,46 @@ sub _print_network_stat $title = $Translate{'Monthly'} || 'Monthly'; $unit = $Translate{'Months'} || 'Months'; } - - my @hits = (); - my @bytes = (); - for ("$first" .. "$last") { - if (exists $total_net_detail{$_}{hits}) { - push(@hits, "[ $_, $total_net_detail{$_}{hits} ]"); - } else { - push(@hits, "[ $_, 0 ]"); - } - if (exists $total_net_detail{$_}{bytes}) { - push(@bytes, "[ $_, " . int($total_net_detail{$_}{bytes}/1000000) . " ]"); - } else { - push(@bytes, "[ $_, 0 ]"); - } - } - %total_net_detail = (); - - my $t1 = $Translate{'Graph_cache_hit_title'}; - $t1 =~ s/\%s/$title/; - $t1 = "$t1 $stat_date"; - my $xlabel = $unit || ''; - my $ylabel = $Translate{'Requests_graph'} || 'Requests'; - my $network_hits = $self->flotr2_bargraph(1, 'network_hits', $type, $t1, $xlabel, $ylabel, - join(',', @hits), $Translate{'Hit_graph'} ); - @hits = (); - print $out qq{}; - $network_hits = ''; - - - $t1 = $Translate{'Graph_cache_byte_title'}; - $t1 =~ s/\%s/$title/; - $t1 = "$t1 $stat_date"; - $xlabel = $unit || ''; - $ylabel = $Translate{'Megabytes_graph'} || $Translate{'Megabytes'}; - my $network_bytes = $self->flotr2_bargraph(1, 'network_bytes', $type, $t1, $xlabel, $ylabel, - join(',', @bytes), $Translate{'Bytes'} ); - @bytes = (); - - print $out qq{
$network_hits$network_bytes
}; - $network_bytes = ''; +# +# my @hits = (); +# my @bytes = (); +# for ("$first" .. "$last") { +# if (exists $total_net_detail{$_}{hits}) { +# push(@hits, "[ $_, $total_net_detail{$_}{hits} ]"); +# } else { +# push(@hits, "[ $_, 0 ]"); +# } +# if (exists $total_net_detail{$_}{bytes}) { +# push(@bytes, "[ $_, " . int($total_net_detail{$_}{bytes}/1000000) . " ]"); +# } else { +# push(@bytes, "[ $_, 0 ]"); +# } +# } +# %total_net_detail = (); +# +# my $t1 = $Translate{'Graph_cache_hit_title'}; +# $t1 =~ s/\%s/$title/; +# $t1 = "$t1 $stat_date"; +# my $xlabel = $unit || ''; +# my $ylabel = $Translate{'Requests_graph'} || 'Requests'; +# my $network_hits = $self->flotr2_bargraph(1, 'network_hits', $type, $t1, $xlabel, $ylabel, +# join(',', @hits), $Translate{'Hit_graph'} ); +# @hits = (); +# print $out qq{}; +# $network_hits = ''; +# +# +# $t1 = $Translate{'Graph_cache_byte_title'}; +# $t1 =~ s/\%s/$title/; +# $t1 = "$t1 $stat_date"; +# $xlabel = $unit || ''; +# $ylabel = $Translate{'Megabytes_graph'} || $Translate{'Megabytes'}; +# my $network_bytes = $self->flotr2_bargraph(1, 'network_bytes', $type, $t1, $xlabel, $ylabel, +# join(',', @bytes), $Translate{'Bytes'} ); +# @bytes = (); +# +# print $out qq{
$network_hits$network_bytes
}; +# $network_bytes = ''; print $out "

$Translate{'Network_number'}: $nnet

\n"; print $out qq{ @@ -1750,8 +1751,8 @@ sub _print_network_stat $self->_print_header(\$outnet, $self->{menu2}, $cal); print $outnet $self->_print_title("$Translate{'Network_title'} $show -", $stat_date); - @hits = (); - @bytes = (); + my @hits = (); + my @bytes = (); for ("$first" .. "$last") { if (exists $detail_network_stat{$net}{$_}{hits}) { push(@hits, "[ $_, " . $detail_network_stat{$net}{$_}{hits} . " ]"); @@ -1766,12 +1767,12 @@ sub _print_network_stat } delete $detail_network_stat{$net}; - $t1 = $Translate{'Graph_cache_hit_title'}; + my $t1 = $Translate{'Graph_cache_hit_title'}; $t1 =~ s/\%s/$title $show/; $t1 = "$t1 $stat_date"; - $xlabel = $unit || ''; - $ylabel = $Translate{'Requests_graph'} || 'Requests'; - $network_hits = $self->flotr2_bargraph(1, 'network_hits', $type, $t1, $xlabel, $ylabel, + my $xlabel = $unit || ''; + my $ylabel = $Translate{'Requests_graph'} || 'Requests'; + my $network_hits = $self->flotr2_bargraph(1, 'network_hits', $type, $t1, $xlabel, $ylabel, join(',', @hits), $Translate{'Hit_graph'} ); @hits = (); print $outnet qq{
}; @@ -1782,7 +1783,7 @@ sub _print_network_stat $t1 = "$t1 $stat_date"; $xlabel = $unit || ''; $ylabel = $Translate{'Megabytes_graph'} || $Translate{'Megabytes'}; - $network_bytes = $self->flotr2_bargraph(1, 'network_bytes', $type, $t1, $xlabel, $ylabel, + my $network_bytes = $self->flotr2_bargraph(1, 'network_bytes', $type, $t1, $xlabel, $ylabel, join(',', @bytes), $Translate{'Bytes'} ); @bytes = (); @@ -1898,48 +1899,48 @@ sub _print_user_stat $unit = $Translate{'Months'} || 'Months'; } - my @hits = (); - my @bytes = (); - for ("$first" .. "$last") { - if (exists $total_user_detail{$_}{hits}) { - push(@hits, "[ $_, $total_user_detail{$_}{hits} ]"); - } else { - push(@hits, "[ $_, 0 ]"); - } - if (exists $total_user_detail{$_}{bytes}) { - push(@bytes, "[ $_, " . int($total_user_detail{$_}{bytes}/1000000) . " ]"); - } else { - push(@bytes, "[ $_, 0 ]"); - } - } +# my @hits = (); +# my @bytes = (); +# for ("$first" .. "$last") { +# if (exists $total_user_detail{$_}{hits}) { +# push(@hits, "[ $_, $total_user_detail{$_}{hits} ]"); +# } else { +# push(@hits, "[ $_, 0 ]"); +# } +# if (exists $total_user_detail{$_}{bytes}) { +# push(@bytes, "[ $_, " . int($total_user_detail{$_}{bytes}/1000000) . " ]"); +# } else { +# push(@bytes, "[ $_, 0 ]"); +# } +# } %total_user_detail = (); print $out $self->_print_title($Translate{'User_title'}, $stat_date); print $out "

$Translate{'User_number'}: $nuser

\n"; - - my $t1 = $Translate{'Graph_cache_hit_title'}; - $t1 =~ s/\%s/$title/; - $t1 = "$t1 $stat_date"; - my $xlabel = $unit || ''; - my $ylabel = $Translate{'Requests_graph'} || 'Requests'; - my $user_hits = $self->flotr2_bargraph(1, 'user_hits', $type, $t1, $xlabel, $ylabel, - join(',', @hits), $Translate{'Hit_graph'}); - @hits = (); - print $out qq{
$network_hits
}; - $user_hits = ''; - - $t1 = $Translate{'Graph_cache_byte_title'}; - $t1 =~ s/\%s/$title/; - $t1 = "$t1 $stat_date"; - $xlabel = $unit || ''; - $ylabel = $Translate{'Megabytes_graph'} || $Translate{'Megabytes'}; - my $user_bytes = $self->flotr2_bargraph(1, 'user_bytes', $type, $t1, $xlabel, $ylabel, - join(',', @bytes), $Translate{'Bytes'}); - @bytes = (); - print $out qq{
$user_hits$user_bytes
}; - $user_bytes = ''; - +# +# my $t1 = $Translate{'Graph_cache_hit_title'}; +# $t1 =~ s/\%s/$title/; +# $t1 = "$t1 $stat_date"; +# my $xlabel = $unit || ''; +# my $ylabel = $Translate{'Requests_graph'} || 'Requests'; +# my $user_hits = $self->flotr2_bargraph(1, 'user_hits', $type, $t1, $xlabel, $ylabel, +# join(',', @hits), $Translate{'Hit_graph'}); +# @hits = (); +# print $out qq{}; +# $user_hits = ''; +# +# $t1 = $Translate{'Graph_cache_byte_title'}; +# $t1 =~ s/\%s/$title/; +# $t1 = "$t1 $stat_date"; +# $xlabel = $unit || ''; +# $ylabel = $Translate{'Megabytes_graph'} || $Translate{'Megabytes'}; +# my $user_bytes = $self->flotr2_bargraph(1, 'user_bytes', $type, $t1, $xlabel, $ylabel, +# join(',', @bytes), $Translate{'Bytes'}); +# @bytes = (); +# print $out qq{
$user_hits$user_bytes
}; +# $user_bytes = ''; +# print $out qq{ @@ -2016,8 +2017,8 @@ sub _print_user_stat $self->_print_header(\$outusr, $self->{menu2}, $cal); print $outusr $self->_print_title("$Translate{'User_title'} $usr -", $stat_date); - @hits = (); - @bytes = (); + my @hits = (); + my @bytes = (); for ("$first" .. "$last") { if (exists $detail_user_stat{$usr}{$_}{hits}) { push(@hits, "[ $_, $detail_user_stat{$usr}{$_}{hits} ]"); @@ -2032,12 +2033,12 @@ sub _print_user_stat } delete $detail_user_stat{$usr}; - $t1 = $Translate{'Graph_cache_hit_title'}; + my $t1 = $Translate{'Graph_cache_hit_title'}; $t1 =~ s/\%s/$title $show/; $t1 = "$t1 $stat_date"; - $xlabel = $unit || ''; - $ylabel = $Translate{'Requests_graph'} || 'Requests'; - $user_hits = $self->flotr2_bargraph(1, 'user_hits', $type, $t1, $xlabel, $ylabel, + my $xlabel = $unit || ''; + my $ylabel = $Translate{'Requests_graph'} || 'Requests'; + my $user_hits = $self->flotr2_bargraph(1, 'user_hits', $type, $t1, $xlabel, $ylabel, join(',', @hits), $Translate{'Hit_graph'}); @hits = (); print $outusr qq{
}; @@ -2046,8 +2047,8 @@ sub _print_user_stat $t1 = $Translate{'Graph_cache_byte_title'}; $t1 =~ s/\%s/$title $show/; $t1 = "$t1 $stat_date"; - my $xlabel = $unit || ''; - my $ylabel = $Translate{'Megabytes_graph'} || $Translate{'Megabytes'}; + $xlabel = $unit || ''; + $ylabel = $Translate{'Megabytes_graph'} || $Translate{'Megabytes'}; my $user_bytes = $self->flotr2_bargraph(1, 'user_bytes', $type, $t1, $xlabel, $ylabel, join(',', @bytes), $Translate{'Bytes'}); @bytes = (); @@ -2508,17 +2509,36 @@ sub _print_top_domain_stat print $out "

$Translate{'Domain_number'}: $nurl

\n"; my %data = (); + my $total_hits = 0; foreach my $dom (keys %perdomain) { - $data{$dom} = $perdomain{$dom}{hits}; + $total_hits += $perdomain{$dom}{hits}; + } + $total_hits ||= 1; + foreach my $dom (keys %perdomain) { + if (($perdomain{$dom}{hits}/$total_hits)*100 > $self->{MinPie}) { + $data{$dom} = $perdomain{$dom}{hits}; + } else { + $data{'others'} += $perdomain{$dom}{hits}; + } } my $title = "$Translate{'Domain_graph_hits_title'} $stat_date"; my $domain_hits = $self->flotr2_piegraph(1, 'domain_hits', $title, $Translate{'Domains_graph'}, '', %data); print $out qq{
$user_hits
}; $domain_hits = ''; %data = (); + my $total_bytes = 0; foreach my $dom (keys %perdomain) { - $data{$dom} = int($perdomain{$dom}{bytes}/1000000); + $total_bytes += $perdomain{$dom}{bytes}; } + $total_bytes ||= 1; + foreach my $dom (keys %perdomain) { + if (($perdomain{$dom}{bytes}/$total_bytes)*100 > $self->{MinPie}) { + $data{$dom} = int($perdomain{$dom}{bytes}/1000000); + } else { + $data{'others'} += $perdomain{$dom}{bytes}; + } + } + $data{'others'} = int($data{'others'}/1000000); $title = "$Translate{'Domain_graph_bytes_title'} $stat_date"; my $domain_bytes = $self->flotr2_piegraph(1, 'domain_bytes', $title, $Translate{'Domains_graph'}, '', %data); print $out qq{
$domain_hits$domain_bytes
}; diff --git a/etc/squidanalyzer.conf b/etc/squidanalyzer.conf index 7b9c908..e4eee05 100644 --- a/etc/squidanalyzer.conf +++ b/etc/squidanalyzer.conf @@ -79,3 +79,6 @@ SiblingHit 1 # Set the default unit for transfert size. Default is BYTES, other possible # values are KB, MB and GB TransfertUnit BYTES + +# Minimum percentage of data in pie's graphs to not be placed in the others item. +MinPie 2