]> mj.ucw.cz Git - netgrind.git/blob - post/http-stats
Implemented dumping of HTTP transactions
[netgrind.git] / post / http-stats
1 #!/usr/bin/perl
2 # Calculate statistics of HTTP transactions from netgrind output
3 # (c) 2003 Martin Mares <mj@ucw.cz>, GPL'ed
4
5 use strict;
6 use warnings;
7 use POSIX;
8
9 print "# time   width   Total   TCPErr  Nocache CacheHit        CacheMiss       LenTotal        NTimings        TimeTotal       TimeTMin        TimeTMax        TimeWait        TimeWMin        TimeWMax        NGETs   NPOSTs\n";
10 my $histogran = 60;
11 my %hist = ();
12 while (<>) {
13         chomp;
14         /^#/ && next;
15         my ($t1, $t2, $src, $dst, $ffor, $result, $cache, $queue, $length, $totaltime, $waittime, $ctype, $method, $url) = split /\s+/;
16         my ($tY, $tm, $td) = split (/-/, $t1);
17         my ($tH, $tM, $tS) = split (/:/, $t2);
18         my $tt = POSIX::mktime($tS, $tM, $tH, $td, $tm-1, $tY-1900);
19         $tt -= $tt % $histogran;
20         my $h = $hist{$tt};
21         if (!defined $h) {
22                 $h = [ $histogran, 0, 0, 0, 0, 0, 0, 0, 0, 1000000000, 0, 0, 1000000000, 0, 0, 0 ];
23                 $hist{$tt} = $h;
24         }
25         $h->[1]++;
26         $h->[2]++ if $result =~ /^[TC]/;
27         $h->[3]++ if $cache =~ /^((N..)|(.[NP].))$/;
28         $h->[4]++ if $cache =~ /\+$/;
29         $h->[5]++ if $cache =~ /-$/;
30         $h->[6]+=$length;
31         if ($result =~ /^\d+$/) {
32                 $h->[7]++;
33                 $h->[8]+=$totaltime;
34                 $h->[9]=$totaltime if $h->[9] > $totaltime;
35                 $h->[10]=$totaltime if $h->[9] < $totaltime;
36                 $h->[11]+=$waittime;
37                 $h->[12]=$waittime if $h->[12] > $waittime;
38                 $h->[13]=$waittime if $h->[12] < $waittime;
39         }
40         $h->[14]++ if $method eq "GET";
41         $h->[15]++ if $method eq "POST";
42 }
43 my $ltt = 1e30;
44 foreach my $x (sort keys %hist) {
45         while ($ltt < $x) {
46                 print "$ltt\t$histogran", "\t0" x $#{$hist{$x}}, "\n";
47                 $ltt += $histogran;
48         }
49         $ltt = $x + $histogran;
50         print "$x\t", join("\t", @{$hist{$x}}), "\n";
51 }