]> mj.ucw.cz Git - netgrind.git/commitdiff
A simple averaging tool.
authorMartin Mares <mj@ucw.cz>
Sat, 21 Jun 2003 14:34:04 +0000 (14:34 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 21 Jun 2003 14:34:04 +0000 (14:34 +0000)
post/average [new file with mode: 0755]
post/graph-hist-ip
post/graph-http-len

diff --git a/post/average b/post/average
new file mode 100755 (executable)
index 0000000..0da1f68
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+# Simple averages and medians
+# (c) 2003 Martin Mares <mj@ucw.cz>, GPL'ed
+
+use strict;
+use warnings;
+
+`sort >avg.tmp`; $? && die;
+open I, "avg.tmp" or die;
+my $n = 0;
+my $sum = 0;
+my $max = 0;
+my $min;
+while (<I>) {
+       chomp;
+       $n++;
+       $sum += $_;
+       $max = $_;
+       $min = $_ if !defined $min;
+}
+$n || die "No data found";
+seek(I, 0, 0);
+my $median = 0;
+for (my $i=0; $i<$n/2; $i++) {
+       $median = <I>;
+       chomp $median;
+}
+my $avg = $sum/$n;
+my $qsum = 0;
+seek (I, 0, 0);
+while (<I>) {
+       chomp;
+       my $d = $_ - $avg;
+       $qsum += $d*$d;
+}
+my $var = $qsum/$n;
+my $stdd = sqrt($var);
+printf "Number of records:     %d\n", $n;
+printf "Average:               %.3f\n", $avg;
+printf "Variance:              %.3f\n", $var;
+printf "Std. deviation:                %.3f\n", $stdd;
+printf "Median:                        %.3f\n", $median;
+printf "Minimum:               %.3f\n", $min;
+printf "Maximum:               %.3f\n", $max;
+;
index 2c8ca40394d07d85dac29680e1cbd201fdd51129..82bc561d0efe6614097ec858de549ddc848f030d 100755 (executable)
@@ -57,8 +57,8 @@ set mxtics 3600
 plot   "$datafile" using 1:3 title "All IP packets", \\
        "$datafile" using 1:4 title "Bad IP header", \\
        "$datafile" using 1:5 title "Non-TCP", \\
-       "$datafile" using 1:6 title "Fragmented TCP", \\
-       "$datafile" using 1:7 title "Processed TCP"
+       "$datafile" using 1:6 title "Processed TCP", \\
+       "$datafile" using 1:7 title "Fragmented TCP"
 EOF
 ;
 close GP;
index 2549144d9e36921be2780020856c74d44048fd7f..528e5745a8277b91f2eb7e7a66a229c33477b1f6 100755 (executable)
@@ -50,7 +50,7 @@ set format x "%d/%m\\n%H:%M"
 set logscale y 2
 #set xtics 86400
 set mxtics 3600
-plot   "$datafile" using 1:3 title "Size"
+plot   [] [1:] "$datafile" using 1:3 title "Size"
 EOF
 ;
 close GP;