Zoomed graphs now honour the 'global_zoom' option, and also use the function RRDs::graphv to fit better in the pop up window of the browser (only for RRDtool 1.3+)

This commit is contained in:
Jordi Sanfeliu 2014-12-30 15:57:00 +01:00
parent 2ec001b391
commit 6986519fc7
1 changed files with 15 additions and 3 deletions

View File

@ -336,6 +336,8 @@ sub system_update {
} }
sub system_cgi { sub system_cgi {
no strict "refs";
my ($package, $config, $cgi) = @_; my ($package, $config, $cgi) = @_;
my $system = $config->{system}; my $system = $config->{system};
@ -346,6 +348,13 @@ sub system_cgi {
my $graph = $cgi->{graph}; my $graph = $cgi->{graph};
my $silent = $cgi->{silent}; my $silent = $cgi->{silent};
my $zoom = "--zoom=" . $config->{global_zoom}; my $zoom = "--zoom=" . $config->{global_zoom};
my %rrd = (
'new' => \&RRDs::graphv,
'old' => \&RRDs::graph,
);
my $version = "new";
my $pic;
my $picz;
my $u = ""; my $u = "";
my $width; my $width;
@ -357,10 +366,12 @@ sub system_cgi {
my $n; my $n;
my $err; my $err;
$version = "old" if $RRDs::VERSION < 1.3;
my $rrd = $config->{base_lib} . $package . ".rrd"; my $rrd = $config->{base_lib} . $package . ".rrd";
my $title = $config->{graph_title}->{$package}; my $title = $config->{graph_title}->{$package};
my $PNG_DIR = $config->{base_dir} . "/" . $config->{imgs_dir}; my $PNG_DIR = $config->{base_dir} . "/" . $config->{imgs_dir};
$title = !$silent ? $title : ""; $title = !$silent ? $title : "";
my $total_mem; my $total_mem;
@ -496,7 +507,7 @@ sub system_cgi {
@tmp = @tmpz; @tmp = @tmpz;
push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n");
} }
RRDs::graph("$PNG_DIR" . "$PNG1", $pic = $rrd{$version}->("$PNG_DIR" . "$PNG1",
"--title=$config->{graphs}->{_system1} ($tf->{nwhen}$tf->{twhen})", "--title=$config->{graphs}->{_system1} ($tf->{nwhen}$tf->{twhen})",
"--start=-$tf->{nwhen}$tf->{twhen}", "--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG", "--imgformat=PNG",
@ -519,7 +530,7 @@ sub system_cgi {
print("ERROR: while graphing $PNG_DIR" . "$PNG1: $err\n") if $err; print("ERROR: while graphing $PNG_DIR" . "$PNG1: $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});
RRDs::graph("$PNG_DIR" . "$PNG1z", $picz = $rrd{$version}->("$PNG_DIR" . "$PNG1z",
"--title=$config->{graphs}->{_system1} ($tf->{nwhen}$tf->{twhen})", "--title=$config->{graphs}->{_system1} ($tf->{nwhen}$tf->{twhen})",
"--start=-$tf->{nwhen}$tf->{twhen}", "--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG", "--imgformat=PNG",
@ -527,6 +538,7 @@ sub system_cgi {
"--width=$width", "--width=$width",
"--height=$height", "--height=$height",
@riglim, @riglim,
$zoom,
@{$cgi->{version12}}, @{$cgi->{version12}},
@{$colors->{graph_colors}}, @{$colors->{graph_colors}},
"DEF:load1=$rrd:system_load1:AVERAGE", "DEF:load1=$rrd:system_load1:AVERAGE",
@ -544,7 +556,7 @@ sub system_cgi {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1 . "' border='0'></a>\n"); print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1 . "' border='0'></a>\n");
} }
else { else {
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1z . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1 . "' border='0'></a>\n"); print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1z . "','','width=" . ($picz->{image_width} * $config->{global_zoom}) . ",height=" . ($picz->{image_height} * $config->{global_zoom}) . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1 . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1 . "'>\n"); print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $PNG1 . "'>\n");