From 123edfe24693f985f45570143d81a223ed6ad95d Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Thu, 12 Feb 2015 15:40:51 +0100 Subject: [PATCH] Zoomed graphs in 'traffacct.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/traffacct.pm | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/traffacct.pm b/lib/traffacct.pm index 0fe976f..6d2c5eb 100644 --- a/lib/traffacct.pm +++ b/lib/traffacct.pm @@ -1,7 +1,7 @@ # # Monitorix - A lightweight system monitoring tool. # -# Copyright (C) 2005-2014 by Jordi Sanfeliu +# Copyright (C) 2005-2015 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 @@ -425,6 +425,16 @@ sub traffacct_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; @@ -442,6 +452,7 @@ sub traffacct_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}; @@ -524,7 +535,7 @@ sub traffacct_cgi { push(@CDEF, "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF"); } ($width, $height) = split('x', $config->{graph_size}->{remote}); - RRDs::graph("$PNG_DIR" . "$PNG[$n]", + $pic = $rrd{$version}->("$PNG_DIR" . "$PNG[$n]", "--title=$name traffic ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -545,7 +556,7 @@ sub traffacct_cgi { print("ERROR: while graphing $PNG_DIR" . "$PNG[$n]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); - RRDs::graph("$PNG_DIR" . "$PNGz[$n]", + $picz = $rrd{$version}->("$PNG_DIR" . "$PNGz[$n]", "--title=$name traffic ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -553,6 +564,7 @@ sub traffacct_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, @@ -567,9 +579,15 @@ sub traffacct_cgi { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$n] . "\">\n"); - } - else { - print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$n] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\">\n"); + } else { + 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[$n] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { print(" \n"); @@ -630,7 +648,7 @@ sub traffacct_cgi { push(@CDEF, "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF"); } ($width, $height) = split('x', $config->{graph_size}->{main}); - RRDs::graph("$PNG_DIR" . "$PNG[$cgi->{val}]", + $pic = $rrd{$version}->("$PNG_DIR" . "$PNG[$cgi->{val}]", "--title=$tal[$cgi->{val}] traffic ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -652,7 +670,7 @@ sub traffacct_cgi { print("ERROR: while graphing $PNG_DIR" . "$PNG[$cgi->{val}]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); - RRDs::graph("$PNG_DIR" . "$PNGz[$cgi->{val}]", + $picz = $rrd{$version}->("$PNG_DIR" . "$PNGz[$cgi->{val}]", "--title=$tal[$cgi->{val}] traffic ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -660,6 +678,7 @@ sub traffacct_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$colors->{graph_colors}}, "DEF:in=$rrd:traffacct" . $cgi->{val} . "_in:AVERAGE", @@ -675,9 +694,15 @@ sub traffacct_cgi { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$cgi->{val}] . "\">\n"); - } - else { - print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$cgi->{val}] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\">\n"); + } else { + 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[$cgi->{val}] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { print(" \n");