From befb213207d3fb851ad1bf897ebf77fcd41a463b Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Tue, 30 Dec 2014 17:53:05 +0100 Subject: [PATCH] Zoomed graphs in 'disk.pm' now honour the 'global_zoom' option, and they also use the function RRDs::graphv to fit better in the browser pop up window (only for RRDtool v1.3+) --- lib/disk.pm | 54 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/lib/disk.pm b/lib/disk.pm index 790f417..fdc6005 100644 --- a/lib/disk.pm +++ b/lib/disk.pm @@ -283,6 +283,8 @@ sub disk_update { } sub disk_cgi { + no strict "refs"; + my ($package, $config, $cgi) = @_; my $disk = $config->{disk}; @@ -293,6 +295,15 @@ sub disk_cgi { my $graph = $cgi->{graph}; my $silent = $cgi->{silent}; my $zoom = "--zoom=" . $config->{global_zoom}; + my %rrd = ( + 'new' => \&RRDs::graphv, + 'old' => \&RRDs::graph, + ); + my $version = "new"; + my $pic; + my $picz; + my $picz_width; + my $picz_height; my $u = ""; my $width; @@ -321,6 +332,7 @@ sub disk_cgi { "#EEEE44", ); + $version = "old" if $RRDs::VERSION < 1.3; my $rrd = $config->{base_lib} . $package . ".rrd"; my $title = $config->{graph_title}->{$package}; my $PNG_DIR = $config->{base_dir} . "/" . $config->{imgs_dir}; @@ -505,7 +517,7 @@ sub disk_cgi { push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n"); } - RRDs::graph("$PNG_DIR" . "$PNG[$e * 3]", + $pic = $rrd{$version}->("$PNG_DIR" . "$PNG[$e * 3]", "--title=$config->{graphs}->{_disk1} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -531,7 +543,7 @@ sub disk_cgi { print("ERROR: while graphing $PNG_DIR" . "$PNG[$e * 3]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); - RRDs::graph("$PNG_DIR" . "$PNGz[$e * 3]", + $picz = $rrd{$version}->("$PNG_DIR" . "$PNGz[$e * 3]", "--title=$config->{graphs}->{_disk1} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -539,6 +551,7 @@ sub disk_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$colors->{graph_colors}}, "DEF:temp0=$rrd:disk" . $e ."_hd0_temp:AVERAGE", @@ -562,7 +575,14 @@ sub disk_cgi { print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3] . "\">\n"); } else { - print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\">\n"); + if($version eq "new") { + $picz_width = $picz->{image_width} * $config->{global_zoom}; + $picz_height = $picz->{image_height} * $config->{global_zoom}; + } else { + $picz_width = $width + 115; + $picz_height = $height + 100; + } + print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { print(" \n"); @@ -627,7 +647,7 @@ sub disk_cgi { push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n"); } - RRDs::graph("$PNG_DIR" . "$PNG[$e * 3 + 1]", + $pic = $rrd{$version}->("$PNG_DIR" . "$PNG[$e * 3 + 1]", "--title=$config->{graphs}->{_disk2} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -654,7 +674,7 @@ sub disk_cgi { print("ERROR: while graphing $PNG_DIR" . "$PNG[$e * 3 + 1]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); - RRDs::graph("$PNG_DIR" . "$PNGz[$e * 3 + 1]", + $picz = $rrd{$version}->("$PNG_DIR" . "$PNGz[$e * 3 + 1]", "--title=$config->{graphs}->{_disk2} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -662,6 +682,7 @@ sub disk_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, @@ -686,7 +707,14 @@ sub disk_cgi { print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3 + 1] . "\">\n"); } else { - print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3 + 1] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\">\n"); + if($version eq "new") { + $picz_width = $picz->{image_width} * $config->{global_zoom}; + $picz_height = $picz->{image_height} * $config->{global_zoom}; + } else { + $picz_width = $width + 115; + $picz_height = $height + 100; + } + print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3 + 1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { print(" \n"); @@ -747,7 +775,7 @@ sub disk_cgi { push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n"); } - RRDs::graph("$PNG_DIR" . "$PNG[$e * 3 + 2]", + $pic = $rrd{$version}->("$PNG_DIR" . "$PNG[$e * 3 + 2]", "--title=$config->{graphs}->{_disk3} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -774,7 +802,7 @@ sub disk_cgi { print("ERROR: while graphing $PNG_DIR" . "$PNG[$e * 3 + 2]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); - RRDs::graph("$PNG_DIR" . "$PNGz[$e * 3 + 2]", + $picz = $rrd{$version}->("$PNG_DIR" . "$PNGz[$e * 3 + 2]", "--title=$config->{graphs}->{_disk3} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -782,6 +810,7 @@ sub disk_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, @@ -806,7 +835,14 @@ sub disk_cgi { print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3 + 2] . "\">\n"); } else { - print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3 + 2] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\">\n"); + if($version eq "new") { + $picz_width = $picz->{image_width} * $config->{global_zoom}; + $picz_height = $picz->{image_height} * $config->{global_zoom}; + } else { + $picz_width = $width + 115; + $picz_height = $height + 100; + } + print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 3 + 2] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { print(" \n");