diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-02-15 13:08:45 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-02-15 13:08:45 +0200 |
commit | c420667377bc294cc11b6d889cafb64722fc1fa0 (patch) | |
tree | 560b914e39081433e84b544093e2949605c07530 | |
parent | a893b27a4a9c1f2b8c26b09ae455713176528e25 (diff) | |
download | netplot-c420667377bc294cc11b6d889cafb64722fc1fa0.tar.gz netplot-c420667377bc294cc11b6d889cafb64722fc1fa0.tar.bz2 |
Configurable graph layout and colors.
The four new options control graph layout and colors: --layout,
--mirror-top, --incomping-graph, and --outgoing-graph.
-rwxr-xr-x | netplot | 159 |
1 files changed, 143 insertions, 16 deletions
@@ -32,7 +32,12 @@ my $nograph; # Don't redraw graphs. my $imgformat = "PNG"; # Create graphs of this type. my $flow_report_cfg; my @graph_size; - + +my $layout = "mirror"; +my $mirror_top = "incoming"; +my @incoming_colors = ( "336600", "32CD32" ); +my @outgoing_colors = ( "0033CC", "4169E1" ); + # Return codes: # 0 - OK, nothing changed # [1 - Not used] @@ -41,6 +46,8 @@ my @graph_size; ############# +open(LOG, ">&STDERR"); + sub logit { if ($logfile) { print LOG strftime "%b %d %H:%M:%S $script: @_\n", localtime; @@ -50,6 +57,7 @@ sub logit { } sub loginit { + close LOG; if ($logfile and (!-e $logfile or -w $logfile)) { print STDERR "$script: logging to $logfile\n"; open(LOG, ">>$logfile"); @@ -220,6 +228,8 @@ sub dograph { my $info; my $i; my @rrdargs; + my $in; + my $out; $info = RRDs::info($rrdfile); @@ -239,20 +249,55 @@ sub dograph { "--height", $graph_size[1]); } push(@rrdargs, - "DEF:in=$rrdfile:in:AVERAGE", - "DEF:out=$rrdfile:out:AVERAGE", - "CDEF:nout=out,-1,*", - "AREA:in#32CD32:Incoming", - "LINE1:in#336600", - "GPRINT:in:MAX: Max\\: %5.1lf %s", - "GPRINT:in:AVERAGE: Avg\\: %5.1lf %S", - "GPRINT:in:LAST: Current\\: %5.1lf %Sbytes/sec\\n", - "AREA:nout#4169E1:Outgoing", - "LINE1:nout#0033CC", - "GPRINT:out:MAX: Max\\: %5.1lf %s", - "GPRINT:out:AVERAGE: Avg\\: %5.1lf %S", - "GPRINT:out:LAST: Current\\: %5.1lf %Sbytes/sec\\n", - "HRULE:0#000000"); + "DEF:in=$rrdfile:in:AVERAGE", + "DEF:out=$rrdfile:out:AVERAGE"); + + if ($layout eq "mirror") { + if ($mirror_top eq "incoming") { + $in = "in"; + $out = "rev"; + push(@rrdargs, "CDEF:rev=out,-1,*"); + } elsif ($mirror_top eq "outgoing") { + $in = "rev"; + $out = "out"; + push(@rrdargs, "CDEF:rev=in,-1,*"); + } else { + abend("invalid mirror-top: $mirror_top"); + } + push(@rrdargs, "HRULE:0#000000"); + } else { + $in = "in"; + $out = "out"; + } + + my $color = ":Incoming"; + + if (defined($incoming_colors[1])) { + push(@rrdargs, "AREA:$in#".$incoming_colors[1].$color); + $color = ""; + } + + push(@rrdargs, "LINE1:$in#".$incoming_colors[0].$color) + if (defined($incoming_colors[0])); + + push(@rrdargs, + "GPRINT:in:MAX: Max\\: %5.1lf %s", + "GPRINT:in:AVERAGE: Avg\\: %5.1lf %S", + "GPRINT:in:LAST: Current\\: %5.1lf %Sbytes/sec\\n"); + + $color = ":Outgoing"; + if (defined($outgoing_colors[1])) { + push(@rrdargs, "AREA:$out#".$outgoing_colors[1].$color); + $color = ""; + } + push(@rrdargs, "LINE1:$out#".$outgoing_colors[0].$color) + if (defined($outgoing_colors[0])); + + push(@rrdargs, + "GPRINT:out:MAX: Max\\: %5.1lf %s", + "GPRINT:out:AVERAGE: Avg\\: %5.1lf %S", + "GPRINT:out:LAST: Current\\: %5.1lf %Sbytes/sec\\n"); + debug('GRAPH',3,"args: ".join(' ', @rrdargs)); RRDs::graph(@rrdargs) unless ($dry_run); my $err=RRDs::error; @@ -261,6 +306,20 @@ sub dograph { } } +sub getcolors { + my @ret = split(/:/, shift); + + abend("invalid colors specification: $_") if ($#ret == -1 || $#ret > 1); + if ($#ret == 0) { + $ret[1] = undef; + } + $ret[0] = undef if ($ret[0] eq "" || $ret[0] eq "-"); + $ret[1] = undef if ($ret[1] eq "" || $ret[1] eq "-"); + + return @ret; +} + + ########### ($script = $0) =~ s/.*\///; @@ -316,8 +375,29 @@ GetOptions("help|h" => \$help, "graph-size:s" => sub { @graph_size = split(/[xX]/, $_[1]); abend("bad size specification: $_[1]") unless ($#graph_size == 1); + }, + "layout:s" => sub { + if ($_[1] eq "traditional" or $_[1] eq "mirror") { + $layout = $_[1]; + } else { + abend("unrecognized layout: $_[1]"); + } + }, + "mirror-top:s" => sub { + if ($_[1] eq "in" or $_[1] eq "incoming") { + $mirror_top = "incoming"; + } elsif ($_[1] eq "out" or $_[1] eq "outgoing") { + $mirror_top = "outgoing"; + } else { + abend("mirror-top must be one of: in, incoming, out, outgoing"); + } + }, + "incoming-graph:s" => sub { + @incoming_colors = getcolors($_[1]); + }, + "outgoing-graph:s" => sub { + @outgoing_colors = getcolors($_[1]); } - ) or exit(3); pod2usage(-message => "$script: $descr", -exitstatus => 0) if $help; @@ -434,6 +514,53 @@ B<NETFLOW REPORT CONFIGURATION>, for a detailed discussion. Sets the size of the graph pictures to create. =back + +Graph layout and colors: + +=over 4 + +=item B<--layout>=B<traditional>|B<mirror> + +Selects the graph layout. The B<traditional> layout represents both +incoming and outgoing graphs in the same coordinate plane. The B<mirror> +layout represents them in two adjacent coordinate places, having the +same time axis and with traffic axes going into opposite directions. +This is the default layout. + +=item B<--mirror-top>=B<incoming>|B<outgoing> + +If B<mirror> layout is used, this option select which of the graphs should +occupy the upper coordinate place. The default is B<incoming>. + +The argument can be abbreviated as B<in> instead for B<incoming> or +B<out> for B<outgoing>. + +=item B<--incoming-graph>=I<LINE>[:I<AREA>] + +Selects colors to use for incoming graph. Each color should be a 6-digit +RGB specfication (e.g. B<7f7f7f> for grey color). The I<LINE> paramenter +specifies the color for the graph line, and I<AREA> supplies the filling +color for the area below the graph. Any of them can be omitted, or given +as B<-> (dash). For example, B<--incoming-graph=ff0000> means that the +incloming graph should be drawn as a red line, without filling its area. + +=item B<--outgoing-graph=I<LINE>[:I<AREA>] + +Selects colors to use for outgoing graph. See above for the description +of parameters. + +Defaults are: + + --incoming-graph=336600:32CD32 --outgoing-graph=0033CC:4169E1 + +which gives the green area for incoming graph and blue area for outgoing +graph. Note, that if you prefer the traditional layout, it is wise to +disable area filling for one of the graphs. For example, the options +below produce graphs in an old MRTG-like fashion: + + --layout=traditional --outgoing-graph=ff0000 + +=back Options controlling log and debug output: |