Show stats.pl syntax highlighted
#!/usr/bin/perl -w
use strict;
use Date::Parse;
use Getopt::Long;
use Pod::Usage;
Getopt::Long::Configure ("bundling");
our $HELP = 0;
our $MAN = 0;
our $DEBUG = 0;
our $START = '2005/1/1 01:00';
our $END = '2020/1/1 01:00';
our $FRAMETIME_SECONDS = 24*3600; # Default of 1 day per frame
our $DOREAD = 0;
our $CUMULATIVE = 0;
GetOptions("help|h" => \$HELP,
"man" => \$MAN,
"start|s=s" => \$START,
"end|e=s" => \$END,
"animate|a=i" => \$FRAMETIME_SECONDS,
"read" => \$DOREAD,
"cumulative|c" => \$CUMULATIVE
) or pod2usage(2);
pod2usage(-exitstatus => 0, -verbose => 1) if $HELP;
pod2usage(-exitstatus => 0, -verbose => 2) if $MAN;
my $begintime = str2time($START);
my $endtime = str2time($END);
my @times;
my @totals;
my @peaks = (0,0,0,0,0,0,0,0,0,0,0);
my $resp;
our @histograms;
our @histtimes;
our @histogram;
our $histdelta = 0.1;
our $intervals = 101;
our $maxhits = 0;
my $cresp;
my $n = 0;
$" = " ";
my ($start, $end);
our $frame = 0;
my $nextframetime = $begintime;
sub nextFrame
{
my $time = shift;
if($frame) {
push @histograms, [ @histogram ];
push @histtimes, $time;
}
$frame++;
for(my $j=0; $j <= $intervals; $j++) {
$maxhits = $histogram[$j] if defined($histogram[$j]) && $histogram[$j] > $maxhits;
$histogram[$j] = 0;
}
}
my $pagepattern = 'Index.*Page Processing Time.* ([.0-9]+)\D';
$pagepattern = 'Read.*Page Processing Time.* ([.0-9]+)\D' if($DOREAD);
my ($curtime, $ts);
while(<>)
{
next if !m/$pagepattern/o;
($start) = m/(\d+\/\d+\/\d+ \d+:\d+:\d+)/ if(!defined($start));
($ts) = m/(\d+\/\d+\/\d+ \d+:\d+:\d+)/;
$curtime = str2time($ts);
if($curtime > $nextframetime) {
$nextframetime = $curtime + $FRAMETIME_SECONDS;
nextFrame($ts);
print "Starting frame $frame\n";
}
if($curtime < $begintime || $curtime > $endtime) {
$start = undef if($curtime < $begintime);
if(!defined($end) && $curtime >= $endtime) {
$end = $ts;
last;
}
next;
}
@times = m/$pagepattern/o;
$n++;
$cresp = $times[0];
$resp += $cresp; # cumulative (for avg) resp time
# convert current response time into histogram hit
$cresp /= $histdelta;
$cresp = int($cresp);
$cresp = $intervals if($cresp >= $intervals);
$histogram[$cresp]++;
}
nextFrame($ts); # finish this frame!
$end = $ts if(!defined($end));
die "No data in range" if !$n;
printf("Average Response Time: %5.3f\n", $resp / $n);
printf("Processed $n page hits from $start to $end (%4.2f/sec)\n", $n/(str2time($end) - str2time($start)));
my $idx = 1;
my ($total, $rt);
for my $frm (@histograms) {
printf("Number of long requests in frame $idx (>10s): %4d\n", $frm->[$intervals]);
open DAT, ">" . sprintf("stats%05d.dat", $idx);
$total = 0;
if($CUMULATIVE) {
for(my $j=0; $j <= $intervals; $j++) {
$total += $frm->[$j];
}
}
$rt = 0;
for(my $j=0; $j <= $intervals; $j++) {
if($CUMULATIVE) {
$rt += $frm->[$j];
print DAT sprintf("%4.2f %4.2f\n", $j*$histdelta, $rt/$total*100.0);
} else {
print DAT sprintf("%4.2f %9d\n", $j*$histdelta, $frm->[$j]);
}
}
close DAT;
$idx++;
}
my ($pagename, $ylabel, $ymax, $xtics, $plotstyle, $ytics);
if($CUMULATIVE) {
$pagename = "Cumulative for ";
$ylabel = "Percentage";
$ymax = 100;
$xtics = "set xtics 0.5";
$ytics = "set ytics 5";
$plotstyle = "lines";
} else {
$pagename = "Histogram for ";
$ylabel = "Responses";
$ymax = $maxhits;
$xtics = "set xtics 0.5";
$ytics = "";
$plotstyle = "boxes";
}
if($DOREAD) {
$pagename .= "read.html";
} else {
$pagename .= "index.html";
}
open CMDS, ">/tmp/stats.cmds";
print CMDS <<EOF;
set terminal postscript color
set title "$pagename from $start to $end"
set xlabel "Response Time (s)"
set ylabel "$ylabel"
set grid
$xtics
$ytics
set grid
set yrange [0:$ymax]
set output "stats.ps"
EOF
for(my $i=1; $i < $idx; $i++) {
print CMDS "plot " . sprintf("\"stats%05d.dat\"", $i) .
" title \"" . $histtimes[$i-1] . "\" with $plotstyle\n";
}
qx(gnuplot /tmp/stats.cmds);
warn "Unable to create plot. Gnuplot failed." if(!-f "stats.ps");
qx(ps2pdf stats.ps stats.pdf);
warn "Unable to create PDF. PS missing or ps2pdf failed" if(!-f "stats.pdf");
unlink "stats.ps";
unlink "/tmp/stats.cmds";
print "Histogram data in stats.pdf\n" if(-f "stats.pdf");
exit 0;
__END__
=head1 NAME
stats.pl - Analyze response time stats from alphamail logs.
=head1 SYNOPSIS
stats.pl [--help] [--man] [--start|-s start] [--end|-e end] [--animate|-a framelength_seconds] [--cumulative|-c] logfile...
=head1 OPTIONS
=over 8
=item B<--help, -h>
Show command help.
=item B<--man>
Show the complete manual for the command.
=item B<--start=start | -s start>
Specify the exact time and date from which to start the analysis. Accepts
timestamps in any format parsable by Date::Parse.
=item B<--end=start | -e start>
Specify the exact time and date at which to end the analysis. Accepts
timestamps in any format parsable by Date::Parse.
=item B<--animate=n | -a n>
Indicate that you want a multipage "animation" of the response times, with one
frame/page every n seconds.
=item B<--cumulative|-c>
Compute a cumulative response time graph instead of a histogram.
=back
=head1 DESCRIPTION
B<stats.pl> will read your alphamail log file and use it to generate some
useful statistics such as average response time, and average number of page
views per second. It also outputs (if gnuplot and ps2pdf are installed)
stats.pdf, which is a histogram of actual response times.
It defaults to generating one page per 24 hours of data, but the -a parameter
can be used to change this "frame" rate in order to make interesting
"animations" of your response time.
=cut
See more files for this project here
AlphaMail is an accelerated web mail interface with a C++ middleware layer that is more effective than an IMAP proxy which is a highly scalable (10k+ users). The interface includes modern features, Section 508 compliance, and universal browser support.
Project homepage:
http://sourceforge.net/projects/alphamail
Programming language(s): C++,Java,JavaScript,Perl
License: other
init.d/
alphamail_tmpfs
imap_webcache
sandbox/
Makefile.am
sandbox.cc
Makefile.am
alphamail_genconfig
awstats_gen
garbage_sweeper
hang_detector
logrotate.conf
prefs_depth.pl
size_vs_time.pl
stats.pl
update_prefs
webcache_watcher