OSSP CVS Repository

ossp - Check-in [4938]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4938
Date: 2004-Dec-30 16:56:00 (local)
2004-Dec-30 15:56:00 (UTC)
User:rse
Branch:
Comment: Calculate a more reasonable Y axis auto-scaling based on average numbers instead of maximum numbers.
Tickets:
Inspections:
Files:
ossp-pkg/flow2rrd/ChangeLog      1.13 -> 1.14     4 inserted, 0 deleted
ossp-pkg/flow2rrd/flow2rrd.pl      1.18 -> 1.19     41 inserted, 2 deleted

ossp-pkg/flow2rrd/ChangeLog 1.13 -> 1.14

--- ChangeLog    2004/12/29 15:22:00     1.13
+++ ChangeLog    2004/12/30 15:56:00     1.14
@@ -10,6 +10,10 @@
 
   Changes between 0.9.1 and 0.9.2 (26-Dec-2004 to 27-Dec-2004):
 
+    *) Calculate a more reasonable Y axis auto-scaling based
+       on average numbers instead of maximum numbers.
+       [Ralf S. Engelschall]
+
     *) Better formatting of legend by manually aligning elements
        in width-dependent number of columns and by prefixing elements
        with calculated average traffic.


ossp-pkg/flow2rrd/flow2rrd.pl 1.18 -> 1.19

--- flow2rrd.pl  2004/12/29 15:45:56     1.18
+++ flow2rrd.pl  2004/12/30 15:56:00     1.19
@@ -672,7 +672,7 @@
             push(@args, @def);
             push(@args, @cdef);
             push(@args, @draw);
-            my ($rrd_averages, $rrd_xsize, $rrd_ysize) = RRDs::graph(@args);
+            my ($rrd_averages, $rrd_xsize, $rrd_ysize) = &rrd_graph(@args);
             my $err = RRDs::error();
             die "failed to generate graph from RRD file: $err" if (defined($err));
         }
@@ -782,10 +782,49 @@
             push(@args, @def);
             push(@args, @cdef);
             push(@args, @draw);
-            my ($rrd_averages, $rrd_xsize, $rrd_ysize) = RRDs::graph(@args);
+            my ($rrd_averages, $rrd_xsize, $rrd_ysize) = &rrd_graph(@args);
             my $err = RRDs::error();
             die "failed to generate graph from RRD file: $err" if (defined($err));
         }
+
+        #   render an RRD graph (frontend to RRDs::graph() function)
+        sub rrd_graph {
+            my (@args) = @_;
+            my ($rrd_results, $rrd_xsize, $rrd_ysize);
+
+            #   if no Y axis limits are specified, try to determine
+            #   reasonable ones based on the calculated average values
+            #   (instead of the maximum values RRDTool uses by default)
+            if (not grep { $_ =~ m/^--(?:upper|lower)-limit$/ } @args) {
+                my @a = @args;
+                @a = map  { s/^GPRINT/PRINT/s; $_ }
+                     grep { $_ !~ m/^(AREA|STACK|LINE|HRULE|VRULE):/ }
+                     @a;
+                ($rrd_results, $rrd_xsize, $rrd_ysize) = RRDs::graph(@a);
+                my $err = RRDs::error();
+                if (not defined($err)) {
+                    my $print = join(" ", @{$rrd_results});
+                    if ($print =~ m/Total Average Traffic:\s+(\S+)\s+out\s+\/\s+(\S+)\s+in/s) {
+                        my ($ulimit, $llimit) = (&canon($1), &canon($2));
+                        sub canon {
+                            my ($limit) = @_;
+                            if    ($limit =~ m|^([+-]?\d+)k$|) { $limit = $1 * 1000;           }
+                            elsif ($limit =~ m|^([+-]?\d+)M$|) { $limit = $1 * 1000*1000;      }
+                            elsif ($limit =~ m|^([+-]?\d+)G$|) { $limit = $1 * 1000*1000*1000; }
+                            return $limit;
+                        }
+                        $ulimit = int($ulimit * 1.5);
+                        $llimit = int($llimit * 1.5);
+                        push(@args, '--upper-limit', $ulimit);
+                        push(@args, '--lower-limit', $llimit);
+                    }
+                }
+            }
+
+            #   pass through the arguments to the RRDs::graph() function
+            ($rrd_results, $rrd_xsize, $rrd_ysize) = RRDs::graph(@args);
+            return ($rrd_results, $rrd_xsize, $rrd_ysize);
+        }
     }
 }
 

CVSTrac 2.0.1