Changeset 258


Ignore:
Timestamp:
Nov 6, 2009, 1:51:46 AM (11 years ago)
Author:
zerodeux
Message:

Bugfixes: broken per URL hit counters, keep up with bogus log records

Location:
phptop
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • phptop/NEWS

    r257 r258  
    11phptop 0.3 - unreleased
    22
    3         *
     3        * Fixed per URL hit counter, was totally bogus (over-estimated)
     4    * More strict log checking with 5 mandatory key:value pairs
     5      (PHP or Apache seem to wrap single input strint to multiple log
     6       lines sometimes)
     7    * More elegant global hits/sample counter
    48
    59phptop 0.2.1 - 2009-11-05
  • phptop/TODO

    r256 r258  
     1- More strict log checking with mandatory keys
    12- Limit URI column width
    23- HTML output mode
    34- Allow many -s options to generate multiple reports in one pass
    45  (very useful with HTML mode, eg. generate a full report every hour)
    5 - Handle gzipped logs (easy, but useful ?)
    6 - Handle log from stdin (easy, but useful ?)
    76- Use 'tac' to parse logs if available (faster)
  • phptop/phptop

    r257 r258  
    108108my %stat;
    109109my $lognb = 0;
     110my $hits  = 0;
    110111foreach (@logfiles) {
    111112    my $lh;
     
    130131        # cannot be parsed, we still process the item.
    131132        if (/^\[(.*?)\]/) {
    132         my $stamp = str2time($1);
    133         next if defined $stamp && ($now - $stamp) > $span;
     133            my $stamp = str2time($1);
     134            next if defined $stamp && ($now - $stamp) > $span;
    134135        }
    135136
     137        # Protect against bogus/wrapped phptop records, count pairs
     138        my @kv = split(/ /, $pairs);
     139        next if @kv < 5;
     140
    136141        # For each 'key:<numeric val>' sum the numeric value per URI
    137         foreach (split(/ /, $pairs)) {
     142        foreach (@kv) {
    138143            my ($key, $val) = split(/:/, $_);
     144            $stat{$uri}{$key} += $val;
     145
     146            # Compute max for some values (mem, inc)
    139147            if ($key eq 'mem') {
    140148                $stat{$uri}{'mem_max'} = $val if ($stat{$uri}{'mem_max'} || 0) < $val;
    141149            }
    142             if ($key eq 'inc') {
     150            elsif ($key eq 'inc') {
    143151                $stat{$uri}{'inc_max'} = $val if ($stat{$uri}{'inc_max'} || 0) < $val;
    144152            }
    145             $stat{$uri}{'hit'}++;
    146             $stat{$uri}{$key} += $val;
    147153        }
     154
     155        $stat{$uri}{'hit'}++;
     156        $hits++;
    148157    }
    149158
     
    155164    exit 2;
    156165}
    157 
    158 my @hits = values %stat;
    159 if (not @hits) {
     166if ($hits == 0) {
    160167    print STDERR "No phptop records found.\n";
    161168    exit 0;
     
    163170
    164171# Convert memory and include values from total to 'per hit', more useful and meaningful
    165 foreach (@hits) {
    166     $_->{'mem_max'} /= 2**20;  # Also scale memory values from bytes to MB
    167     $_->{'mem'} /= $_->{'hit'} * 2**20;
    168     $_->{'inc'} /= $_->{'hit'};
     172while (my ($url, $i) = each %stat) {
     173    $i->{'mem_max'} /= 2**20;  # Also scale memory values from bytes to MB
     174    $i->{'mem'} /= $i->{'hit'} * 2**20;
     175    $i->{'inc'} /= $i->{'hit'};
    169176}
    170177
Note: See TracChangeset for help on using the changeset viewer.