]> mj.ucw.cz Git - netgrind.git/blob - post/graph-http-cache
Added various graphing and filtering utilities.
[netgrind.git] / post / graph-http-cache
1 #!/usr/bin/perl
2 # Draw graphs of HTTP transaction caching 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 $datafile = "gp.tmp";
10 open D, ">$datafile" or die;
11
12 my @colnames = ();
13 my @ewma = ( 0, 0, 0, 0 );
14 my $ew = 0.9;
15 my $eww = 1-$ew;
16 while (<>) {
17         chomp;
18         if (/^#/) {
19                 s/^#\s+//;
20                 @colnames = split /\t/;
21         } else {
22                 my $i = 0;
23                 s/\([^)]*\)//g;
24                 my %row = map { $colnames[$i++] => $_ } split /\t/;
25                 my $time = POSIX::strftime("%d-%m-%Y %H:%M:%S", localtime $row{'time'});
26                 my $w = $row{'width'};
27                 my @r = (
28                         $row{'Total'} / $w,
29                         $row{'Nocache'} / $w,
30                         $row{'CacheHit'} / $w,
31                         $row{'CacheMiss'} / $w
32                 );
33                 print D "$time";
34                 for (my $i=0; $i<=$#r; $i++) {
35                         $ewma[$i] = $ew*$ewma[$i] + $eww*$r[$i];
36                         print D "\t", $ewma[$i];
37                 }
38                 print D "\n";
39         }
40 }
41
42 close D;
43 open GP, "|gnuplot" or die;
44 print GP <<EOF
45 set terminal png
46 set grid
47 set style data lines
48 set title "HTTP Transactions: Cacheability"
49 set xlabel "Time"
50 set ylabel "Transactions/s [EWMA $ew]"
51 set xdata time
52 set timefmt "%d-%m-%Y %H:%M:%S"
53 set format x "%d/%m\\n%H:%M"
54 #set xtics 86400
55 set mxtics 3600
56 plot    "$datafile" using 1:3 title "Total", \\
57         "$datafile" using 1:4 title "Not cacheable", \\
58         "$datafile" using 1:5 title "Cache hits", \\
59         "$datafile" using 1:6 title "Cache misses"
60 EOF
61 ;
62 close GP;