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

This commit is contained in:
Jordi Sanfeliu 2017-08-04 10:00:10 +02:00
parent c0f2d015bc
commit 1017f69f58
1 changed files with 46 additions and 45 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
@ -233,6 +233,7 @@ sub nvidia_update {
sub nvidia_cgi { sub nvidia_cgi {
my ($package, $config, $cgi) = @_; my ($package, $config, $cgi) = @_;
my @output;
my $nvidia = $config->{nvidia}; my $nvidia = $config->{nvidia};
my @rigid = split(',', ($nvidia->{rigid} || "")); my @rigid = split(',', ($nvidia->{rigid} || ""));
@ -292,31 +293,31 @@ sub nvidia_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 < $nvidia->{max}; $n++) { for($n = 0; $n < $nvidia->{max}; $n++) {
print(" NVIDIA card $n"); push(@output, " NVIDIA card $n");
} }
print("\n"); push(@output, "\n");
for($n = 0; $n < $nvidia->{max}; $n++) { for($n = 0; $n < $nvidia->{max}; $n++) {
$line2 .= " Temp GPU Mem"; $line2 .= " Temp GPU Mem";
$line3 .= "-----------------"; $line3 .= "-----------------";
} }
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;
@ -324,7 +325,7 @@ sub nvidia_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));
undef($line1); undef($line1);
undef(@row); undef(@row);
for($n2 = 0; $n2 < $nvidia->{max}; $n2++) { for($n2 = 0; $n2 < $nvidia->{max}; $n2++) {
@ -333,17 +334,17 @@ sub nvidia_cgi {
push(@row, celsius_to($config, @$line[$n2 + 18])); push(@row, celsius_to($config, @$line[$n2 + 18]));
$line1 .= " %3d %3d%% %3d%%"; $line1 .= " %3d %3d%% %3d%%";
} }
print(sprintf($line1, @row)); push(@output, sprintf($line1, @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;
} }
@ -375,7 +376,7 @@ sub nvidia_cgi {
} }
if($title) { if($title) {
main::graph_header($title, 2); push(@output, main::graph_header($title, 2));
} }
@riglim = @{setup_riglim($rigid[0], $limit[0])}; @riglim = @{setup_riglim($rigid[0], $limit[0])};
@ -393,8 +394,8 @@ sub nvidia_cgi {
} }
if($title) { if($title) {
print(" <tr>\n"); push(@output, " <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}'>\n"); push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
} }
if(lc($config->{temperature_scale}) eq "f") { if(lc($config->{temperature_scale}) eq "f") {
push(@CDEF, "CDEF:temp_0=9,5,/,temp0,*,32,+"); push(@CDEF, "CDEF:temp_0=9,5,/,temp0,*,32,+");
@ -455,7 +456,7 @@ sub nvidia_cgi {
"COMMENT: \\n", "COMMENT: \\n",
"COMMENT: \\n"); "COMMENT: \\n");
$err = RRDs::error; $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") { 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" . "$IMG1z", $picz = $rrd{$version}->("$IMG_DIR" . "$IMG1z",
@ -482,12 +483,12 @@ sub nvidia_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $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 =~ /nvidia1/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /nvidia1/)) {
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} . $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 { } 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};
@ -496,16 +497,16 @@ sub nvidia_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} . $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 { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n");
} }
} }
if($title) { if($title) {
print(" </td>\n"); push(@output, " </td>\n");
print(" <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n"); push(@output, " <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n");
} }
@riglim = @{setup_riglim($rigid[1], $limit[1])}; @riglim = @{setup_riglim($rigid[1], $limit[1])};
undef(@tmp); undef(@tmp);
@ -576,7 +577,7 @@ sub nvidia_cgi {
"COMMENT: \\n", "COMMENT: \\n",
@tmp); @tmp);
$err = RRDs::error; $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") { 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" . "$IMG2z", $picz = $rrd{$version}->("$IMG_DIR" . "$IMG2z",
@ -604,12 +605,12 @@ sub nvidia_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $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 =~ /nvidia2/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /nvidia2/)) {
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} . $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 { } 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};
@ -618,10 +619,10 @@ sub nvidia_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} . $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 { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n");
} }
} }
@ -694,7 +695,7 @@ sub nvidia_cgi {
"COMMENT: \\n", "COMMENT: \\n",
@tmp); @tmp);
$err = RRDs::error; $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") { 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" . "$IMG3z", $picz = $rrd{$version}->("$IMG_DIR" . "$IMG3z",
@ -722,12 +723,12 @@ sub nvidia_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $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 =~ /nvidia3/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /nvidia3/)) {
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} . $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 { } 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};
@ -736,20 +737,20 @@ sub nvidia_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} . $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 { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\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;