mirror of https://github.com/mikaku/Monitorix.git
redirect all the output into an array to support parallelizing in 'disk.pm'
This commit is contained in:
parent
de88119303
commit
af89e0e625
89
lib/disk.pm
89
lib/disk.pm
|
@ -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
|
||||||
|
@ -290,6 +290,7 @@ sub disk_update {
|
||||||
|
|
||||||
sub disk_cgi {
|
sub disk_cgi {
|
||||||
my ($package, $config, $cgi) = @_;
|
my ($package, $config, $cgi) = @_;
|
||||||
|
my @output;
|
||||||
|
|
||||||
my $disk = $config->{disk};
|
my $disk = $config->{disk};
|
||||||
my @rigid = split(',', ($disk->{rigid} || ""));
|
my @rigid = split(',', ($disk->{rigid} || ""));
|
||||||
|
@ -354,20 +355,20 @@ sub disk_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");
|
||||||
foreach my $k (sort keys %{$disk->{list}}) {
|
foreach my $k (sort keys %{$disk->{list}}) {
|
||||||
# values delimitted by ", " (comma + space)
|
# values delimitted by ", " (comma + space)
|
||||||
my @d = split(', ', $disk->{list}->{$k});
|
my @d = split(', ', $disk->{list}->{$k});
|
||||||
|
@ -379,9 +380,9 @@ sub disk_cgi {
|
||||||
$line3 .= "----------------------";
|
$line3 .= "----------------------";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print(" $line1\n");
|
push(@output, " $line1\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;
|
||||||
|
@ -390,7 +391,7 @@ sub disk_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));
|
||||||
$e = 0;
|
$e = 0;
|
||||||
foreach my $k (sort keys %{$disk->{list}}) {
|
foreach my $k (sort keys %{$disk->{list}}) {
|
||||||
# values delimitted by ", " (comma + space)
|
# values delimitted by ", " (comma + space)
|
||||||
|
@ -400,20 +401,20 @@ sub disk_cgi {
|
||||||
$to = $from + 3;
|
$to = $from + 3;
|
||||||
my ($temp, $realloc, $pending) = @$line[$from..$to];
|
my ($temp, $realloc, $pending) = @$line[$from..$to];
|
||||||
@row = (celsius_to($config, $temp), $realloc, $pending);
|
@row = (celsius_to($config, $temp), $realloc, $pending);
|
||||||
printf(" %4.0f %7.0f %7.0f ", @row);
|
push(@output, sprintf(" %4.0f %7.0f %7.0f ", @row));
|
||||||
}
|
}
|
||||||
$e++;
|
$e++;
|
||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -447,10 +448,10 @@ sub disk_cgi {
|
||||||
my @d = split(', ', $disk->{list}->{$k});
|
my @d = split(', ', $disk->{list}->{$k});
|
||||||
|
|
||||||
if($e) {
|
if($e) {
|
||||||
print(" <br>\n");
|
push(@output, " <br>\n");
|
||||||
}
|
}
|
||||||
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])};
|
||||||
|
@ -487,8 +488,8 @@ sub disk_cgi {
|
||||||
push(@tmp, "COMMENT: \\n");
|
push(@tmp, "COMMENT: \\n");
|
||||||
}
|
}
|
||||||
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,+");
|
||||||
|
@ -546,7 +547,7 @@ sub disk_cgi {
|
||||||
@CDEF,
|
@CDEF,
|
||||||
@tmp);
|
@tmp);
|
||||||
$err = RRDs::error;
|
$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") {
|
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[$e * 3]",
|
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3]",
|
||||||
|
@ -572,13 +573,13 @@ sub disk_cgi {
|
||||||
@CDEF,
|
@CDEF,
|
||||||
@tmpz);
|
@tmpz);
|
||||||
$err = RRDs::error;
|
$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;
|
$e2 = $e + 1;
|
||||||
if($title || ($silent =~ /imagetag/ && $graph =~ /disk$e2/)) {
|
if($title || ($silent =~ /imagetag/ && $graph =~ /disk$e2/)) {
|
||||||
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[$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 {
|
} 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};
|
||||||
|
@ -587,16 +588,16 @@ sub disk_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[$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 {
|
} 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) {
|
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);
|
||||||
|
@ -676,7 +677,7 @@ sub disk_cgi {
|
||||||
@CDEF,
|
@CDEF,
|
||||||
@tmp);
|
@tmp);
|
||||||
$err = RRDs::error;
|
$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") {
|
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[$e * 3 + 1]",
|
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3 + 1]",
|
||||||
|
@ -703,13 +704,13 @@ sub disk_cgi {
|
||||||
@CDEF,
|
@CDEF,
|
||||||
@tmpz);
|
@tmpz);
|
||||||
$err = RRDs::error;
|
$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;
|
$e2 = $e + 2;
|
||||||
if($title || ($silent =~ /imagetag/ && $graph =~ /disk$e2/)) {
|
if($title || ($silent =~ /imagetag/ && $graph =~ /disk$e2/)) {
|
||||||
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[$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 {
|
} 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};
|
||||||
|
@ -718,10 +719,10 @@ sub disk_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[$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 {
|
} 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -803,7 +804,7 @@ sub disk_cgi {
|
||||||
@CDEF,
|
@CDEF,
|
||||||
@tmp);
|
@tmp);
|
||||||
$err = RRDs::error;
|
$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") {
|
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[$e * 3 + 2]",
|
$picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3 + 2]",
|
||||||
|
@ -830,13 +831,13 @@ sub disk_cgi {
|
||||||
@CDEF,
|
@CDEF,
|
||||||
@tmpz);
|
@tmpz);
|
||||||
$err = RRDs::error;
|
$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;
|
$e2 = $e + 3;
|
||||||
if($title || ($silent =~ /imagetag/ && $graph =~ /disk$e2/)) {
|
if($title || ($silent =~ /imagetag/ && $graph =~ /disk$e2/)) {
|
||||||
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[$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 {
|
} 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};
|
||||||
|
@ -845,22 +846,22 @@ sub disk_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[$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 {
|
} 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) {
|
if($title) {
|
||||||
print(" </td>\n");
|
push(@output, " </td>\n");
|
||||||
print(" </tr>\n");
|
push(@output, " </tr>\n");
|
||||||
main::graph_footer();
|
push(@output, main::graph_footer());
|
||||||
}
|
}
|
||||||
$e++;
|
$e++;
|
||||||
}
|
}
|
||||||
print(" <br>\n");
|
push(@output, " <br>\n");
|
||||||
return;
|
return @output;
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in New Issue