]> mj.ucw.cz Git - netgrind.git/blob - post/graph-hist-ip
TODO: A note on IPv6
[netgrind.git] / post / graph-hist-ip
1 #!/usr/bin/perl
2 # Draw graphs of IP traffic from netgrind histograms
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, 0 );
14 my $ew = 0.9;
15 my $eww = 1-$ew;
16 my $w = 60;
17 while (<>) {
18         chomp;
19         if (/^#/) {
20                 s/^#\s+//;
21                 @colnames = split /\t/;
22         } else {
23                 my $i = 0;
24                 s/\([^)]*\)//g;
25                 my %row = map { $colnames[$i++] => $_ } split /\t/;
26                 my $time = POSIX::strftime("%d-%m-%Y %H:%M:%S", localtime $row{'time'});
27                 my @r = (
28                         $row{'IPIn'} / $w,
29                         ($row{'IPBad'} + $row{'IPBadSum'}) / $w,
30                         $row{'IPUnint'} / $w,
31                         $row{'TCPIn'} / $w,
32                         $row{'IPFrag'} / $w
33                 );
34                 print D "$time";
35                 for (my $i=0; $i<=$#r; $i++) {
36                         $ewma[$i] = $ew*$ewma[$i] + $eww*$r[$i];
37                         print D "\t", $ewma[$i];
38                 }
39                 print D "\n";
40         }
41 }
42
43 close D;
44 open GP, "|gnuplot" or die;
45 print GP <<EOF
46 set terminal png
47 set grid
48 set style data lines
49 set title "IP packet spectrum"
50 set xlabel "Time"
51 set ylabel "Packets / s [EWMA $ew]"
52 set xdata time
53 set timefmt "%d-%m-%Y %H:%M:%S"
54 set format x "%d/%m\\n%H:%M"
55 #set xtics 86400
56 set mxtics 3600
57 plot    "$datafile" using 1:3 title "All IP packets", \\
58         "$datafile" using 1:4 title "Bad IP header", \\
59         "$datafile" using 1:5 title "Non-TCP", \\
60         "$datafile" using 1:6 title "Processed TCP", \\
61         "$datafile" using 1:7 title "Fragmented TCP"
62 EOF
63 ;
64 close GP;