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

This commit is contained in:
Jordi Sanfeliu 2017-08-30 10:36:23 +02:00
parent fdf9ead148
commit ad86b26729
1 changed files with 41 additions and 40 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
@ -162,6 +162,7 @@ sub verlihub_update {
sub verlihub_cgi {
my ($package, $config, $cgi) = @_;
my @output;
my $verlihub = $config->{verlihub};
my @rigid = split(',', ($verlihub->{rigid} || ""));
@ -205,16 +206,16 @@ sub verlihub_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("Time Users Upload (GB) Share (GB)\n");
print("---------------------------------------------\n");
push(@output, "ERROR: while fetching $rrd: $err\n") if $err;
push(@output, " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
push(@output, "Time Users Upload (GB) Share (GB)\n");
push(@output, "---------------------------------------------\n");
my $line;
my @row;
my $time;
@ -224,16 +225,16 @@ sub verlihub_cgi {
my ($users_total, $upload_total, $share_total) = @$line;
@row = ($users_total, $upload_total, $share_total);
$time = $time - (1 / $tf->{ts});
printf(" %2d$tf->{tc} %6d %6d %6d\n", $time, @row);
push(@output, sprintf(" %2d$tf->{tc} %6d %6d %6d\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;
}
@ -264,12 +265,12 @@ sub verlihub_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 bgcolor='$colors->{title_bg_color}'>\n");
push(@output, " <tr>\n");
push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
}
push(@tmp, "AREA:users_total#2258FF:Connected Users");
push(@tmp, "GPRINT:users_total:LAST: Current\\: %3.0lf");
@ -310,7 +311,7 @@ sub verlihub_cgi {
"COMMENT: \\n",
"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",
@ -329,12 +330,12 @@ sub verlihub_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 =~ /_verlihub1/)) {
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};
@ -343,16 +344,16 @@ sub verlihub_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[1], $limit[1])};
undef(@tmp);
@ -397,7 +398,7 @@ sub verlihub_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",
@ -418,12 +419,12 @@ sub verlihub_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 =~ /_verlihub2/)) {
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};
@ -432,10 +433,10 @@ sub verlihub_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");
}
}
@ -480,7 +481,7 @@ sub verlihub_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",
@ -501,12 +502,12 @@ sub verlihub_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 =~ /_verlihub3/)) {
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};
@ -515,20 +516,20 @@ sub verlihub_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;