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

This commit is contained in:
Jordi Sanfeliu 2017-08-28 17:44:39 +02:00
parent d800f0d694
commit d4c2d3386b
1 changed files with 55 additions and 54 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
@ -196,6 +196,7 @@ sub phpapc_update {
sub phpapc_cgi {
my $myself = (caller(0))[3];
my ($package, $config, $cgi) = @_;
my @output;
my $phpapc = $config->{phpapc};
my @rigid = split(',', ($phpapc->{rigid} || ""));
@ -245,33 +246,33 @@ sub phpapc_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 $line1;
my $line2;
my $line3;
print(" <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
print(" ");
push(@output, " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
push(@output, " ");
for($n = 0; $n < scalar(my @pl = split(',', $phpapc->{list})); $n++) {
$line1 = " ";
$line2 .= " Free Used Frag. Hits Miss. CacheF";
$line3 .= "-------------------------------------------";
if($line1) {
my $i = length($line1);
printf(sprintf("%${i}s", sprintf("%s", trim($pl[$n]))));
push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($pl[$n])))));
}
}
print("\n");
print("Time$line2\n");
print("----$line3 \n");
push(@output, "\n");
push(@output, "Time$line2\n");
push(@output, "----$line3 \n");
my $line;
my @row;
my $time;
@ -281,24 +282,24 @@ sub phpapc_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 @pl = split(',', $phpapc->{list})); $n2++) {
undef(@row);
$from = $n2 * 14;
$to = $from + 14;
my (undef, $free, $used, $hits, $miss, $cachf, undef, undef, $frag) = @$line[$from..$to];
printf(" %5.1f%% %5.1f%% %5.1f%% %5.1f%% %5.1f%% %6d", $free || 0, $used || 0, $frag || 0, $hits || 0, $miss || 0, $cachf || 0);
push(@output, sprintf(" %5.1f%% %5.1f%% %5.1f%% %5.1f%% %5.1f%% %6d", $free || 0, $used || 0, $frag || 0, $hits || 0, $miss || 0, $cachf || 0));
}
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;
}
@ -350,15 +351,15 @@ sub phpapc_cgi {
}
if($e) {
print(" <br>\n");
push(@output, " <br>\n");
}
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 bgcolor='$colors->{title_bg_color}'>\n");
push(@output, " <tr>\n");
push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
}
undef(@tmp);
undef(@tmpz);
@ -422,7 +423,7 @@ sub phpapc_cgi {
"COMMENT: \\n",
$uptimeline);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3]: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3]: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3]",
@ -443,13 +444,13 @@ sub phpapc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3]: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3]: $err\n") if $err;
}
$e2 = $e + 1;
if($title || ($silent =~ /imagetag/ && $graph =~ /phpapc$e2/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3] . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3] . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -458,16 +459,16 @@ sub phpapc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3] . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3] . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3] . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3] . "'>\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[1], $limit[1])};
undef(@tmp);
@ -515,7 +516,7 @@ sub phpapc_cgi {
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 1]: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 1]: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3 + 1]",
@ -536,13 +537,13 @@ sub phpapc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 1]: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 1]: $err\n") if $err;
}
$e2 = $e + 2;
if($title || ($silent =~ /imagetag/ && $graph =~ /phpapc$e2/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 1] . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 1] . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -551,10 +552,10 @@ sub phpapc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 1] . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 1] . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 1] . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 1] . "'>\n");
}
}
@ -600,7 +601,7 @@ sub phpapc_cgi {
@CDEF,
@tmp);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 2]: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 2]: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3 + 2]",
@ -622,13 +623,13 @@ sub phpapc_cgi {
@CDEF,
@tmpz);
$err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 2]: $err\n") if $err;
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 2]: $err\n") if $err;
}
$e2 = $e + 3;
if($title || ($silent =~ /imagetag/ && $graph =~ /phpapc$e2/)) {
if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 2] . "' border='0'></a>\n");
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 2] . "' border='0'></a>\n");
} else {
if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom};
@ -637,31 +638,31 @@ sub phpapc_cgi {
$picz_width = $width + 115;
$picz_height = $height + 100;
}
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 2] . "' border='0'></a>\n");
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 2] . "' border='0'></a>\n");
}
} else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 2] . "'>\n");
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$e * 3 + 2] . "'>\n");
}
}
if($title) {
print(" </td>\n");
print(" </tr>\n");
push(@output, " </td>\n");
push(@output, " </tr>\n");
print(" <tr>\n");
print " <td bgcolor='$colors->{title_bg_color}' colspan='2'>\n";
print " <font face='Verdana, sans-serif' color='$colors->{title_fg_color}'>\n";
print " <font size='-1'>\n";
print " <b>&nbsp;&nbsp;<a href='" . trim($url) . "' style='color: " . $colors->{title_fg_color} . "'>" . trim($url) . "</a></b>\n";
print " </font></font>\n";
print " </td>\n";
print(" </tr>\n");
main::graph_footer();
push(@output, " <tr>\n");
push(@output, " <td bgcolor='$colors->{title_bg_color}' colspan='2'>\n");
push(@output, " <font face='Verdana, sans-serif' color='$colors->{title_fg_color}'>\n");
push(@output, " <font size='-1'>\n");
push(@output, " <b>&nbsp;&nbsp;<a href='" . trim($url) . "' style='color: " . $colors->{title_fg_color} . "'>" . trim($url) . "</a></b>\n");
push(@output, " </font></font>\n");
push(@output, " </td>\n");
push(@output, " </tr>\n");
push(@output, main::graph_footer());
}
$e++;
}
print(" <br>\n");
return;
push(@output, " <br>\n");
return @output;
}
1;