torrus misc fixes, RT10574
authorlevinse <levinse>
Thu, 3 Feb 2011 06:18:41 +0000 (06:18 +0000)
committerlevinse <levinse>
Thu, 3 Feb 2011 06:18:41 +0000 (06:18 +0000)
FS/FS/svc_port.pm
httemplate/view/svc_port.cgi

index 129fb07..ad92e68 100644 (file)
@@ -254,6 +254,8 @@ sub graph_png {
         $start = $opt{start} if $opt{start};
         $end = $opt{end} if $opt{end};
 
+       $end = $now if $end > $now;
+
         return 'Invalid date range' if ($start < 0 || $start >= $end 
             || $end <= $start || $end < 0 || $end > $now || $start > $now
             || $end-$start > 86400*366 );
@@ -292,8 +294,8 @@ sub graph_png {
         foreach my $rec ( @records ) {
             push @times, $rec->_date 
                 unless grep { $_ eq $rec->_date } @times;
-            push @in, $rec->value if $rec->serviceid =~ /_IN$/;
-            push @out, $rec->value if $rec->serviceid =~ /_OUT$/;
+            push @in, $rec->value*8 if $rec->serviceid =~ /_IN$/;
+            push @out, $rec->value*8 if $rec->serviceid =~ /_OUT$/;
         }
 
         my $timediff = $times[-1] - $times[0]; # they're sorted ascending
@@ -340,8 +342,14 @@ sub graph_png {
 
       my @data = ( \@times, \@in, \@out );
 
+      
       # hardcoded size, colour, etc.
-      my $graph = new GD::Graph::mixed(600,360);  #600,400
+
+      # don't change width/height other than through here; breaks legend otherwise
+      my $width = 600;
+      my $height = 360;
+
+      my $graph = new GD::Graph::mixed($width,$height);  
       $graph->set(
         types => ['area','lines'],
         dclrs => ['green','blue'],
@@ -364,6 +372,7 @@ sub graph_png {
             my $value = shift;
             $self->_format_bandwidth($value,1);
         },
+       y_tick_number => 'auto',
         y_label => 'bps',
         legend_placement => 'BR',
        lg_cols => 1,
@@ -389,9 +398,9 @@ sub graph_png {
       return "graph error: ".$graph->error unless($gd);
 
       my $black = $gd->colorAllocate(0,0,0);       
-      $gd->string(gdMediumBoldFont,50,285,
+      $gd->string(gdMediumBoldFont,50,$height-35,
            "Current: $in_curr   Average: $in_avg   Maximum: $in_max   Minimum: $in_min",$black);
-      $gd->string(gdMediumBoldFont,50,305,
+      $gd->string(gdMediumBoldFont,50,$height-15,
            "Current: $out_curr   Average: $out_avg   Maximum: $out_max   Minimum: $out_min",$black);
 
       return $gd->png;
index 0df8263..eec803d 100644 (file)
@@ -30,12 +30,8 @@ if ( $cgi->param('svcnum') ) {
   $svcnum = $1;
 }
 
-my $start = '';
-my $end = '';
-if ( $cgi->param('start') && $cgi->param('end') ) {
-    $start = $cgi->param('start');
-    $end = $cgi->param('end');
-}
+my $start = $cgi->param('start');
+my $end = $cgi->param('end');
 
 sub preset_range {
     my($start,$end,$label,$date_format) = (shift,shift,shift,shift);
@@ -52,7 +48,7 @@ my $html_foot = sub {
 
     if($start && $end) {
        $graph = "<BR><BR><IMG SRC=${p}/view/port_graph.html?svcnum=$svcnum;".
-               "start=".str2time($start).";end=".str2time($end).">";
+               "start=".str2time("$start 00:00:00").";end=".str2time("$end 23:59:59").">";
     }
 
     return '