mirror of https://github.com/mikaku/Monitorix.git
redirect all the output into an array to support parallelizing in 'du.pm'
This commit is contained in:
parent
af89e0e625
commit
d300601538
67
lib/du.pm
67
lib/du.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
|
||||
|
@ -178,6 +178,7 @@ sub du_update {
|
|||
|
||||
sub du_cgi {
|
||||
my ($package, $config, $cgi) = @_;
|
||||
my @output;
|
||||
|
||||
my $du = $config->{du};
|
||||
my @rigid = split(',', ($du->{rigid} || ""));
|
||||
|
@ -236,21 +237,21 @@ sub du_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 @dl = split(',', $du->{list})); $n++) {
|
||||
$line1 = "";
|
||||
foreach my $i (split(',', $du->{desc}->{$n})) {
|
||||
|
@ -263,12 +264,12 @@ sub du_cgi {
|
|||
}
|
||||
if($line1) {
|
||||
my $i = length($line1);
|
||||
printf(sprintf("%${i}s", sprintf("%s", trim($dl[$n]))));
|
||||
push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($dl[$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;
|
||||
|
@ -279,7 +280,7 @@ sub du_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 @dl = split(',', $du->{list})); $n2++) {
|
||||
$n3 = 0;
|
||||
foreach my $i (split(',', $du->{desc}->{$n2})) {
|
||||
|
@ -287,19 +288,19 @@ sub du_cgi {
|
|||
$to = $from + 1;
|
||||
my ($j) = @$line[$from..$to];
|
||||
@row = ($j);
|
||||
printf("%17d KB ", @row);
|
||||
push(@output, sprintf("%17d KB ", @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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -330,14 +331,14 @@ sub du_cgi {
|
|||
while($n < scalar(my @dl = split(',', $du->{list}))) {
|
||||
if($title) {
|
||||
if($n == 0) {
|
||||
main::graph_header($title, $du->{graphs_per_row});
|
||||
push(@output, main::graph_header($title, $du->{graphs_per_row}));
|
||||
}
|
||||
print(" <tr>\n");
|
||||
push(@output, " <tr>\n");
|
||||
}
|
||||
for($n2 = 0; $n2 < $du->{graphs_per_row}; $n2++) {
|
||||
last unless $n < scalar(my @dl = split(',', $du->{list}));
|
||||
if($title) {
|
||||
print(" <td bgcolor='" . $colors->{title_bg_color} . "'>\n");
|
||||
push(@output, " <td bgcolor='" . $colors->{title_bg_color} . "'>\n");
|
||||
}
|
||||
undef(@tmp);
|
||||
undef(@tmpz);
|
||||
|
@ -397,7 +398,7 @@ sub du_cgi {
|
|||
@CDEF,
|
||||
@tmp);
|
||||
$err = RRDs::error;
|
||||
print("ERROR: while graphing $IMG_DIR" . "$IMG[$n]: $err\n") if $err;
|
||||
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$n]: $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[$n]",
|
||||
|
@ -434,12 +435,12 @@ sub du_cgi {
|
|||
@CDEF,
|
||||
@tmpz);
|
||||
$err = RRDs::error;
|
||||
print("ERROR: while graphing $IMG_DIR" . "$IMGz[$n]: $err\n") if $err;
|
||||
push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$n]: $err\n") if $err;
|
||||
}
|
||||
if($title || ($silent =~ /imagetag/ && $graph =~ /du$n/)) {
|
||||
if(lc($config->{enable_zoom}) eq "y") {
|
||||
if(lc($config->{disable_javascript_void}) eq "y") {
|
||||
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$n] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$n] . "' border='0'></a>\n");
|
||||
push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$n] . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$n] . "' border='0'></a>\n");
|
||||
} else {
|
||||
if($version eq "new") {
|
||||
$picz_width = $picz->{image_width} * $config->{global_zoom};
|
||||
|
@ -448,26 +449,26 @@ sub du_cgi {
|
|||
$picz_width = $width + 115;
|
||||
$picz_height = $height + 100;
|
||||
}
|
||||
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$n] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$n] . "' border='0'></a>\n");
|
||||
push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMGz[$n] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$n] . "' border='0'></a>\n");
|
||||
}
|
||||
} else {
|
||||
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$n] . "'>\n");
|
||||
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG[$n] . "'>\n");
|
||||
}
|
||||
}
|
||||
if($title) {
|
||||
print(" </td>\n");
|
||||
push(@output, " </td>\n");
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
if($title) {
|
||||
print(" </tr>\n");
|
||||
push(@output, " </tr>\n");
|
||||
}
|
||||
}
|
||||
if($title) {
|
||||
main::graph_footer();
|
||||
push(@output, main::graph_footer());
|
||||
}
|
||||
print(" <br>\n");
|
||||
return;
|
||||
push(@output, " <br>\n");
|
||||
return @output;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in New Issue