\n";
print "\n";
- print "Messages | Bytes | \u$text | \n";
+ print "
---|
Messages | Bytes | Average | \u$text | \n";
# Align non-local addresses to the right (so all the .com's line up).
# Local addresses are aligned on the left as they are userids.
my $align = ($text !~ /local/i) ? 'right' : 'left';
- $format = "
---|
%d | %s | %s | \n";
+ $format = " %d | %s | %s | %s | \n";
}
else {
printf("%s\n%s\n\n", $temp, "-" x length($temp));
$format = "%7d %10s %s\n";
}
-my($key,$htmlkey);
+my($key,$htmlkey,$rounded_volume,$rounded_average,$count,$data,$gigs);
foreach $key (top_n_sort($topcount,$m_count,$m_data_gigs,$m_data)) {
if ($html) {
$htmlkey = $key;
$htmlkey =~ s/>/\>\;/g;
$htmlkey =~ s/\<\;/g;
- printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $htmlkey);
+
+ # When displaying the average figures, we calculate the average of
+ # the rounded data, as the user would calculate it. This reduces
+ # the accuracy slightly, but we have to do it this way otherwise
+ # when using -merge to convert results from text to HTML and
+ # vice-versa discrepencies would occur.
+ $rounded_volume = volume_rounded($$m_data{$key},$$m_data_gigs{$key});
+ $data = $gigs = 0;
+ un_round($rounded_volume,\$data,\$gigs);
+ $count = $$m_count{$key};
+ $rounded_average = volume_rounded($data/$count,$gigs/$count);
+ printf($format, $count, $rounded_volume, $rounded_average, $htmlkey);
}
else {
printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $key);
@@ -1078,7 +1092,7 @@ if ($html) {
print "\n";
print "\n";
print "\n";
- print "Messages | Bytes | \u$text | \n";
+ print "
---|
Messages | Bytes | Average | \u$text | \n";
}
else {
printf("%s\n%s\n\n", $temp, "-" x length($temp));
@@ -1089,6 +1103,9 @@ else {
$chartotherval = 0;
my $use_gig = 0;
foreach $key (top_n_sort($topcount,$m_data_gigs,$m_data,$m_count)) {
+ # The largest volume will be the first (top of the list).
+ # If it has at least 1 gig, then just use gigabytes to avoid
+ # risking an integer overflow when generating the pie charts.
if ($$m_data_gigs{$key}) {
$use_gig = 1;
}
@@ -1096,7 +1113,13 @@ foreach $key (top_n_sort($topcount,$m_data_gigs,$m_data,$m_count)) {
$htmlkey = $key;
$htmlkey =~ s/>/\>\;/g;
$htmlkey =~ s/\<\;/g;
- printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $htmlkey);
+
+ $rounded_volume = volume_rounded($$m_data{$key},$$m_data_gigs{$key});
+ $data = $gigs = 0;
+ un_round($rounded_volume,\$data,\$gigs);
+ $count = $$m_count{$key};
+ $rounded_average = volume_rounded($data/$count,$gigs/$count);
+ printf($format, $count, $rounded_volume, $rounded_average, $htmlkey);
}
else {
printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $key);
@@ -1157,22 +1180,22 @@ print "\n";
#######################################################################
# top_n_sort();
-#
+#
# @sorted_keys = top_n_sort($n,$href1,$href2,$href3);
-#
+#
# Given a hash which has numerical values, return the sorted $n keys which
# point to the top values. The second and third hashes are used as
# tiebreakers. They all must have the same keys.
-#
+#
# The idea behind this routine is that when you only want to see the
# top n members of a set, rather than sorting the entire set and then
# plucking off the top n, sort through the stack as you go, discarding
# any member which is lower than your current n'th highest member.
-#
+#
# This proves to be an order of magnitude faster for large hashes.
# On 200,000 lines of mainlog it benchmarked 9 times faster.
# On 700,000 lines of mainlog it benchmarked 13.8 times faster.
-#
+#
# We assume the values are > 0.
#######################################################################
sub top_n_sort {
@@ -1198,15 +1221,15 @@ sub top_n_sort {
my $n_minus_1 = $n - 1;
my $n_minus_2 = $n - 2;
- # Pick out the top $n keys.
+ # Pick out the top $n keys.
my($key,$value1,$value2,$value3,$i,$comparison,$insert_position);
while (($key,$value1) = each %$href1) {
#print STDERR "key $key ($value1,",$href2->{$key},",",$href3->{$key},") <=> ($minimum_value1,$minimum_value2,$minimum_value3)\n";
-
+
# Check to see that the new value is bigger than the lowest of the
# top n keys that we're keeping.
- $comparison = $value1 <=> $minimum_value1 ||
+ $comparison = $value1 <=> $minimum_value1 ||
$href2->{$key} <=> $minimum_value2 ||
$href3->{$key} <=> $minimum_value3 ||
$top_n_key cmp $key;
@@ -1233,7 +1256,7 @@ sub top_n_sort {
for ($i = 0; $i < $n_minus_1; $i++) {
$top_n_key = $top_n_keys[$i];
if ( ($top_n_key eq '_') ||
- ( ($value1 <=> $href1->{$top_n_key} ||
+ ( ($value1 <=> $href1->{$top_n_key} ||
$value2 <=> $href2->{$top_n_key} ||
$value3 <=> $href3->{$top_n_key} ||
$top_n_key cmp $key) == 1
@@ -1265,9 +1288,9 @@ sub top_n_sort {
#######################################################################
# html_header();
-#
+#
# $header = html_header($title);
-#
+#
# Print our HTML header and start the block.
#######################################################################
sub html_header {
@@ -1289,9 +1312,9 @@ EoText
#######################################################################
# help();
-#
+#
# help();
-#
+#
# Display usage instructions and exit.
#######################################################################
sub help {
@@ -1354,15 +1377,15 @@ EoText
#######################################################################
# generate_parser();
-#
+#
# $parser = generate_parser();
-#
+#
# This subroutine generates the parsing routine which will be
# used to parse the mainlog. We take the base operation, and remove bits not in use.
# This improves performance depending on what bits you take out or add.
-#
+#
# I've tested using study(), but this does not improve performance.
-#
+#
# We store our parsing routing in a variable, and process it looking for #IFDEF (Expression)
# or #IFNDEF (Expression) statements and corresponding #ENDIF (Expression) statements. If
# the expression evaluates to true, then it is included/excluded accordingly.
@@ -1701,9 +1724,9 @@ sub generate_parser {
#######################################################################
# parse();
-#
+#
# parse($parser,\*FILEHANDLE);
-#
+#
# This subroutine accepts a parser and a filehandle from main and parses each
# line. We store the results into global variables.
#######################################################################
@@ -1724,9 +1747,9 @@ sub parse {
#######################################################################
# print_header();
-#
+#
# print_header();
-#
+#
# Print our headers and contents.
#######################################################################
sub print_header {
@@ -1780,9 +1803,9 @@ sub print_header {
#######################################################################
# print_grandtotals();
-#
+#
# print_grandtotals();
-#
+#
# Print the grand totals.
#######################################################################
sub print_grandtotals {
@@ -1867,9 +1890,9 @@ EoText
#######################################################################
# print_user_patterns()
-#
+#
# print_user_patterns();
-#
+#
# Print the counts of user specified patterns.
#######################################################################
sub print_user_patterns {
@@ -1915,9 +1938,9 @@ sub print_user_patterns {
#######################################################################
# print_transport();
-#
+#
# print_transport();
-#
+#
# Print totals by transport.
#######################################################################
sub print_transport {
@@ -2020,9 +2043,9 @@ sub print_transport {
#######################################################################
# print_relay();
-#
+#
# print_relay();
-#
+#
# Print our totals by relay.
#######################################################################
sub print_relay {
@@ -2066,9 +2089,9 @@ sub print_relay {
#######################################################################
# print_errors();
-#
+#
# print_errors();
-#
+#
# Print our errors. In HTML, we display them as a list rather than a table -
# Netscape doesn't like large tables!
#######################################################################
@@ -2094,7 +2117,7 @@ sub print_errors {
$text =~ s/\s\s+/ /g; #Convert multiple spaces to a single space.
$total_errors += $errors_count{$key};
if ($html) {
-
+
#Translate HTML tag characters. Sergey Sholokh.
$text =~ s/\\<\;/g;
$text =~ s/\>/\>\;/g;
@@ -2124,36 +2147,36 @@ sub print_errors {
#######################################################################
# parse_old_eximstat_reports();
-#
+#
# parse_old_eximstat_reports($fh);
-#
+#
# Parse old eximstat output so we can merge daily stats to weekly stats and weekly to monthly etc.
-#
+#
# To test that the merging still works after changes, do something like the following.
# All the diffs should produce no output.
-#
+#
# options='-bydomain -byemail -byhost -byedomain'
# options="$options -pattern 'Completed Messages' /Completed/"
# options="$options -pattern 'Received Messages' /<=/"
-#
+#
# ./eximstats $options mainlog > mainlog.txt
# ./eximstats $options -merge mainlog.txt > mainlog.2.txt
# diff mainlog.txt mainlog.2.txt
-#
+#
# ./eximstats $options -html mainlog > mainlog.html
# ./eximstats $options -merge -html mainlog.txt > mainlog.2.html
# diff mainlog.html mainlog.2.html
-#
+#
# ./eximstats $options -merge mainlog.html > mainlog.3.txt
# diff mainlog.txt mainlog.3.txt
-#
+#
# ./eximstats $options -merge -html mainlog.html > mainlog.3.html
# diff mainlog.html mainlog.3.html
-#
+#
# ./eximstats $options -nvr mainlog > mainlog.nvr.txt
# ./eximstats $options -merge mainlog.nvr.txt > mainlog.4.txt
# diff mainlog.txt mainlog.4.txt
-#
+#
# # double_mainlog.txt should have twice the values that mainlog.txt has.
# ./eximstats $options mainlog mainlog > double_mainlog.txt
#######################################################################
@@ -2334,6 +2357,9 @@ sub parse_old_eximstat_reports {
#-------------------------------------
#
# 48 1468KB local
+# Could also have average values for HTML output.
+# 48 1468KB 30KB local
+
my($category,$by_count_or_volume) = ($1,$2);
#As we show 2 views of each table (by count and by volume),
@@ -2379,6 +2405,10 @@ sub parse_old_eximstat_reports {
$_ = html2txt($_); #Convert general HTML markup to text.
$reached_table = 1 if (/^\s*\d/);
next unless $reached_table;
+
+ # Remove optional 'average value' column.
+ s/^\s*(\d+)\s+(\S+)\s+(\d+(KB|MB|GB|\b)\s+)/$1 $2 /;
+
if (/^\s*(\d+)\s+(\S+)\s*(.*?)\s*$/) {
my($count,$rounded_volume,$entry) = ($1,$2,$3);
#Note: $entry fields can be both null and can contain spaces.
@@ -2483,9 +2513,9 @@ sub parse_old_eximstat_reports {
#######################################################################
# update_relayed();
-#
+#
# update_relayed($count,$sender,$recipient);
-#
+#
# Adds an entry into the %relayed hash. Currently only used when
# merging reports.
#######################################################################
@@ -2508,12 +2538,12 @@ sub update_relayed {
#######################################################################
# add_to_totals();
-#
+#
# add_to_totals(\%totals,\@keys,$values);
-#
+#
# Given a line of space seperated values, add them into the provided hash using @keys
# as the hash keys.
-#
+#
# If the value contains a '%', then the value is set rather than added. Otherwise, we
# convert the value to bytes and gigs. The gigs get added to I-gigs.
#######################################################################
@@ -2538,11 +2568,11 @@ sub add_to_totals {
#######################################################################
# get_report_total();
-#
+#
# $total = get_report_total(\%hash,$key);
-#
+#
# If %hash contains values split into Units and Gigs, we calculate and return
-#
+#
# $hash{$key} + 1024*1024*1024 * $hash{"${key}-gigs"}
#######################################################################
sub get_report_total {
@@ -2556,9 +2586,9 @@ sub get_report_total {
#######################################################################
# html2txt();
-#
+#
# $text_line = html2txt($html_line);
-#
+#
# Convert a line from html to text. Currently we just convert HTML tags to spaces
# and convert >, <, and tags back.
#######################################################################
@@ -2579,16 +2609,16 @@ sub html2txt {
#######################################################################
# get_next_arg();
-#
+#
# $arg = get_next_arg();
-#
+#
# Because eximstats arguments are often passed as variables,
# we can't rely on shell parsing to deal with quotes. This
# subroutine returns $ARGV[1] and does a shift. If $ARGV[1]
# starts with a quote (' or "), and doesn't end in one, then
# we append the next argument to it and shift again. We repeat
# until we've got all of the argument.
-#
+#
# This isn't perfect as all white space gets reduced to one space,
# but it's as good as we can get! If it's esential that spacing
# be preserved precisely, then you get that by not using shell
---|
| |