OSSP CVS Repository

ossp - Difference in ossp-pkg/flow2rrd/flow2rrd.pl versions 1.18 and 1.19
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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