#!PERL_COMMAND -w
-# $Cambridge: exim/src/src/eximstats.src,v 1.2 2004/11/24 14:43:57 ph10 Exp $
+# $Cambridge: exim/src/src/eximstats.src,v 1.3 2004/12/20 13:12:32 steve Exp $
# Copyright (c) 2001 University of Cambridge.
# See the file NOTICE for conditions of use and distribution.
# 2004-07-15 V1.33 Steve Campbell
# Documentation update - I've converted the subroutine
# documentation from POD to comments.
+#
+# 2004-12-10 V1.34 Steve Campbell
+# Eximstats can now parse syslog lines as well as mainlog lines.
+#
+# 2004-12-20 V1.35 Andreas Metzler
+# Pie charts by volume were actually generated by count. Fixed.
=head1 NAME
-eximstats - generates statistics from Exim mainlog files.
+eximstats - generates statistics from Exim mainlog or syslog files.
=head1 SYNOPSIS
=head1 DESCRIPTION
-Eximstats parses exim mainlog files and outputs a statistical
+Eximstats parses exim mainlog and syslog files to output a statistical
analysis of the messages processed. By default, a text
analysis is generated, but you can request an html analysis
by using the B<-html> flag. See the help (B<-help>) to learn
@days_per_month = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
$gig = 1024 * 1024 * 1024;
-$VERSION = '1.33';
+$VERSION = '1.35';
# How much space do we allow for the Hosts/Domains/Emails/Edomains column headers?
$COLUMN_WIDTHS = 8;
@chartdatanames = ();
@chartdatavals = ();
$chartotherval = 0;
+my $use_gig = 0;
foreach $key (top_n_sort($topcount,$m_data_gigs,$m_data,$m_count)) {
+ if ($$m_data_gigs{$key}) {
+ $use_gig = 1;
+ }
if ($html) {
$htmlkey = $key;
$htmlkey =~ s/>/\>\;/g;
printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $key);
}
- if (scalar @chartdatanames < $ntopchart)
- {
- push(@chartdatanames, $key);
- push(@chartdatavals, $$m_count{$key});
+ if (scalar @chartdatanames < $ntopchart) {
+ if ($use_gig) {
+ if ($$m_data_gigs{$key}) {
+ push(@chartdatanames, $key);
+ push(@chartdatavals, $$m_data_gigs{$key});
+ }
}
- else
- {
- $chartotherval += $$m_count{$key};
+ else {
+ push(@chartdatanames, $key);
+ push(@chartdatavals, $$m_data{$key});
}
}
+ else {
+ $chartotherval += ($use_gig) ? $$m_data_gigs{$key} : $$m_data{$key};
+ }
+}
push(@chartdatanames, "Other");
push(@chartdatavals, $chartotherval);
my $graph = GD::Graph::pie->new(300, 300);
$graph->set(
x_label => 'Name',
- y_label => 'Volume',
+ y_label => 'Volume' ,
title => 'By Volume',
);
my $gd = $graph->plot(\@data) or warn($graph->error);
eximstats -merge [Options] report.1.txt report.2.txt ... > weekly_rep.txt
eximstats -merge -html [Options] report.1.html ... > weekly_rep.html
-Parses exim mainlog files and generates a statistical analysis of
-the messages processed. Valid options are:
+Parses exim mainlog or syslog files and generates a statistical analysis
+of the messages processed. Valid options are:
-h<number> histogram divisions per hour. The default is 1, and
0 suppresses histograms. Other valid values are:
my($ip,$host,$email,$edomain,$domain,$thissize,$size,$old,$new);
my($tod,$m_hour,$m_min,$id,$flag);
while (<$fh>) {
- next if length($_) < 38;
- # PH/FANF
- # next unless /^(\\d{4}\\-\\d\\d-\\d\\d\\s(\\d\\d):(\\d\\d):\\d\\d)/;
+ # Convert syslog lines to mainlog format.
+ if (! /^\\d{4}/) {
+ next unless s/^.*? exim\\b.*?: //;
+ }
+
+ next if length($_) < 38;
next unless /^(\\d{4}\\-\\d\\d-\\d\\d\\s(\\d\\d):(\\d\\d):\\d\\d( [-+]\\d\\d\\d\\d)?)/o;
($tod,$m_hour,$m_min) = ($1,$2,$3);
# Fill in $report_totals{Received|Delivered}{Volume|Messages|Hosts|Domains|...|Delayed|DelayedPercent|Failed|FailedPercent}
my(@fields);
while (<$fh>) {
- $_ = html2txt($_); #Convert general HTML markup to text.
+ $_ = html2txt($_); #Convert general HTML markup to text.
s/At least one addr//g; #Another part of the HTML output we don't want.
# TOTAL Volume Messages Hosts Domains Delayed Failed
while (<$fh>) { last if (/Total/); } #Wait until we get the table headers.
while (<$fh>) {
print STDERR "Parsing $_" if $debug;
- $_ = html2txt($_); #Convert general HTML markup to text.
+ $_ = html2txt($_); #Convert general HTML markup to text.
if (/^\s*(.*?)\s+(\d+)\s*$/) {
$report_totals{patterns}{$1} = {} unless (defined $report_totals{patterns}{$1});
add_to_totals($report_totals{patterns}{$1},['Total'],$2);
while (<$fh>) { last if (/Volume/); } #Wait until we get the table headers.
while (<$fh>) {
print STDERR "Parsing $_" if $debug;
- $_ = html2txt($_); #Convert general HTML markup to text.
+ $_ = html2txt($_); #Convert general HTML markup to text.
if (/(\S+)\s+(\d+\S*\s+\d+)/) {
$report_totals{transport}{$1} = {} unless (defined $report_totals{transport}{$1});
add_to_totals($report_totals{transport}{$1},['Volume','Messages'],$2);
my $bin_aref = ($1 eq 'all messages') ? \@queue_bin : \@remote_queue_bin;
my $reached_table = 0;
while (<$fh>) {
- $_ = html2txt($_); #Convert general HTML markup to text.
+ $_ = html2txt($_); #Convert general HTML markup to text.
$reached_table = 1 if (/^\s*Under/);
next unless $reached_table;
my $previous_seconds_on_queue = 0;
my $reached_table = 0;
while (<$fh>) {
- $_ = html2txt($_); #Convert general HTML markup to text.
+ $_ = html2txt($_); #Convert general HTML markup to text.
$reached_table = 1 if (/^\s*\d/);
next unless $reached_table;
if (/^\s*(\d+)\s+(\S+)\s*(.*?)\s*$/) {
next unless $reached_table;
s/^<li>(\d+) -/$1/; #Convert an HTML line to a text line.
- $_ = html2txt($_); #Convert general HTML markup to text.
+ $_ = html2txt($_); #Convert general HTML markup to text.
if (/\t\s*(.*)/) {
$error .= ' ' . $1; #Join a multiline error.
}
elsif ($ARGV[0] =~ /^-chartdir$/) { $chartdir = $ARGV[1]; shift; $charts_option_specified = 1; }
elsif ($ARGV[0] =~ /^-chartrel$/) { $chartrel = $ARGV[1]; shift; $charts_option_specified = 1; }
- elsif ($ARGV[0] =~ /^-cache$/) { } #Not currently used.
+ elsif ($ARGV[0] =~ /^-cache$/) { } #Not currently used.
elsif ($ARGV[0] =~ /^-byhost$/) { $do_sender{Host} = 1 }
elsif ($ARGV[0] =~ /^-bydomain$/) { $do_sender{Domain} = 1 }
elsif ($ARGV[0] =~ /^-byemail$/) { $do_sender{Email} = 1 }