mirror of https://github.com/mikaku/Monitorix.git
redirect all the output into an array to support parallelizing in 'net.pm'
This commit is contained in:
parent
1b76900b15
commit
9ab95d35ea
97
lib/net.pm
97
lib/net.pm
|
@ -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
|
||||
|
@ -285,6 +285,7 @@ sub net_update {
|
|||
|
||||
sub net_cgi {
|
||||
my ($package, $config, $cgi) = @_;
|
||||
my @output;
|
||||
|
||||
my $net = $config->{net};
|
||||
my $tf = $cgi->{tf};
|
||||
|
@ -335,32 +336,32 @@ sub net_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;
|
||||
print(" <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
|
||||
print(" ");
|
||||
push(@output, "ERROR: while fetching $rrd: $err\n") if $err;
|
||||
push(@output, " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
|
||||
push(@output, " ");
|
||||
for($n = 0; $n < scalar(my @nl = split(',', $net->{list})); $n++) {
|
||||
$nl[$n] = trim($nl[$n]);
|
||||
my $nd = trim((split(',', $net->{desc}->{$nl[$n]}))[0]);
|
||||
print(trim($nl[$n]) . " ($nd) ");
|
||||
push(@output, (trim($nl[$n]) . " ($nd) "));
|
||||
}
|
||||
print("\nTime");
|
||||
push(@output, "\nTime");
|
||||
for($n = 0; $n < scalar(my @nl = split(',', $net->{list})); $n++) {
|
||||
print(" K$T/s_I K$T/s_O Pk/s_I Pk/s_O Er/s_I Er/s_O");
|
||||
push(@output, " K$T/s_I K$T/s_O Pk/s_I Pk/s_O Er/s_I Er/s_O");
|
||||
}
|
||||
print(" \n----");
|
||||
push(@output, " \n----");
|
||||
for($n = 0; $n < scalar(my @nl = split(',', $net->{list})); $n++) {
|
||||
print("-------------------------------------------------");
|
||||
push(@output, "-------------------------------------------------");
|
||||
}
|
||||
print " \n";
|
||||
push(@output, " \n");
|
||||
my $line;
|
||||
my @row;
|
||||
my $time;
|
||||
|
@ -370,7 +371,7 @@ sub net_cgi {
|
|||
for($n = 0, $time = $tf->{tb}; $n < ($tf->{tb} * $tf->{ts}); $n++) {
|
||||
$line = @$data[$n];
|
||||
$time = $time - (1 / $tf->{ts});
|
||||
printf(" %2d$tf->{tc}", $time);
|
||||
push(@output, sprintf(" %2d$tf->{tc}", $time));
|
||||
for($n2 = 0; $n2 < scalar(my @nl = split(',', $net->{list})); $n2++) {
|
||||
$from = $n2 * 6;
|
||||
$to = $from + 6;
|
||||
|
@ -386,18 +387,18 @@ sub net_cgi {
|
|||
$ko *= 8;
|
||||
}
|
||||
@row = ($ki, $ko, $pi, $po, $ei, $eo);
|
||||
printf(" %6d %6d %6d %6d %6d %6d", @row);
|
||||
push(@output, sprintf(" %6d %6d %6d %6d %6d %6d", @row));
|
||||
}
|
||||
print(" \n");
|
||||
push(@output, " \n");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -441,11 +442,11 @@ sub net_cgi {
|
|||
|
||||
if($title) {
|
||||
if($n) {
|
||||
print(" <br>\n");
|
||||
push(@output, " <br>\n");
|
||||
}
|
||||
main::graph_header($nl[$n] . " " . $title, 2);
|
||||
print(" <tr>\n");
|
||||
print(" <td bgcolor='$colors->{title_bg_color}'>\n");
|
||||
push(@output, main::graph_header($nl[$n] . " " . $title, 2));
|
||||
push(@output, " <tr>\n");
|
||||
push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
|
||||
}
|
||||
|
||||
@riglim = @{setup_riglim($rigid, $limit)};
|
||||
|
@ -514,7 +515,7 @@ sub net_cgi {
|
|||
"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",
|
||||
|
@ -534,13 +535,13 @@ sub net_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;
|
||||
}
|
||||
$netname="net" . $n . "1";
|
||||
if($title || ($silent =~ /imagetag/ && $graph =~ /$netname/)) {
|
||||
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};
|
||||
|
@ -549,16 +550,16 @@ sub net_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");
|
||||
}
|
||||
}
|
||||
|
||||
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, $limit)};
|
||||
undef(@tmp);
|
||||
|
@ -608,7 +609,7 @@ sub net_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",
|
||||
|
@ -629,13 +630,13 @@ sub net_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;
|
||||
}
|
||||
$netname="net" . $n . "2";
|
||||
if($title || ($silent =~ /imagetag/ && $graph =~ /$netname/)) {
|
||||
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};
|
||||
|
@ -644,10 +645,10 @@ sub net_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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -699,7 +700,7 @@ sub net_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",
|
||||
|
@ -720,13 +721,13 @@ sub net_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;
|
||||
}
|
||||
$netname="net" . $n . "3";
|
||||
if($title || ($silent =~ /imagetag/ && $graph =~ /$netname/)) {
|
||||
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};
|
||||
|
@ -735,20 +736,20 @@ sub net_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");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue