From 5c77077d809f3d74f257f7c73620e5576bb8f95b Mon Sep 17 00:00:00 2001 From: Pierce Lopez Date: Fri, 25 Nov 2022 16:57:35 -0500 Subject: [PATCH] master: get graph width/height for html in graph-cgi mode also When generating html, if graph mode is cron, munin looks for the generated graph png files (from the previous run) to get width and height for the img elements, so that the page doesn't jump around for the few seconds it takes to download all the graph images. This can be done if graph mode is cgi, also, by looking in the cgitmpdir. Sometimes graph images won't be found, but if they are found they can be used. ----------------- This is admittedly a "hacky" implementation, and targetting the last stable branch instead of master. It is offered as an illustration of an idea that would be nice to have, if implemented properly. (The hacky implementation does work :) --- master/lib/Munin/Master/HTMLConfig.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/master/lib/Munin/Master/HTMLConfig.pm b/master/lib/Munin/Master/HTMLConfig.pm index 3f9cffa3e3..273a4b5add 100644 --- a/master/lib/Munin/Master/HTMLConfig.pm +++ b/master/lib/Munin/Master/HTMLConfig.pm @@ -511,8 +511,14 @@ sub generate_service_templates { $srv{zoomyear} = "$common_url&start_epoch=$start_year&stop_epoch=$epoch_now"; } + my $svccfg = { %$service }; + if ( munin_get($config, "graph_strategy", "cron") eq "cgi" ) { + my $cgitmpdir = munin_get($config, "cgitmpdir", "$Munin::Common::Defaults::MUNIN_DBDIR/cgi-tmp"); + $svccfg->{htmldir} = $cgitmpdir . "/munin-cgi-graph"; + } + for my $scale (@times) { - my ($w, $h) = get_png_size(munin_get_picture_filename($service, $scale)); + my ($w, $h) = get_png_size(munin_get_picture_filename($svccfg, $scale)); if ($w && $h) { $srv{"img" . $scale . "width"} = $w; $srv{"img" . $scale . "height"} = $h; @@ -524,7 +530,7 @@ sub generate_service_templates { $srv{imgyearsum} = "$srv{node}-year-sum.png"; for my $scale (["week", "year"]) { - my ($w, $h) = get_png_size(munin_get_picture_filename($service, $scale, 1)); + my ($w, $h) = get_png_size(munin_get_picture_filename($svccfg, $scale, 1)); if ($w && $h) { $srv{"img" . $scale . "sumwidth"} = $w; $srv{"img" . $scale . "sumheight"} = $h; @@ -725,14 +731,11 @@ sub borrowed_path { } } -#TODO: This method is obsolete when cgi-graphing is the only strategy left sub get_png_size { my $filename = shift; my $width = undef; my $height = undef; - return (undef, undef) if (munin_get($config, "graph_strategy", "cron") eq "cgi") ; - if (open(my $PNG, '<', $filename)) { my $incoming; binmode($PNG);