Changeset 234


Ignore:
Timestamp:
Oct 14, 2009, 6:23:52 PM (11 years ago)
Author:
zerodeux
Message:
Feature: -ppath-only, Fixes: warn if no logfile, warn if no samples
Location:
phptop
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • phptop/TODO

    r230 r234  
    1 - Warn if no logfile is found
    21- Limit URI column width
    3 - Option to strip http://host part
    42- HTML output mode
    53- Allow many -s options to generate multiple reports in one pass
    64  (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 ?)
  • phptop/phptop

    r231 r234  
    2626
    2727my $package_name    = 'phptop';
    28 my $package_version = '0.1';
     28my $package_version = '0.2-dev';
    2929my $package_owner   = 'Copyright (C) 2009 Bearstech - http://bearstech.com/';
    3030my $package_url     = 'http://forge.bearstech.com/trac/wiki/PhpTop';
     
    3838my $sortkey = 'hit';
    3939my $span = 60;
    40 push(@log, '/var/log/apache2/error*log', '/var/log/apache2/*/error*log') if !@log;
     40my $path_only;
    4141
    4242
     
    4444    print STDERR <<EOF;
    4545Usage: $package_name [options]
     46
    4647Try '$package_name --help' for more information.
    4748EOF
     
    5859  -h, --help       Display this information
    5960  -l, --log path   Logfiles to parse, you may use several -l and wildcards
     61  -p, --path-only  Only print path, skip http://host
    6062  -s, --sort key   Sort key: hit, time, user, sys, mem or inc (default is $sortkey)
    6163  -t, --time N     Consider log events from now back to N minutes (default is $span)
     
    7678
    7779sub print_version {
    78     print <<EOF;
    79 $package_name $package_version
    80 EOF
     80    print "$package_name $package_version\n";
    8181    exit 0;
    8282}
     
    8888    'h|help'         => \$help,
    8989    'l|log=s'        => \@log,
     90    'p|path'         => \$path_only,
    9091    's|sort=s'       => \$sortkey,
    9192    't|time=s'       => \$span,
     
    9899
    99100my @logfiles;
     101push(@log, '/var/log/apache2/error*log', '/var/log/apache2/*/error*log') if !@log;
    100102map { push(@logfiles, glob($_)) } @log;
    101103
     
    105107
    106108my %stat;
     109my $lognb = 0;
    107110foreach (@logfiles) {
    108111    my $lh;
     
    111114        next;
    112115    }
     116    $lognb++;
    113117
    114118    while (<$lh>) {
     
    119123
    120124        my ($uri, $pairs) = ($1, $2);
    121         $uri =~ s/index\.php\/?//;  # / == /index.php (99.9% of the time)
     125        $uri =~ s/index\.php\/?//;  # / == /index.php (99.9% of the time)
    122126        $uri =~ s/\?.*// if not defined $full_query;
     127        $uri =~ s/^https?:\/\/[^\/]+// if defined $path_only;
    123128
    124129        # Only keep records within expected time span. If a time stamp is not found or
    125         # cannot be parsed, we still process the item.
     130        # cannot be parsed, we still process the item.
    126131        if (/^\[(.*?)\]/) {
    127             my $stamp = str2time($1);
    128             next if defined $stamp && ($now - $stamp) > $span;
     132        my $stamp = str2time($1);
     133        next if defined $stamp && ($now - $stamp) > $span;
    129134        }
    130135
     
    146151}
    147152
     153if ($lognb == 0) {
     154    print STDERR "Error: no log files found. Path/globs tried: ".join(", ", @log)."\n";
     155    exit 2;
     156}
     157
     158my @hits = values %stat;
     159if (not @hits) {
     160    print STDERR "No phptop records found.\n";
     161    exit 0;
     162}
     163
    148164# Convert memory and include values from total to 'per hit', more useful and meaningful
    149 foreach (values %stat) {
     165foreach (@hits) {
    150166    $_->{'mem_max'} /= 2**20;  # Also scale memory values from bytes to MB
    151167    $_->{'mem'} /= $_->{'hit'} * 2**20;
Note: See TracChangeset for help on using the changeset viewer.