aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-02-15 16:03:01 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-02-15 16:03:01 +0200
commit287a3f9fa6f522720075fa0e837f0921b7110691 (patch)
treebee4f403ae6573f3c4766c9958a1958611d4ed7c
parentc420667377bc294cc11b6d889cafb64722fc1fa0 (diff)
downloadnetplot-287a3f9fa6f522720075fa0e837f0921b7110691.tar.gz
netplot-287a3f9fa6f522720075fa0e837f0921b7110691.tar.bz2
Specify the order in which graphs are drawn.
The order makes sense only for traditional layout. The default order is incoming first, outgoing next. It is changed if one of the graphs has its area filled and the other has not, in which case the former is output first, lest it obscures the other.
-rwxr-xr-xnetplot120
1 files changed, 81 insertions, 39 deletions
diff --git a/netplot b/netplot
index 6d1eb01..99026ee 100755
--- a/netplot
+++ b/netplot
@@ -37,6 +37,7 @@ my $layout = "mirror";
my $mirror_top = "incoming";
my @incoming_colors = ( "336600", "32CD32" );
my @outgoing_colors = ( "0033CC", "4169E1" );
+my @order;
# Return codes:
# 0 - OK, nothing changed
@@ -220,6 +221,27 @@ sub collect_ips_from_rrds {
close($fd);
}
+# addgraph(legend,var,varname,colors)
+sub addgraph {
+ my ($args,$legend,$var,$varname,$colors) = @_;
+
+ my $suf = ":$legend";
+
+ if (defined($colors->[1])) {
+ push(@$args, "AREA:$var#".$colors->[1].$suf);
+ $suf = "";
+ }
+
+ push(@$args, "LINE1:$var#".$colors->[0].$suf)
+ if (defined($colors->[0]));
+
+ push(@$args,
+ "GPRINT:$varname:MAX: Max\\: %5.1lf %s",
+ "GPRINT:$varname:AVERAGE: Avg\\: %5.1lf %S",
+ "GPRINT:$varname:LAST: Current\\: %5.1lf %Sbytes/sec\\n");
+
+}
+
my @graphs = ("day", "week", "month", "year");
sub dograph {
@@ -270,34 +292,15 @@ sub dograph {
$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 = "";
+ foreach my $x (@order) {
+ if ($x eq "incoming") {
+ addgraph(\@rrdargs, "Incoming",$in,"in",\@incoming_colors);
+ } elsif ($x eq "outgoing") {
+ addgraph(\@rrdargs, "Outgoing",$out,"out",\@outgoing_colors);
+ } else {
+ abend("invalid order component: $x");
+ }
}
- 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;
@@ -319,7 +322,11 @@ sub getcolors {
return @ret;
}
-
+my %comp = ( 'in' => 'incoming',
+ 'incoming' => 'incoming',
+ 'out' => 'outgoing',
+ 'outgoing' => 'outgoing' );
+
###########
($script = $0) =~ s/.*\///;
@@ -384,14 +391,21 @@ GetOptions("help|h" => \$help,
}
},
"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";
+ if (defined($comp{$_[1]})) {
+ $mirror_top = $comp{$_[1]};
} else {
- abend("mirror-top must be one of: in, incoming, out, outgoing");
+ abend("unrecognized argument to mirror-top");
}
},
+ "order:s" => sub {
+ @order = split(/,/, $_[1]);
+ abend("invalid number of components in the order")
+ if ($#order == -1 or $#order > 1);
+ @order = map {
+ abend("unrecognized argument to order: $_")
+ if (!defined($comp{$_}));
+ $comp{$_}; } @order;
+ },
"incoming-graph:s" => sub {
@incoming_colors = getcolors($_[1]);
},
@@ -403,6 +417,22 @@ GetOptions("help|h" => \$help,
pod2usage(-message => "$script: $descr", -exitstatus => 0) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
+# Select the default order
+if ($layout eq "traditional") {
+ if ($#order == -1) {
+ if (defined($outgoing_colors[1]) and !defined($incoming_colors[1])) {
+ @order = ( "outgoing", "incoming" );
+ } else {
+ if (defined($outgoing_colors[1]) and defined($incoming_colors[1])) {
+ logit("warning: both graphs are filled and traditional layout is used; one of them will obscure the other");
+ }
+ @order = ( "incoming", "outgoing" );
+ }
+ }
+} else {
+ @order = ( "incoming", "outgoing" );
+}
+
loginit();
debug('GENERAL', 1, "startup");
debug('GENERAL', 2, "args: ".join(' ', @ARGV));
@@ -453,7 +483,7 @@ netplot - graphical processor for NetFlow exports
=head1 SYNOPSIS
-netplot [I<options>] I<FILE> [I<FILE>...]
+netplot [I<options>] [I<FILE>...]
=head1 DESCRIPTION
@@ -509,16 +539,16 @@ The report must contain two definitions: B<in-summary> and B<out-summary>,
for incoming and outgoing traffic, correspondingly. See the section
B<NETFLOW REPORT CONFIGURATION>, for a detailed discussion.
-=item B<--graph-size>=I<WIDTH>xI<HEIGHTS>
-
-Sets the size of the graph pictures to create.
-
=back
Graph layout and colors:
=over 4
+=item B<--graph-size>=I<WIDTH>xI<HEIGHTS>
+
+Sets the size of the graph pictures to create.
+
=item B<--layout>=B<traditional>|B<mirror>
Selects the graph layout. The B<traditional> layout represents both
@@ -535,6 +565,18 @@ 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<--order>=I<ORDER>
+
+Specifies the order in which graphs should be drawn. The argument is
+a comma-separated list of graph names: B<incoming> (or B<in>) and
+B<outgoing> (or B<out>). It is OK if it consists of only one graph
+name: in this case the other graph will not be drawn.
+
+The order of drawing makes sense only for traditional layout. B<Netplot>
+selects the default order so that the graph that has its area filled is
+drawn first. It will issue a warning if both graphs are filled. Use this
+option to override the default order, or to suppress this warning.
+
=item B<--incoming-graph>=I<LINE>[:I<AREA>]
Selects colors to use for incoming graph. Each color should be a 6-digit
@@ -544,7 +586,7 @@ 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>]
+=item B<--outgoing-graph>=I<LINE>[:I<AREA>]
Selects colors to use for outgoing graph. See above for the description
of parameters.

Return to:

Send suggestions and report system problems to the System administrator.