freebsd-ports/net-mgmt/routers2-extras/files/patch-95.pl
Martin Wilke e3e42399d8 Extras extensions and third party scripts for routers2 frontend
WWW: http://www.steveshipway.org/software/

PR:		ports/106720
Submitted by:	Xavier Beaudouin <kiwi at oav.net>
2006-12-14 22:24:26 +00:00

83 lines
2 KiB
Perl

--- 95.pl.orig Thu Dec 14 16:22:04 2006
+++ 95.pl Thu Dec 14 16:22:56 2006
@@ -0,0 +1,80 @@
+#!%%PERL%%
+
+use strict;
+use Getopt::Long;
+
+# Options
+my %option;
+
+sub usage
+{
+ print <<"EOA"
+usage: 95 --rrd=/path/to/rrdfile.rdd
+ --rrd=file rrdfile to be used to compute the 95 percentil
+ --help this help
+ -h this help
+EOA
+}
+
+sub main
+{
+ my $rrd;
+ my $line;
+ my $value;
+ my $percentile95;
+ my $percentile95i;
+ my $percentile95o;
+ my @rrdfetch;
+ my @allvalues;
+ my @allvaluesi;
+ my @allvalueso;
+ my $in;
+ my $out;
+ my @array;
+
+ die unless GetOptions(
+ 'help|h' => \$option{'help'},
+ 'rrd=s' => \$option{'rrd'},
+ );
+
+ if ($option{'help'}) {
+ usage();
+ exit;
+ }
+
+ unless (defined $option{'rrd'} ) {
+ usage();
+ die 'rrdfile is not specified';
+ }
+
+ $rrd = $option{'rrd'};
+
+ #@rrdfetch=qx(/usr/local/bin/rrdtool fetch $rrd AVERAGE -r 300 -s -30000 -e -300);
+# @rrdfetch=qx(/usr/local/bin/rrdtool fetch $rrd AVERAGE -r 300 -s -24h);
+# @rrdfetch=qx(/usr/local/bin/rrdtool fetch $rrd AVERAGE -r 300 -s -24h -e -300);
+ #@rrdfetch=qx(/usr/local/bin/rrdtool fetch $rrd AVERAGE -r 300 -s -1m -e -300);
+ @rrdfetch=qx(/usr/local/bin/rrdtool fetch $rrd AVERAGE -r 300 -s -1month);
+ chomp @array;
+ foreach $line (@rrdfetch) {
+ split(/\s+/,$line);
+ $in = $_[1]; $out = $_[2];
+ #$value=($_[1] > $_[2]) ? $_[1] : $_[2];
+ $value=($in > $out) ? $in : $out;
+ push (@allvalues,$value);
+ push (@allvaluesi,$in);
+ push (@allvalueso,$out);
+ }
+
+ @allvalues=sort {$a <=> $b} @allvalues;
+ $percentile95=sprintf("%.2f",($allvalues[(sprintf("%.0f",(@allvalues*0.95))-1)]*8/1000));
+ @allvaluesi=sort {$a <=> $b} @allvaluesi;
+ $percentile95i=sprintf("%.2f",($allvaluesi[(sprintf("%.0f",(@allvaluesi*0.95))-1)]*8/1000));
+ @allvalueso=sort {$a <=> $b} @allvalueso;
+ $percentile95o=sprintf("%.2f",($allvalueso[(sprintf("%.0f",(@allvalueso*0.95))-1)]*8/1000));
+ print "In/Out : $percentile95 KBytes\n";
+ print "In : $percentile95i KBytes\n";
+ print "Out : $percentile95o KBytes\n";
+
+}
+
+main();