From 5a3d9f6a6823f805e310cba17dfb7d54770ae1d3 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Wed, 21 Jan 2015 18:20:32 +0100 Subject: [PATCH] Zoomed graphs in 'apache.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/apache.pm | 52 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/apache.pm b/lib/apache.pm index 5f8e8e4..1b16f5b 100644 --- a/lib/apache.pm +++ b/lib/apache.pm @@ -214,6 +214,15 @@ sub apache_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; @@ -231,6 +240,7 @@ sub apache_cgi { my $str; my $err; + $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}; @@ -368,7 +378,7 @@ sub apache_cgi { ($width, $height) = split('x', $config->{graph_size}->{main}) if $silent eq "imagetagbig"; @tmp = @tmpz; } - RRDs::graph("$PNG_DIR" . "$PNG[$e * 3]", + $pic = $rrd{$version}->("$PNG_DIR" . "$PNG[$e * 3]", "--title=$config->{graphs}->{_apache1} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -392,7 +402,7 @@ sub apache_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}->{_apache1} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -400,6 +410,7 @@ sub apache_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$colors->{graph_colors}}, "DEF:apache" . $e . "_busy=$rrd:apache" . $e . "_busy:AVERAGE", @@ -418,7 +429,14 @@ sub apache_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"); @@ -452,7 +470,7 @@ sub apache_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}->{_apache2} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -472,7 +490,7 @@ sub apache_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}->{_apache2} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -480,6 +498,7 @@ sub apache_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, @@ -497,7 +516,14 @@ sub apache_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"); @@ -527,7 +553,7 @@ sub apache_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}->{_apache3} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -547,7 +573,7 @@ sub apache_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}->{_apache3} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -555,6 +581,7 @@ sub apache_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, @@ -572,7 +599,14 @@ sub apache_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");