From fc26d6db8b7d39f73cef9b40936215b1934643c3 Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Fri, 28 Jan 2022 17:30:03 +0100 Subject: [PATCH 1/7] Fix wrong index for image directory. The number of plots was wrongly fixed to 3 instead of the actual number. --- lib/amdgpu.pm | 14 +++++++------- lib/nvidiagpu.pm | 14 +++++++------- lib/nvme.pm | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/amdgpu.pm b/lib/amdgpu.pm index f33492b..f2abc44 100644 --- a/lib/amdgpu.pm +++ b/lib/amdgpu.pm @@ -679,7 +679,7 @@ sub amdgpu_cgi { $cdef_sensor_allvalues .= ",0,GT,1,UNKN,IF"; } my $plot_title = $config->{graphs}->{'_amdgpu' . ($n_plot + 1)}; - $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 3 + $n_plot]", + $pic = $rrd{$version}->("$IMG_DIR" . $IMG[$e * $number_of_sensor_values_in_use + $n_plot], "--title=$plot_title ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", @@ -697,10 +697,10 @@ sub amdgpu_cgi { @CDEF, @tmp); $err = RRDs::error; - push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + $n_plot]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . $IMG[$e * $number_of_sensor_values_in_use + $n_plot]. ": $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[$e * 3 + $n_plot]", + $picz = $rrd{$version}->("$IMG_DIR" . $IMGz[$e * $number_of_sensor_values_in_use + $n_plot], "--title=$plot_title ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", @@ -719,13 +719,13 @@ sub amdgpu_cgi { @CDEF, @tmpz); $err = RRDs::error; - push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + $n_plot]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . $IMGz[$e * $number_of_sensor_values_in_use + $n_plot]. ": $err\n") if $err; } $e2 = $e + $n_plot + 1; if($title || ($silent =~ /imagetag/ && $graph =~ /amdgpu$e2/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - push(@output, " " . picz_a_element(config => $config, IMGz => $IMGz[$e * 3 + $n_plot], IMG => $IMG[$e * 3 + $n_plot]) . "\n"); + push(@output, " " . picz_a_element(config => $config, IMGz => $IMGz[$e * $number_of_sensor_values_in_use + $n_plot], IMG => $IMG[$e * $number_of_sensor_values_in_use + $n_plot]) . "\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -734,10 +734,10 @@ sub amdgpu_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - push(@output, " " . picz_js_a_element(width => $picz_width, height => $picz_height, config => $config, IMGz => $IMGz[$e * 3 + $n_plot], IMG => $IMG[$e * 3 + $n_plot]) . "\n"); + push(@output, " " . picz_js_a_element(width => $picz_width, height => $picz_height, config => $config, IMGz => $IMGz[$e * $number_of_sensor_values_in_use + $n_plot], IMG => $IMG[$e * $number_of_sensor_values_in_use + $n_plot]) . "\n"); } } else { - push(@output, " " . img_element(config => $config, IMG => $IMG[$e * 3 + $n_plot]) . "\n"); + push(@output, " " . img_element(config => $config, IMG => $IMG[$e * $number_of_sensor_values_in_use + $n_plot]) . "\n"); } } } diff --git a/lib/nvidiagpu.pm b/lib/nvidiagpu.pm index f46c193..918abf6 100644 --- a/lib/nvidiagpu.pm +++ b/lib/nvidiagpu.pm @@ -632,7 +632,7 @@ sub nvidiagpu_cgi { $cdef_sensor_allvalues .= ",0,GT,1,UNKN,IF"; } my $plot_title = $config->{graphs}->{'_nvidiagpu' . ($n_plot + 1)}; - $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 3 + $n_plot]", + $pic = $rrd{$version}->("$IMG_DIR" . $IMG[$e * $number_of_sensor_values_in_use + $n_plot], "--title=$plot_title ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", @@ -650,10 +650,10 @@ sub nvidiagpu_cgi { @CDEF, @tmp); $err = RRDs::error; - push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + $n_plot]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . $IMG[$e * $number_of_sensor_values_in_use + $n_plot] . ": $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[$e * 3 + $n_plot]", + $picz = $rrd{$version}->("$IMG_DIR" . $IMGz[$e * $number_of_sensor_values_in_use + $n_plot], "--title=$plot_title ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", @@ -672,13 +672,13 @@ sub nvidiagpu_cgi { @CDEF, @tmpz); $err = RRDs::error; - push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + $n_plot]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . $IMGz[$e * $number_of_sensor_values_in_use + $n_plot]. ": $err\n") if $err; } $e2 = $e + $n_plot + 1; if($title || ($silent =~ /imagetag/ && $graph =~ /nvidiagpu$e2/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - push(@output, " " . picz_a_element(config => $config, IMGz => $IMGz[$e * 3 + $n_plot], IMG => $IMG[$e * 3 + $n_plot]) . "\n"); + push(@output, " " . picz_a_element(config => $config, IMGz => $IMGz[$e * $number_of_sensor_values_in_use + $n_plot], IMG => $IMG[$e * $number_of_sensor_values_in_use + $n_plot]) . "\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -687,10 +687,10 @@ sub nvidiagpu_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - push(@output, " " . picz_js_a_element(width => $picz_width, height => $picz_height, config => $config, IMGz => $IMGz[$e * 3 + $n_plot], IMG => $IMG[$e * 3 + $n_plot]) . "\n"); + push(@output, " " . picz_js_a_element(width => $picz_width, height => $picz_height, config => $config, IMGz => $IMGz[$e * $number_of_sensor_values_in_use + $n_plot], IMG => $IMG[$e * $number_of_sensor_values_in_use + $n_plot]) . "\n"); } } else { - push(@output, " " . img_element(config => $config, IMG => $IMG[$e * 3 + $n_plot]) . "\n"); + push(@output, " " . img_element(config => $config, IMG => $IMG[$e * $number_of_sensor_values_in_use + $n_plot]) . "\n"); } } } diff --git a/lib/nvme.pm b/lib/nvme.pm index 35dee72..50c894c 100644 --- a/lib/nvme.pm +++ b/lib/nvme.pm @@ -631,7 +631,7 @@ sub nvme_cgi { push(@scaling_options, "--alt-y-grid"); } my $plot_title = $config->{graphs}->{'_nvme' . ($n_smart + 1)}; - $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 3 + $n_smart]", + $pic = $rrd{$version}->("$IMG_DIR" . $IMG[$e * $number_of_smart_values_in_use + $n_smart], "--title=$plot_title ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", @@ -650,10 +650,10 @@ sub nvme_cgi { @CDEF, @tmp); $err = RRDs::error; - push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + $n_smart]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . $IMG[$e * $number_of_smart_values_in_use + $n_smart]. ": $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[$e * 3 + $n_smart]", + $picz = $rrd{$version}->("$IMG_DIR" . $IMGz[$e * $number_of_smart_values_in_use + $n_smart], "--title=$plot_title ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", @@ -673,13 +673,13 @@ sub nvme_cgi { @CDEF, @tmpz); $err = RRDs::error; - push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + $n_smart]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . $IMGz[$e * $number_of_smart_values_in_use + $n_smart]. ": $err\n") if $err; } $e2 = $e + $n_smart + 1; if($title || ($silent =~ /imagetag/ && $graph =~ /nvme$e2/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - push(@output, " " . picz_a_element(config => $config, IMGz => $IMGz[$e * 3 + $n_smart], IMG => $IMG[$e * 3 + $n_smart]) . "\n"); + push(@output, " " . picz_a_element(config => $config, IMGz => $IMGz[$e * $number_of_smart_values_in_use + $n_smart], IMG => $IMG[$e * $number_of_smart_values_in_use + $n_smart]) . "\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -688,10 +688,10 @@ sub nvme_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - push(@output, " " . picz_js_a_element(width => $picz_width, height => $picz_height, config => $config, IMGz => $IMGz[$e * 3 + $n_smart], IMG => $IMG[$e * 3 + $n_smart]) . "\n"); + push(@output, " " . picz_js_a_element(width => $picz_width, height => $picz_height, config => $config, IMGz => $IMGz[$e * $number_of_smart_values_in_use + $n_smart], IMG => $IMG[$e * $number_of_smart_values_in_use + $n_smart]) . "\n"); } } else { - push(@output, " " . img_element(config => $config, IMG => $IMG[$e * 3 + $n_smart]) . "\n"); + push(@output, " " . img_element(config => $config, IMG => $IMG[$e * $number_of_smart_values_in_use + $n_smart]) . "\n"); } } } From 53bd054a097fa8aba9fe715e08233bb2f5f40d2b Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Sun, 30 Jan 2022 14:24:07 +0100 Subject: [PATCH 2/7] Add additional_graph_name config option. This is an optional configuration option for configuration files in include_dir. It takes a comma separated list of additional modules that is appended to the graph_name option. This enables you to add custom modules without changing the monitorix.conf or copy all names from graph_name to your config file. --- man/man5/monitorix.conf.5 | 7 +++++++ monitorix | 6 +++++- monitorix.cgi | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index d828ec7..36675c7 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -180,6 +180,13 @@ All the configuration files in there will be loaded in alphabetic order, so the Default value: \fI/etc/monitorix/conf.d\fP .RE .P +.BI additional_graph_name +.RS +This is an optional configuration option for configuration files in \fIinclude_dir\fP. It takes a comma separated list of additional modules that is appended to the \fIgraph_name\fP option. This enables you to add custom modules without changing the \fImonitorix.conf\fP or copy all names from \fIgraph_name\fP to your config file. +.P +Default value: \fINone\fP +.RE +.P .BI ip_default_table .RS This option will define in which table Monitorix will put all \fIiptables\fP rules for network traffic accounting monitoring. It only works on Linux. diff --git a/monitorix b/monitorix index a6cba57..39c41e3 100755 --- a/monitorix +++ b/monitorix @@ -607,7 +607,11 @@ if($config{include_dir} && opendir(DIR, $config{include_dir})) { # delete $config_inc{$key}; # next; #} - + if($key eq "additional_graph_name") { + $config{graph_name} .= ", $val"; + delete $config_inc{$key}; + next; + } # one level options $config{$key} = $val; delete $config_inc{$key}; diff --git a/monitorix.cgi b/monitorix.cgi index b53a90a..48133d6 100755 --- a/monitorix.cgi +++ b/monitorix.cgi @@ -295,7 +295,11 @@ if($config{include_dir} && opendir(DIR, $config{include_dir})) { # delete $config_inc{graph_name}; # next; #} - + if($key eq "additional_graph_name") { + $config{graph_name} .= ", $val"; + delete $config_inc{$key}; + next; + } # one level options $config{$key} = $val; delete $config_inc{$key}; From f50d49cc059673169b37eb0f9b3bf65370392e84 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Tue, 1 Feb 2022 10:13:30 +0100 Subject: [PATCH 3/7] fixed a change in the quotation marks introduced in 3.14 that prevented from sending reports #391 --- lib/emailreports.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/emailreports.pm b/lib/emailreports.pm index 39bf669..13eddb1 100644 --- a/lib/emailreports.pm +++ b/lib/emailreports.pm @@ -1,7 +1,7 @@ # # Monitorix - A lightweight system monitoring tool. # -# Copyright (C) 2005-2017 by Jordi Sanfeliu +# Copyright (C) 2005-2022 by Jordi Sanfeliu # # 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 @@ -83,7 +83,7 @@ EOF
-Copyright © 2005-2017 Jordi Sanfeliu +Copyright © 2005-2022 Jordi Sanfeliu @@ -135,7 +135,7 @@ EOF foreach (split('\n', $graph)) { if(/"); - ($url) = $_ =~ m/new($url); my $path = $uri->path || ""; $response = $ua->request(HTTP::Request->new('GET', "$prefix$path")); From c67dd952de0d3fb3c4c8cee4196af41122592f1a Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Wed, 2 Feb 2022 09:35:03 +0100 Subject: [PATCH 4/7] update Changes --- Changes | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Changes b/Changes index 6ef19b7..6d1d758 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,16 @@ +N.NN.N - DD-MMM-YYYY +==================== +- Added the 'additional_graph_name' configuration option. [#388] +- Fixed an error in 'pgsql.pm' if a non-privileged user is used to read the + statistics. [#384] +- Fixed the amdgpu section in 'monitorix.conf'. [#385] +- Fixed a change in the quotation marks introduced in 3.14 that prevented from + sending reports. [#391] + (thanks to Michael Bronzini, mb20 AT bronzeware.se for pointing this out) +- Fixed wrong index for image directory in 'amdgpu.pm', 'nvidiagpu.pm' and + 'nvme.pm'. [#387] + + 3.14.0 - 18-Jan-2022 ==================== - Added a complete graph to support NVMe device statistics ('nvme.pm'). [#215] From 8c8bd09f8bb497c9e73822292984ac206594f966 Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Thu, 3 Feb 2022 11:00:39 +0100 Subject: [PATCH 5/7] Add improved line padding which checks the actually needed lines to ipmi.pm plots. --- lib/ipmi.pm | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/lib/ipmi.pm b/lib/ipmi.pm index aa1e4d5..9f1f867 100644 --- a/lib/ipmi.pm +++ b/lib/ipmi.pm @@ -77,7 +77,7 @@ sub ipmi_init { push(@max, "RRA:MAX:0.5:1440:" . (365 * $n)); push(@last, "RRA:LAST:0.5:1440:" . (365 * $n)); } - for($n = 0; $n < scalar(my @sl = split(',', $ipmi->{list})); $n++) { + for($n = 0; $n < scalar(my @sensor_list = split(',', $ipmi->{list})); $n++) { push(@tmp, "DS:ipmi" . $n . "_s1:GAUGE:120:U:U"); push(@tmp, "DS:ipmi" . $n . "_s2:GAUGE:120:U:U"); push(@tmp, "DS:ipmi" . $n . "_s3:GAUGE:120:U:U"); @@ -149,8 +149,10 @@ sub ipmi_update { my @data = ; close(IN); + my @sensor_list = split(',', $ipmi->{list}); + my $e = 0; - while($e < scalar(my @sl = split(',', $ipmi->{list}))) { + while($e < scalar(@sensor_list)) { my $e2 = 0; foreach my $i (split(',', $ipmi->{desc}->{$e})) { my $unit; @@ -195,7 +197,7 @@ sub ipmi_update { } $e = 0; - while($e < scalar(my @sl = split(',', $ipmi->{list}))) { + while($e < scalar(@sensor_list)) { for($n = 0; $n < 9; $n++) { $sens[$e][$n] = 0 unless defined $sens[$e][$n]; $rrdata .= ":" . $sens[$e][$n]; @@ -271,7 +273,7 @@ sub ipmi_cgi { } $title = !$silent ? $title : ""; - + my @sensor_list = split(',', $ipmi->{list}); # text mode # @@ -292,7 +294,7 @@ sub ipmi_cgi { my $line3; push(@output, "
\n");
 		push(@output, "    ");
-		for($n = 0; $n < scalar(my @sl = split(',', $ipmi->{list})); $n++) {
+		for($n = 0; $n < scalar(@sensor_list); $n++) {
 			$line1 = "";
 			foreach my $i (split(',', $ipmi->{desc}->{$n})) {
 				$i = trim($i);
@@ -304,7 +306,7 @@ sub ipmi_cgi {
 			}
 			if($line1) {
 				my $i = length($line1);
-				push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($sl[$n])))));
+				push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($sensor_list[$n])))));
 			}
 		}
 		push(@output, "\n");
