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

This commit is contained in:
Jordi Sanfeliu 2017-07-26 11:26:12 +02:00
parent 0fd6b965b2
commit 582e6b0471
1 changed files with 41 additions and 40 deletions

View File

@ -1,7 +1,7 @@
# #
# Monitorix - A lightweight system monitoring tool. # 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 # 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 # it under the terms of the GNU General Public License as published by
@ -168,6 +168,7 @@ sub gensens_update {
sub gensens_cgi { sub gensens_cgi {
my ($package, $config, $cgi) = @_; my ($package, $config, $cgi) = @_;
my @output;
my $gensens = $config->{gensens}; my $gensens = $config->{gensens};
my @rigid = split(',', ($gensens->{rigid} || "")); my @rigid = split(',', ($gensens->{rigid} || ""));
@ -230,21 +231,21 @@ sub gensens_cgi {
# #
if(lc($config->{iface_mode}) eq "text") { if(lc($config->{iface_mode}) eq "text") {
if($title) { if($title) {
main::graph_header($title, 2); push(@output, main::graph_header($title, 2));
print(" <tr>\n"); push(@output, " <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}'>\n"); push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
} }
my (undef, undef, undef, $data) = RRDs::fetch("$rrd", my (undef, undef, undef, $data) = RRDs::fetch("$rrd",
"--start=-$tf->{nwhen}$tf->{twhen}", "--start=-$tf->{nwhen}$tf->{twhen}",
"AVERAGE", "AVERAGE",
"-r $tf->{res}"); "-r $tf->{res}");
$err = RRDs::error; $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 $line1;
my $line2; my $line2;
my $line3; my $line3;
print(" <pre style='font-size: 12px; color: $colors->{fg_color}';>\n"); push(@output, " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
print(" "); push(@output, " ");
for($n = 0; $n < 2; $n++) { for($n = 0; $n < 2; $n++) {
$line1 = ""; $line1 = "";
foreach my $i (split(',', $gensens->{list}->{$n})) { foreach my $i (split(',', $gensens->{list}->{$n})) {
@ -258,12 +259,12 @@ sub gensens_cgi {
if($line1) { if($line1) {
my $i = length($line1); my $i = length($line1);
$str = "_gensens" . ($n + 1); $str = "_gensens" . ($n + 1);
printf(sprintf("%${i}s", sprintf("%s", trim($config->{graphs}->{$str})))); push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($config->{graphs}->{$str})))));
} }
} }
print("\n"); push(@output, "\n");
print("Time$line2\n"); push(@output, "Time$line2\n");
print("----$line3 \n"); push(@output, "----$line3 \n");
my $line; my $line;
my @row; my @row;
my $time; my $time;
@ -274,7 +275,7 @@ sub gensens_cgi {
for($n = 0, $time = $tf->{tb}; $n < ($tf->{tb} * $tf->{ts}); $n++) { for($n = 0, $time = $tf->{tb}; $n < ($tf->{tb} * $tf->{ts}); $n++) {
$line = @$data[$n]; $line = @$data[$n];
$time = $time - (1 / $tf->{ts}); $time = $time - (1 / $tf->{ts});
printf(" %2d$tf->{tc} ", $time); push(@output, sprintf(" %2d$tf->{tc} ", $time));
for($n2 = 0; $n2 < 2; $n2++) { for($n2 = 0; $n2 < 2; $n2++) {
$n3 = 0; $n3 = 0;
foreach my $i (split(',', $gensens->{list}->{$n2})) { foreach my $i (split(',', $gensens->{list}->{$n2})) {
@ -282,19 +283,19 @@ sub gensens_cgi {
$to = $from + 1; $to = $from + 1;
my ($j) = @$line[$from..$to]; my ($j) = @$line[$from..$to];
@row = ($j); @row = ($j);
printf("%10d ", @row); push(@output, sprintf("%10d ", @row));
} }
} }
print("\n"); push(@output, "\n");
} }
print(" </pre>\n"); push(@output, " </pre>\n");
if($title) { if($title) {
print(" </td>\n"); push(@output, " </td>\n");
print(" </tr>\n"); push(@output, " </tr>\n");
main::graph_footer(); push(@output, main::graph_footer());
} }
print(" <br>\n"); push(@output, " <br>\n");
return; return @output;
} }
@ -326,8 +327,8 @@ sub gensens_cgi {
# Temperatures # Temperatures
if($title) { if($title) {
main::graph_header($title, 2); push(@output, main::graph_header($title, 2));
print(" <tr>\n"); push(@output, " <tr>\n");
} }
@riglim = @{setup_riglim($rigid[0], $limit[0])}; @riglim = @{setup_riglim($rigid[0], $limit[0])};
@ -354,7 +355,7 @@ sub gensens_cgi {
$n++; $n++;
} }
if($title) { if($title) {
print(" <td bgcolor='$colors->{title_bg_color}'>\n"); push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
} }
if(lc($config->{show_gaps}) eq "y") { if(lc($config->{show_gaps}) eq "y") {
push(@tmp, "AREA:wrongdata#$colors->{gap}:"); push(@tmp, "AREA:wrongdata#$colors->{gap}:");
@ -386,7 +387,7 @@ sub gensens_cgi {
@CDEF, @CDEF,
@tmp); @tmp);
$err = RRDs::error; $err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG[0]: $err\n") if $err; push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[0]: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom}); ($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[0]", $picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[0]",
@ -413,12 +414,12 @@ sub gensens_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMGz[0]: $err\n") if $err; push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[0]: $err\n") if $err;
} }
if($title || ($silent =~ /imagetag/ && $graph =~ /gensens0/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /gensens0/)) {
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[0] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[0] . "' border='0'></a>\n"); push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[0] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[0] . "' border='0'></a>\n");
} else { } else {
if($version eq "new") { if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom}; $picz_width = $picz->{image_width} * $config->{global_zoom};
@ -427,15 +428,15 @@ sub gensens_cgi {
$picz_width = $width + 115; $picz_width = $width + 115;
$picz_height = $height + 100; $picz_height = $height + 100;
} }
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[0] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[0] . "' border='0'></a>\n"); push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[0] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[0] . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[0] . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[0] . "'>\n");
} }
} }
if($title) { if($title) {
print(" </td>\n"); push(@output, " </td>\n");
} }
# CPU frequency # CPU frequency
@ -463,7 +464,7 @@ sub gensens_cgi {
$n++; $n++;
} }
if($title) { if($title) {
print(" <td bgcolor='$colors->{title_bg_color}'>\n"); push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
} }
if(lc($config->{show_gaps}) eq "y") { if(lc($config->{show_gaps}) eq "y") {
push(@tmp, "AREA:wrongdata#$colors->{gap}:"); push(@tmp, "AREA:wrongdata#$colors->{gap}:");
@ -495,7 +496,7 @@ sub gensens_cgi {
@CDEF, @CDEF,
@tmp); @tmp);
$err = RRDs::error; $err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMG[1]: $err\n") if $err; push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[1]: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom}); ($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[1]", $picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[1]",
@ -522,12 +523,12 @@ sub gensens_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $err = RRDs::error;
print("ERROR: while graphing $IMG_DIR" . "$IMGz[1]: $err\n") if $err; push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[1]: $err\n") if $err;
} }
if($title || ($silent =~ /imagetag/ && $graph =~ /gensens1/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /gensens1/)) {
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[1] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[1] . "' border='0'></a>\n"); push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[1] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[1] . "' border='0'></a>\n");
} else { } else {
if($version eq "new") { if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom}; $picz_width = $picz->{image_width} * $config->{global_zoom};
@ -536,20 +537,20 @@ sub gensens_cgi {
$picz_width = $width + 115; $picz_width = $width + 115;
$picz_height = $height + 100; $picz_height = $height + 100;
} }
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[1] . "' border='0'></a>\n"); push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[1] . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[1] . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[1] . "'>\n");
} }
} }
if($title) { if($title) {
print(" </td>\n"); push(@output, " </td>\n");
print(" </tr>\n"); push(@output, " </tr>\n");
main::graph_footer(); push(@output, main::graph_footer());
} }
print(" <br>\n"); push(@output, " <br>\n");
return; return @output;
} }
1; 1;