[freeside-commits] freeside/FS/FS svc_port.pm,1.10,1.11
Ivan,,,
ivan at wavetail.420.am
Tue Mar 1 22:33:50 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv5858
Modified Files:
svc_port.pm
Log Message:
95th percentile line?
Index: svc_port.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_port.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -d -r1.10 -r1.11
--- svc_port.pm 3 Feb 2011 06:18:41 -0000 1.10
+++ svc_port.pm 2 Mar 2011 06:33:48 -0000 1.11
@@ -3,15 +3,16 @@
use strict;
use vars qw($conf $system $DEBUG $me );
use base qw( FS::svc_Common );
+use List::Util qw(max);
+use Date::Format qw(time2str);
+use Data::Dumper;
+use GD;
+use GD::Graph;
+use GD::Graph::mixed;
use FS::UID qw( driver_name );
use FS::Record qw( qsearch qsearchs
str2time_sql str2time_sql_closing concat_sql );
use FS::cust_svc;
-use GD::Graph;
-use GD::Graph::mixed;
-use GD;
-use Date::Format qw(time2str);
-use Data::Dumper;
$DEBUG = 1;
$me = '[FS::svc_port]';
@@ -242,11 +243,18 @@
$value;
}
+sub _percentile {
+ my $self = shift;
+ my @values = sort { $a <=> $b } @{$_[0]};
+ $values[ int(.95 * $#values) ];
+}
+
sub graph_png {
my($self, %opt) = @_;
my $serviceid = $self->serviceid;
- if($serviceid && $system eq 'Torrus_Internal') {
+ return '' unless $serviceid && $system eq 'Torrus_Internal'; #empty/error png?
+
my $start = -1;
my $end = -1;
my $now = time;
@@ -333,14 +341,19 @@
my $in_avg = $self->_format_bandwidth($in_sum/$numsamples);
my $out_avg = $self->_format_bandwidth($out_sum/$numsamples);
- warn "$me timediff=$timediff bwdiff=$bwdiff start=$start end=$end "
- . "in_min=$in_min out_min=$out_min in_max=$in_max "
- . "out_max=$out_max in_avg=$in_avg out_avg=$out_avg "
- . " # records = " . scalar(@records) . "\n\ntimes:\n"
- . Dumper(@times) . "\n\nin:\n" . Dumper(@in) . "\n\nout:\n"
- . Dumper(@out) if $DEBUG > 1;
+ my $percentile = max( $self->_percentile(\@in), $self->_percentile(\@out) );
+ my @percentile = ( $percentile x scalar(@in) );
+ $percentile = $self->_format_bandwidth($percentile); #for below
- my @data = ( \@times, \@in, \@out );
+ warn "$me timediff=$timediff bwdiff=$bwdiff start=$start end=$end ".
+ "in_min=$in_min out_min=$out_min in_max=$in_max ".
+ "out_max=$out_max in_avg=$in_avg out_avg=$out_avg ".
+ "percentile=$percentile ".
+ " # records = " . scalar(@records) . "\n\ntimes:\n".
+ Dumper(@times) . "\n\nin:\n" . Dumper(@in) . "\n\nout:\n". Dumper(@out)
+ if $DEBUG > 1;
+
+ my @data = ( \@times, \@in, \@out, \@percentile );
# hardcoded size, colour, etc.
@@ -351,8 +364,8 @@
my $graph = new GD::Graph::mixed($width,$height);
$graph->set(
- types => ['area','lines'],
- dclrs => ['green','blue'],
+ types => ['area','lines','lines'],
+ dclrs => ['green','blue','red',],
x_label => ' ',
x_tick_number => 'auto',
x_number_format => sub {
@@ -381,7 +394,7 @@
$graph->set_text_clr('black')
or return "can't set text colour: ".$graph->error;
- $graph->set_legend(('In','Out'))
+ $graph->set_legend(('In','Out','95th'))
or return "can't set legend: ".$graph->error;
$graph->set_title_font(['verdana', 'arial', gdGiantFont], 16)
or return "can't set title font: ".$graph->error;
@@ -398,17 +411,16 @@
return "graph error: ".$graph->error unless($gd);
my $black = $gd->colorAllocate(0,0,0);
- $gd->string(gdMediumBoldFont,50,$height-35,
+ $gd->string(gdMediumBoldFont,50,$height-55,
"Current: $in_curr Average: $in_avg Maximum: $in_max Minimum: $in_min",$black);
- $gd->string(gdMediumBoldFont,50,$height-15,
+ $gd->string(gdMediumBoldFont,50,$height-35,
"Current: $out_curr Average: $out_avg Maximum: $out_max Minimum: $out_min",$black);
+ $gd->string(gdMediumBoldFont,50,$height-15,
+ "95th percentile: $percentile", $black);
return $gd->png;
}
- '';
-}
-
=back
=head1 BUGS
More information about the freeside-commits
mailing list