[exim-cvs] cvs commit: exim/exim-src/src eximstats.src

Pàgina inicial
Delete this message
Reply to this message
Autor: Steve Campbell
Data:  
A: exim-cvs
Assumpte: [exim-cvs] cvs commit: exim/exim-src/src eximstats.src
steve 2004/12/20 13:12:32 GMT

  Modified files:
    exim-src/src         eximstats.src 
  Log:
  1.34 - allow eximstats to parse syslog lines as well as mainlog lines
  1.35 - bugfix such that pie charts by volume are generated correctly


  Revision  Changes    Path
  1.3       +42 -23    exim/exim-src/src/eximstats.src


  Index: eximstats.src
  ===================================================================
  RCS file: /home/cvs/exim/exim-src/src/eximstats.src,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- eximstats.src    24 Nov 2004 14:43:57 -0000    1.2
  +++ eximstats.src    20 Dec 2004 13:12:32 -0000    1.3
  @@ -1,5 +1,5 @@
   #!PERL_COMMAND -w
  -# $Cambridge: exim/exim-src/src/eximstats.src,v 1.2 2004/11/24 14:43:57 ph10 Exp $
  +# $Cambridge: exim/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.
  @@ -187,11 +187,17 @@
   # 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

@@ -360,7 +366,7 @@

=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
@@ -413,7 +419,7 @@

   @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;
  @@ -1081,7 +1087,11 @@
   @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/>/\&gt\;/g;
  @@ -1092,16 +1102,22 @@
       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);


  @@ -1117,7 +1133,7 @@
       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);
  @@ -1288,8 +1304,8 @@
          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:
  @@ -1356,10 +1372,13 @@
     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);
  @@ -2152,7 +2171,7 @@
         # 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
  @@ -2180,7 +2199,7 @@
         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);
  @@ -2200,7 +2219,7 @@
         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);
  @@ -2250,7 +2269,7 @@
         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;
  @@ -2357,7 +2376,7 @@


         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*$/) {
  @@ -2433,7 +2452,7 @@
       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.
  @@ -2658,7 +2677,7 @@
     }
     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 }