@@ -320,7 +322,7 @@ sub ipmi_cgi {
 			$line = @$data[$n];
 			$time = $time - (1 / $tf->{ts});
 			push(@output, sprintf(" %2d$tf->{tc} ", $time));
-			for($n2 = 0; $n2 < scalar(my @sl = split(',', $ipmi->{list})); $n2++) {
+			for($n2 = 0; $n2 < scalar(@sensor_list); $n2++) {
 				$n3 = $n2 * 9;
 				foreach my $i (split(',', $ipmi->{desc}->{$n2})) {
 					$from = $n3++;
@@ -353,7 +355,7 @@ sub ipmi_cgi {
 		$u = "";
 	}
 
-	for($n = 0; $n < scalar(my @sl = split(',', $ipmi->{list})); $n++) {
+	for($n = 0; $n < scalar(@sensor_list); $n++) {
 		$str = $u . $package . $n . "." . $tf->{when} . ".$imgfmt_lc";
 		push(@IMG, $str);
 		unlink("$IMG_DIR" . $str);
@@ -364,16 +366,36 @@ sub ipmi_cgi {
 		}
 	}
 
+	my $graphs_per_row = $ipmi->{graphs_per_row};
+	my @linpad =(0) x scalar(@sensor_list);
+	if ($graphs_per_row > 1) {
+		for(my $n = 0; $n < scalar(@sensor_list); $n++) {
+			my @ls = split(',', $ipmi->{desc}->{$n});
+			$linpad[$n] = scalar(@ls);
+		}
+		for(my $n = 0; $n < scalar(@linpad); $n++) {
+			if ($n % $graphs_per_row == 0) {
+				my $max_number_of_lines = 0;
+				for (my $sub_n = $n; $sub_n < min($n + $graphs_per_row, scalar(@linpad)); $sub_n++) {
+					$max_number_of_lines = max($max_number_of_lines, $linpad[$sub_n]);
+				}
+				for (my $sub_n = $n; $sub_n < min($n + $graphs_per_row, scalar(@linpad)); $sub_n++) {
+					$linpad[$sub_n] = $max_number_of_lines;
+				}
+			}
+		}
+	}
+
 	$n = 0;
-	while($n < scalar(my @sl = split(',', $ipmi->{list}))) {
+	while($n < scalar(@sensor_list)) {
 		if($title) {
 			if($n == 0) {
-				push(@output, main::graph_header($title, $ipmi->{graphs_per_row}));
+				push(@output, main::graph_header($title, $graphs_per_row));
 			}
 			push(@output, "    \n");
 		}
-		for($n2 = 0; $n2 < $ipmi->{graphs_per_row}; $n2++) {
-			last unless $n < scalar(my @sl = split(',', $ipmi->{list}));
+		for($n2 = 0; $n2 < $graphs_per_row; $n2++) {
+			last unless $n < scalar(@sensor_list);
 			if($title) {
 				push(@output, "    \n");
 			}
@@ -392,7 +414,7 @@ sub ipmi_cgi {
 				push(@tmpz, "LINE2:s" . ($e + 1) . $LC[$e] . ":$str");
 				$e++;
 			}
-			while($e < 9) {
+			while($e < $linpad[$n]) {
 				push(@tmp, "COMMENT: \\n");
 				$e++;
 			}
@@ -402,7 +424,7 @@ sub ipmi_cgi {
 				push(@CDEF, "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF");
 			}
 			($width, $height) = split('x', $config->{graph_size}->{medium});
-			$str = substr(trim($sl[$n]), 0, 25);
+			$str = substr(trim($sensor_list[$n]), 0, 25);
 			my $cdef_allvalues = $gap_on_all_nan ? "CDEF:allvalues=s1,UN,0,1,IF,s2,UN,0,1,IF,s3,UN,0,1,IF,s4,UN,0,1,IF,s5,UN,0,1,IF,s6,UN,0,1,IF,s7,UN,0,1,IF,s8,UN,0,1,IF,s9,UN,0,1,IF,+,+,+,+,+,+,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=s1,s2,s3,s4,s5,s6,s7,s8,s9,+,+,+,+,+,+,+,+";
 			$pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$n]",
 				"--title=$str  ($tf->{nwhen}$tf->{twhen})",

From cd6b03ba62f87d7730ac391b14c9f927e762c7ac Mon Sep 17 00:00:00 2001
From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com>
Date: Thu, 3 Feb 2022 11:18:50 +0100
Subject: [PATCH 6/7] Add improved line padding which checks the actually
 needed lines to du.pm plots.

---
 lib/du.pm | 56 +++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 16 deletions(-)

diff --git a/lib/du.pm b/lib/du.pm
index af17801..f7bbc57 100644
--- a/lib/du.pm
+++ b/lib/du.pm
@@ -53,6 +53,8 @@ sub du_init {
 		$heartbeat = 2 * $refresh_interval;
 	}
 
+	my @disk_list = split(',', $du->{list});
+
 	if(-e $rrd) {
 		$info = RRDs::info($rrd);
 		for my $key (keys %$info) {
@@ -76,8 +78,8 @@ sub du_init {
 				}
 			}
 		}
-		if(scalar(@ds) / 9 != scalar(my @fl = split(',', $du->{list}))) {
-			logger("$myself: Detected size mismatch between 'list' (" . scalar(my @fl = split(',', $du->{list})) . ") and $rrd (" . scalar(@ds) / 9 . "). Resizing it accordingly. All historical data will be lost. Backup file created.");
+		if(scalar(@ds) / 9 != scalar(@disk_list)) {
+			logger("$myself: Detected size mismatch between 'list' (" . scalar(@disk_list) . ") and $rrd (" . scalar(@ds) / 9 . "). Resizing it accordingly. All historical data will be lost. Backup file created.");
 			rename($rrd, "$rrd.bak");
 		}
 		if(scalar(@rra) < 12 + (4 * $config->{max_historic_years})) {
@@ -106,7 +108,7 @@ sub du_init {
 			push(@max, "RRA:MAX:0.5:1440:" . (365 * $n));
 			push(@last, "RRA:LAST:0.5:1440:" . (365 * $n));
 		}
-		for($n = 0; $n < scalar(my @fl = split(',', $du->{list})); $n++) {
+		for($n = 0; $n < scalar(@disk_list); $n++) {
 			push(@tmp, "DS:du" . $n . "_d1:GAUGE:" . $heartbeat . ":0:U");
 			push(@tmp, "DS:du" . $n . "_d2:GAUGE:" . $heartbeat . ":0:U");
 			push(@tmp, "DS:du" . $n . "_d3:GAUGE:" . $heartbeat . ":0:U");
@@ -177,8 +179,10 @@ sub du_update {
 		return if(($min + 60 * $hour) % int($refresh_interval / 60));
 	}
 
+	my @disk_list = split(',', $du->{list});
+
 	my $e = 0;
-	while($e < scalar(my @dl = split(',', $du->{list}))) {
+	while($e < scalar(@disk_list)) {
 		my $type;
 		my $e2 = 0;
 
@@ -215,7 +219,7 @@ sub du_update {
 	}
 
 	$e = 0;
-	while($e < scalar(my @dl = split(',', $du->{list}))) {
+	while($e < scalar(@disk_list)) {
 		for($n = 0; $n < 9; $n++) {
 			$dirs[$e][$n] = 0 unless defined $dirs[$e][$n];
 			$rrdata .= ":" . $dirs[$e][$n];
@@ -291,7 +295,7 @@ sub du_cgi {
 	}
 
 	$title = !$silent ? $title : "";
-
+	my @disk_list = split(',', $du->{list});
 
 	# text mode
 	#
@@ -312,7 +316,7 @@ sub du_cgi {
 		my $line3;
 		push(@output, "    
\n");
 		push(@output, "    ");
-		for($n = 0; $n < scalar(my @dl = split(',', $du->{list})); $n++) {
+		for($n = 0; $n < scalar(@disk_list); $n++) {
 			$line1 = "";
 			foreach my $i (split(',', $du->{desc}->{$n})) {
 				$i = trim($i);
@@ -324,7 +328,7 @@ sub du_cgi {
 			}
 			if($line1) {
 				my $i = length($line1);
-				push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($dl[$n])))));
+				push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($disk_list[$n])))));
 			}
 		}
 		push(@output, "\n");
@@ -341,7 +345,7 @@ sub du_cgi {
 			$line = @$data[$n];
 			$time = $time - (1 / $tf->{ts});
 			push(@output, sprintf(" %2d$tf->{tc} ", $time));
-			for($n2 = 0; $n2 < scalar(my @dl = split(',', $du->{list})); $n2++) {
+			for($n2 = 0; $n2 < scalar(@disk_list); $n2++) {
 				$n3 = 0;
 				foreach my $i (split(',', $du->{desc}->{$n2})) {
 					$from = $n2 * 9 + $n3++;
@@ -375,7 +379,7 @@ sub du_cgi {
 		$u = "";
 	}
 
-	for($n = 0; $n < scalar(my @dl = split(',', $du->{list})); $n++) {
+	for($n = 0; $n < scalar(@disk_list); $n++) {
 		$str = $u . $package . $n . "." . $tf->{when} . ".$imgfmt_lc";
 		push(@IMG, $str);
 		unlink("$IMG_DIR" . $str);
@@ -386,21 +390,41 @@ sub du_cgi {
 		}
 	}
 
+	my $graphs_per_row = $du->{graphs_per_row};
+	my @linpad =(0) x scalar(@disk_list);
+	if ($graphs_per_row > 1) {
+		for(my $n = 0; $n < scalar(@disk_list); $n++) {
+			my @ls = split(',', $du->{desc}->{$n});
+			$linpad[$n] = scalar(@ls);
+		}
+		for(my $n = 0; $n < scalar(@linpad); $n++) {
+			if ($n % $graphs_per_row == 0) {
+				my $max_number_of_lines = 0;
+				for (my $sub_n = $n; $sub_n < min($n + $graphs_per_row, scalar(@linpad)); $sub_n++) {
+					$max_number_of_lines = max($max_number_of_lines, $linpad[$sub_n]);
+				}
+				for (my $sub_n = $n; $sub_n < min($n + $graphs_per_row, scalar(@linpad)); $sub_n++) {
+					$linpad[$sub_n] = $max_number_of_lines;
+				}
+			}
+		}
+	}
+
 	@riglim = @{setup_riglim($rigid[0], $limit[0])};
 	$n = 0;
-	while($n < scalar(my @dl = split(',', $du->{list}))) {
+	while($n < scalar(@disk_list)) {
 		if($title) {
 			if($n == 0) {
-				push(@output, main::graph_header($title, $du->{graphs_per_row}));
+				push(@output, main::graph_header($title, $graphs_per_row));
 			}
 			push(@output, "    \n");
 		}
-		for($n2 = 0; $n2 < $du->{graphs_per_row}; $n2++) {
+		for($n2 = 0; $n2 < $graphs_per_row; $n2++) {
 			my $type;
 			my @DEF0;
 			my @CDEF0;
 
-			last unless $n < scalar(my @dl = split(',', $du->{list}));
+			last unless $n < scalar(@disk_list);
 			if($title) {
 				push(@output, "    \n");
 			}
@@ -460,7 +484,7 @@ sub du_cgi {
 				push(@tmpz, "LINE2:d" . ($e + 1) . $LC[$e] . ":$str");
 				$e++;
 			}
-			while($e < 9) {
+			while($e < $linpad[$n]) {
 				push(@tmp, "COMMENT: \\n");
 				$e++;
 			}
@@ -470,7 +494,7 @@ sub du_cgi {
 				push(@CDEF, "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF");
 			}
 			($width, $height) = split('x', $config->{graph_size}->{medium});
-			$str = substr(trim($dl[$n]), 0, 25);
+			$str = substr(trim($disk_list[$n]), 0, 25);
 			$pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$n]",
 				"--title=$str  ($tf->{nwhen}$tf->{twhen})",
 				"--start=-$tf->{nwhen}$tf->{twhen}",

From 2b4f1abc8ea0a4918a288dd13f00c04efd6a6d0c Mon Sep 17 00:00:00 2001
From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com>
Date: Thu, 3 Feb 2022 11:18:50 +0100
Subject: [PATCH 7/7] Add improved line padding which checks the actually
 needed lines to du.pm plots.

---
 lib/du.pm | 56 +++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 16 deletions(-)

diff --git a/lib/du.pm b/lib/du.pm
index af17801..f7bbc57 100644
--- a/lib/du.pm
+++ b/lib/du.pm
@@ -53,6 +53,8 @@ sub du_init {
 		$heartbeat = 2 * $refresh_interval;
 	}
 
+	my @disk_list = split(',', $du->{list});
+
 	if(-e $rrd) {
 		$info = RRDs::info($rrd);
 		for my $key (keys %$info) {
@@ -76,8 +78,8 @@ sub du_init {
 				}
 			}
 		}
-		if(scalar(@ds) / 9 != scalar(my @fl = split(',', $du->{list}))) {
-			logger("$myself: Detected size mismatch between 'list' (" . scalar(my @fl = split(',', $du->{list})) . ") and $rrd (" . scalar(@ds) / 9 . "). Resizing it accordingly. All historical data will be lost. Backup file created.");
+		if(scalar(@ds) / 9 != scalar(@disk_list)) {
+			logger("$myself: Detected size mismatch between 'list' (" . scalar(@disk_list) . ") and $rrd (" . scalar(@ds) / 9 . "). Resizing it accordingly. All historical data will be lost. Backup file created.");
 			rename($rrd, "$rrd.bak");
 		}
 		if(scalar(@rra) < 12 + (4 * $config->{max_historic_years})) {
@@ -106,7 +108,7 @@ sub du_init {
 			push(@max, "RRA:MAX:0.5:1440:" . (365 * $n));
 			push(@last, "RRA:LAST:0.5:1440:" . (365 * $n));
 		}
-		for($n = 0; $n < scalar(my @fl = split(',', $du->{list})); $n++) {
+		for($n = 0; $n < scalar(@disk_list); $n++) {
 			push(@tmp, "DS:du" . $n . "_d1:GAUGE:" . $heartbeat . ":0:U");
 			push(@tmp, "DS:du" . $n . "_d2:GAUGE:" . $heartbeat . ":0:U");
 			push(@tmp, "DS:du" . $n . "_d3:GAUGE:" . $heartbeat . ":0:U");
@@ -177,8 +179,10 @@ sub du_update {
 		return if(($min + 60 * $hour) % int($refresh_interval / 60));
 	}
 
+	my @disk_list = split(',', $du->{list});
+
 	my $e = 0;
-	while($e < scalar(my @dl = split(',', $du->{list}))) {
+	while($e < scalar(@disk_list)) {
 		my $type;
 		my $e2 = 0;
 
@@ -215,7 +219,7 @@ sub du_update {
 	}
 
 	$e = 0;
-	while($e < scalar(my @dl = split(',', $du->{list}))) {
+	while($e < scalar(@disk_list)) {
 		for($n = 0; $n < 9; $n++) {
 			$dirs[$e][$n] = 0 unless defined $dirs[$e][$n];
 			$rrdata .= ":" . $dirs[$e][$n];
@@ -291,7 +295,7 @@ sub du_cgi {
 	}
 
 	$title = !$silent ? $title : "";
-
+	my @disk_list = split(',', $du->{list});
 
 	# text mode
 	#
@@ -312,7 +316,7 @@ sub du_cgi {
 		my $line3;
 		push(@output, "    
\n");
 		push(@output, "    ");
-		for($n = 0; $n < scalar(my @dl = split(',', $du->{list})); $n++) {
+		for($n = 0; $n < scalar(@disk_list); $n++) {
 			$line1 = "";
 			foreach my $i (split(',', $du->{desc}->{$n})) {
 				$i = trim($i);
@@ -324,7 +328,7 @@ sub du_cgi {
 			}
 			if($line1) {
 				my $i = length($line1);
-				push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($dl[$n])))));
+				push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($disk_list[$n])))));
 			}
 		}
 		push(@output, "\n");
@@ -341,7 +345,7 @@ sub du_cgi {
 			$line = @$data[$n];
 			$time = $time - (1 / $tf->{ts});
 			push(@output, sprintf(" %2d$tf->{tc} ", $time));
-			for($n2 = 0; $n2 < scalar(my @dl = split(',', $du->{list})); $n2++) {
+			for($n2 = 0; $n2 < scalar(@disk_list); $n2++) {
 				$n3 = 0;
 				foreach my $i (split(',', $du->{desc}->{$n2})) {
 					$from = $n2 * 9 + $n3++;
@@ -375,7 +379,7 @@ sub du_cgi {
 		$u = "";
 	}
 
-	for($n = 0; $n < scalar(my @dl = split(',', $du->{list})); $n++) {
+	for($n = 0; $n < scalar(@disk_list); $n++) {
 		$str = $u . $package . $n . "." . $tf->{when} . ".$imgfmt_lc";
 		push(@IMG, $str);
 		unlink("$IMG_DIR" . $str);
@@ -386,21 +390,41 @@ sub du_cgi {
 		}
 	}
 
+	my $graphs_per_row = $du->{graphs_per_row};
+	my @linpad =(0) x scalar(@disk_list);
+	if ($graphs_per_row > 1) {
+		for(my $n = 0; $n < scalar(@disk_list); $n++) {
+			my @ls = split(',', $du->{desc}->{$n});
+			$linpad[$n] = scalar(@ls);
+		}
+		for(my $n = 0; $n < scalar(@linpad); $n++) {
+			if ($n % $graphs_per_row == 0) {
+				my $max_number_of_lines = 0;
+				for (my $sub_n = $n; $sub_n < min($n + $graphs_per_row, scalar(@linpad)); $sub_n++) {
+					$max_number_of_lines = max($max_number_of_lines, $linpad[$sub_n]);
+				}
+				for (my $sub_n = $n; $sub_n < min($n + $graphs_per_row, scalar(@linpad)); $sub_n++) {
+					$linpad[$sub_n] = $max_number_of_lines;
+				}
+			}
+		}
+	}
+
 	@riglim = @{setup_riglim($rigid[0], $limit[0])};
 	$n = 0;
-	while($n < scalar(my @dl = split(',', $du->{list}))) {
+	while($n < scalar(@disk_list)) {
 		if($title) {
 			if($n == 0) {
-				push(@output, main::graph_header($title, $du->{graphs_per_row}));
+				push(@output, main::graph_header($title, $graphs_per_row));
 			}
 			push(@output, "    \n");
 		}
-		for($n2 = 0; $n2 < $du->{graphs_per_row}; $n2++) {
+		for($n2 = 0; $n2 < $graphs_per_row; $n2++) {
 			my $type;
 			my @DEF0;
 			my @CDEF0;
 
-			last unless $n < scalar(my @dl = split(',', $du->{list}));
+			last unless $n < scalar(@disk_list);
 			if($title) {
 				push(@output, "    \n");
 			}
@@ -460,7 +484,7 @@ sub du_cgi {
 				push(@tmpz, "LINE2:d" . ($e + 1) . $LC[$e] . ":$str");
 				$e++;
 			}
-			while($e < 9) {
+			while($e < $linpad[$n]) {
 				push(@tmp, "COMMENT: \\n");
 				$e++;
 			}
@@ -470,7 +494,7 @@ sub du_cgi {
 				push(@CDEF, "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF");
 			}
 			($width, $height) = split('x', $config->{graph_size}->{medium});
-			$str = substr(trim($dl[$n]), 0, 25);
+			$str = substr(trim($disk_list[$n]), 0, 25);
 			$pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$n]",
 				"--title=$str  ($tf->{nwhen}$tf->{twhen})",
 				"--start=-$tf->{nwhen}$tf->{twhen}",