redirect all the output into an array to support parallelizing in 'nfsc.pm'

This commit is contained in:
Jordi Sanfeliu 2017-08-03 10:45:46 +02:00
parent ff6a0bb4a7
commit d60faf2218
1 changed files with 56 additions and 55 deletions

View File

@ -1,7 +1,7 @@
#
# Monitorix - A lightweight system monitoring tool.
#
# Copyright (C) 2005-2016 by Jordi Sanfeliu <jordi@fibranet.cat>
# Copyright (C) 2005-2017 by Jordi Sanfeliu <jordi@fibranet.cat>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -217,6 +217,7 @@ sub nfsc_update {
sub nfsc_cgi {
my ($package, $config, $cgi) = @_;
my @output;
my $nfsc = $config->{nfsc};
my @rigid = split(',', ($nfsc->{rigid} || ""));
@ -307,20 +308,20 @@ sub nfsc_cgi {
#
if(lc($config->{iface_mode}) eq "text") {
if($title) {
main::graph_header($title, 2);
print(" <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}'>\n");
push(@output, main::graph_header($title, 2));
push(@output, " <tr>\n");
push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
}
my (undef, undef, undef, $data) = RRDs::fetch("$rrd",
"--start=-$tf->{nwhen}$tf->{twhen}",
"AVERAGE",
"-r $tf->{res}");
$err = RRDs::error;
print("ERROR: while fetching $rrd: $err\n") if $err;
push(@output, "ERROR: while fetching $rrd: $err\n") if $err;
my $str;
my $line1;
my $line2;
print(" <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
push(@output, " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
foreach my $t (@nfsv) {
$str = sprintf("%12s ", $t);
$line1 .= $str;
@ -328,8 +329,8 @@ sub nfsc_cgi {
}
$line1 .= sprintf("%12s %12s %12s", "calls", "retrans", "authrefrsh");
$line2 .= "-------------" . "-------------" . "-------------";
print("Time $line1\n");
print("-----$line2\n");
push(@output, "Time $line1\n");
push(@output, "-----$line2\n");
my $line;
my @row;
my $time;
@ -347,16 +348,16 @@ sub nfsc_cgi {
push(@row, @$line[50..52]);
$line1 .= "%12d %12d %12d ";
$time = $time - (1 / $tf->{ts});
printf(" %2d$tf->{tc} $line1\n", $time, @row);
push(@output, sprintf(" %2d$tf->{tc} $line1\n", $time, @row));
}
print(" </pre>\n");
push(@output, " </pre>\n");
if($title) {
print(" </td>\n");
print(" </tr>\n");
main::graph_footer();
push(@output, " </td>\n");
push(@output, " </tr>\n");
push(@output, main::graph_footer());
}
print(" <br>\n");
return;
push(@output, " <br>\n");
return @output;
}
@ -398,12 +399,12 @@ sub nfsc_cgi {
}
if($title) {
main::graph_header($title, 2);
push(@output, main::graph_header($title, 2));
}
@riglim = @{setup_riglim($rigid[0], $limit[0])};
if($title) {
print(" <tr>\n");
print(" <td valign='top' bgcolor='$colors->{title_bg_color}'>\n");
push(@output, " <tr>\n");
push(@output, " <td valign='top' bgcolor='$colors->{title_bg_color}'>\n");
}
for($n = 0; $n < 10; $n++) {
my $str = trim((split(',', $nfsc->{graph_0}))[$n]) || "";
@ -453,7 +454,7 @@ sub nfsc_cgi {
@tmp,
"COMMENT: \\n");
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG1: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG1: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG1z",
@ -471,12 +472,12 @@ sub nfsc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG1z: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG1z: $err\n") if $err;
}
if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc1/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -485,10 +486,10 @@ sub nfsc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n");
}
}
@ -546,7 +547,7 @@ sub nfsc_cgi {
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG2: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG2: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG2z",
@ -564,12 +565,12 @@ sub nfsc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG2z: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG2z: $err\n") if $err;
}
if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc2/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -578,16 +579,16 @@ sub nfsc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n");
}
}
if($title) {
print(" </td>\n");
print(" <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n");
push(@output, " </td>\n");
push(@output, " <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n");
}
@riglim = @{setup_riglim($rigid[2], $limit[2])};
undef(@tmp);
@ -650,7 +651,7 @@ sub nfsc_cgi {
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG3: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG3: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG3z",
@ -669,12 +670,12 @@ sub nfsc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG3z: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG3z: $err\n") if $err;
}
if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc3/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -683,10 +684,10 @@ sub nfsc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\n");
}
}
@ -751,7 +752,7 @@ sub nfsc_cgi {
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG4: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG4: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG4z",
@ -770,12 +771,12 @@ sub nfsc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG4z: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG4z: $err\n") if $err;
}
if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc4/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4 . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4 . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -784,10 +785,10 @@ sub nfsc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4 . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4 . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4 . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG4 . "'>\n");
}
}
@ -852,7 +853,7 @@ sub nfsc_cgi {
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG5: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG5: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG5z",
@ -871,12 +872,12 @@ sub nfsc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG5z: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG5z: $err\n") if $err;
}
if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc5/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5 . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5 . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -885,10 +886,10 @@ sub nfsc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5 . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5 . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5 . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG5 . "'>\n");
}
}
@ -944,7 +945,7 @@ sub nfsc_cgi {
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG6: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG6: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG6z",
@ -966,12 +967,12 @@ sub nfsc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG6z: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG6z: $err\n") if $err;
}
if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc6/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6 . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6 . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -980,20 +981,20 @@ sub nfsc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6 . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6 . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6 . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG6 . "'>\n");
}
}
if($title) {
print(" </td>\n");
print(" </tr>\n");
main::graph_footer();
push(@output, " </td>\n");
push(@output, " </tr>\n");
push(@output, main::graph_footer());
}
print(" <br>\n");
return;
push(@output, " <br>\n");
return @output;
}
1;