]> mj.ucw.cz Git - netgrind.git/blob - post/graph-http-wait
...
[netgrind.git] / post / graph-http-wait
1 #!/usr/bin/perl
2 # Draw graphs of HTTP transaction delays from http-stats output
3 # (c) 2003 Martin Mares <mj@ucw.cz>, GPL'ed
4
5 use strict;
6 use warnings;
7 use POSIX;
8
9 my $maxs = (@ARGV >= 1 && $ARGV[0] eq "--max");
10
11 my $datafile = "gp.tmp";
12 open D, ">$datafile" or die;
13
14 my @colnames = ();
15 my @ewma = ( 0, 0, 0, 0, 0, 0 );
16 my $ew = 0;
17 my $eww = 1-$ew;
18 while (<STDIN>) {
19         chomp;
20         if (/^#/) {
21                 s/^#\s+//;
22                 @colnames = split /\t/;
23         } else {
24                 my $i = 0;
25                 s/\([^)]*\)//g;
26                 my %row = map { $colnames[$i++] => $_ } split /\t/;
27                 my $time = POSIX::strftime("%d-%m-%Y %H:%M:%S", localtime $row{'time'});
28                 my $n = $row{'NTimings'};
29                 my @r;
30                 if ($n) {
31                         @r = (
32                                 $row{'TimeTotal'} / $n,
33                                 $row{'TimeTMin'},
34                                 $row{'TimeTMax'},
35                                 $row{'TimeWait'} / $n,
36                                 $row{'TimeWMin'},
37                                 $row{'TimeWMax'}
38                         );
39                 } else {
40                         @r = ( 0, 0, 0, 0, 0, 0 );
41                 }
42                 print D "$time";
43                 for (my $i=0; $i<=$#r; $i++) {
44                         $ewma[$i] = $ew*$ewma[$i] + $eww*$r[$i];
45                         print D "\t", $ewma[$i];
46                 }
47                 print D "\n";
48         }
49 }
50 close D;
51
52 my $ct = $maxs ? "Maximum" : "Average";
53 my $c1 = $maxs ? 5 : 3;
54 my $c2 = $maxs ? 8 : 6;
55
56 open GP, "|gnuplot" or die;
57 print GP <<EOF
58 set terminal png
59 set grid
60 set style data lines
61 set title "HTTP Transactions: $ct Timings"
62 set xlabel "Time"
63 set ylabel "seconds [EWMA $ew]"
64 set xdata time
65 set timefmt "%d-%m-%Y %H:%M:%S"
66 set format x "%d/%m\\n%H:%M"
67 #set xtics 86400
68 #set mxtics 3600
69 plot [] [0:30] \\
70         "$datafile" using 1:$c1 title "Total time", \\
71         "$datafile" using 1:$c2 title "Reply delay"
72 EOF
73 ;
74 close GP;