Changeset 3389
- Timestamp:
- 02/26/10 21:24:00 (2 years ago)
- Files:
-
- people/snide/pre_1.5/common/lib/Munin/Common/Config.pm (modified) (1 diff)
- people/snide/pre_1.5/common/lib/Munin/Common/Defaults.pm (modified) (1 diff)
- people/snide/pre_1.5/master/_bin/munin-fastcgi-graph.in (modified) (7 diffs)
- people/snide/pre_1.5/master/lib/Munin/Master/HTMLOld.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
people/snide/pre_1.5/common/lib/Munin/Common/Config.pm
r3139 r3389 38 38 "onlynullcdef", "group_order", "pipe", "pipe_command", 39 39 "unknown_limit", "notify_countdown", "dropdownlimit", 40 "max_graph_jobs", "munin_cgi_graph_jobs" ); 40 "max_graph_jobs", "munin_cgi_graph_jobs", 41 "cgitmpdir", 42 ); 41 43 42 44 my %bools = map { $_ => 1} qw(yes no true false on off 1 0); people/snide/pre_1.5/common/lib/Munin/Common/Defaults.pm
r2951 r3389 26 26 our $MUNIN_HTMLDIR = ''; 27 27 our $MUNIN_CGIDIR = ''; 28 our $MUNIN_CGITMPDIR = ''; 28 29 our $MUNIN_DBDIR = ''; 29 30 our $MUNIN_PLUGSTATE = ''; people/snide/pre_1.5/master/_bin/munin-fastcgi-graph.in
r3376 r3389 64 64 my $config = &munin_readconfig ($conffile); 65 65 66 # Get semaphore handle - Before graphing as recommended by snide.67 my $semid = undef;68 69 #sem_setup();70 71 66 # BEGIN FAST-CGI LOOP: 72 67 while (new CGI::Fast) { … … 93 88 # If a "Cache-Control: no-cache" header gets send, we regenerate the image in every case: 94 89 my $no_cache = $pinpoint || defined($ENV{HTTP_CACHE_CONTROL}) && $ENV{HTTP_CACHE_CONTROL} =~ /no-cache/i; 90 print STDERR "no_cache:$no_cache\n"; 91 92 # Compute the cache values 93 my $graph_ttl = $pinpoint ? 1 : $period{$scale}; 94 my $graph_last_expires = $time - $time % $graph_ttl; 95 95 96 if ($no_cache or (! &graph_usable ($filename, $time) )) { 96 my $graph_epoch = (! $no_cache) && file_newer_than($filename, $graph_last_expires); 97 if ($graph_epoch) { 98 # The graph is fresh enough. Sending either IMS if asked, or just skip generation 99 # Check for If-Modified-Since and send 304 if not changed: 100 if (defined $ENV{HTTP_IF_MODIFIED_SINCE} && 101 ! rfctime_newer_than($ENV{HTTP_IF_MODIFIED_SINCE}, $graph_epoch)) { 102 print "Status: 304\n"; 103 print "Content-Type: image/png\n"; 104 print "\n"; 105 106 # We replied, continue with the next request 107 next; 108 } 109 } else { 110 # Should generate it 97 111 my $scale_options; 98 112 if ($pinpoint) { … … 102 116 } 103 117 next unless draw_graph_or_complain($dom, $host, $serv, $scale_options, $filename, "$config->{logdir}/munin-cgi-graph.log"); 104 goto draw; 105 } 106 107 # At this time the file exists. But may be old. Or not.108 109 my @stats = stat ($filename);110 my $last_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9])); 118 } 119 120 # At this time the file exists and should be served 121 my @stats = stat ($filename); 122 my $mtime_epoch = $stats[9]; 123 my $last_modified = get_w3c_date_from_epoch($mtime_epoch); 124 111 125 # "Expires" has to use last modified time as base: 112 my $ expires = strftime ("%a, %d %b %Y %H:%M:%S GMT",113 gmtime($stats[9]+($period{$scale}-($stats[9]%$period{$scale}))));126 my $graph_next_expires = $mtime_epoch - ($mtime_epoch % $graph_ttl) + $graph_ttl; 127 my $expires = get_w3c_date_from_epoch($graph_next_expires); 114 128 115 # Check for If-Modified-Since and send 304 if not changed: 116 if (defined $ENV{HTTP_IF_MODIFIED_SINCE} and 117 !&modified ($ENV{HTTP_IF_MODIFIED_SINCE}, $stats[9]-1)) { 118 print "Status: 304\n"; 119 print "Content-Type: image/png\n"; 120 print "Expires: ", $expires, "\n"; 121 print "Last-Modified: $last_modified\n"; 122 print "\n"; 123 next; 124 } 125 126 draw: 127 my $period_scale = $pinpoint ? 1 : $period{$scale}; 128 @stats = stat ($filename); # restat to be sure 129 $last_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9])) unless defined($last_modified); 130 # "Expires" has to use last modified time as base: 131 #$expires = strftime ("%a, %d %b %Y %H:%M:%S GMT", 132 # gmtime($stats[9]+($period{$scale}-($stats[9]%$period_scale)))) unless defined ($expires); 133 129 130 # Sending headers 134 131 print "Status: 200\n"; 135 132 print "Content-Type: image/png\n"; 136 133 print "Content-Length: $stats[7]\n"; 137 #print "Expires: ", $expires, "\n"; 138 print "Last-Modified: $last_modified\n"; 134 135 # Conditionaly add timing informations 136 print "Expires: $expires\n" if $expires; 137 print "Last-Modified: $last_modified\n" if $last_modified; 139 138 print "\n"; 140 139 141 &graph ($filename);142 } 143 140 # Sending graph data 141 send_graph_data($filename); 142 } 144 143 # END FAST-CGI LOOP 145 144 146 sub sem_setup { 147 $semid = semget($IPC_KEY, 0, 0 ); 148 149 if(!defined($semid)) { 150 # Or create it if needed 151 $semid = semget($IPC_KEY, 1 , oct(666) | IPC_CREAT ); 152 153 die "Creating semaphore: $!" unless defined($semid); 154 155 my $max_cgi_graph_jobs = &munin_get ($config, "max_cgi_graph_jobs" , 6, $dom); 156 157 # And initialize to max_cgi_graph_jobs 158 my $opstring = pack("s!s!s!",0, $max_cgi_graph_jobs,0); 159 semop($semid,$opstring) || die "$!"; 160 } 161 } 162 163 164 sub sem_get { 165 # Call this before doing heavy work. 166 # Decrement, or lock/hang/yield if already 0 167 my $opstring = pack("s!s!s!",0, -1, 0); 168 semop($semid,$opstring); 169 } 170 171 172 sub sem_release { 173 # Call this after doing heavy work. 174 # Increment (and release waiting processes). 175 my $opstring = pack("s!s!s!",0, 1, 0); 176 semop($semid,$opstring); 177 } 178 179 180 sub graph { 181 # Serve the graph contents. This is not heavy, no semaphore. 145 sub get_w3c_date_from_epoch { 146 my $epoch = shift; 147 print STDERR "get_w3c_date_from_epoch($epoch)\n"; 148 return strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime($epoch)); 149 } 150 151 sub send_graph_data { 152 # Serve the graph contents. 182 153 my $filename = shift; 183 154 … … 195 166 my $scale = shift; 196 167 197 return "/tmp/munin-cgi-png/$domain/$name/$service-$scale.png"; 168 my $cgi_tmp_dir = $config->{cgitmpdir} || "/tmp/munin-cgi-tmp"; 169 170 return "$cgi_tmp_dir/$domain/$name/$service-$scale.png"; 198 171 } 199 172 … … 270 243 271 244 272 sub graph_usable{245 sub file_newer_than { 273 246 my $filename = shift; 274 247 my $time = shift; … … 276 249 if (-f $filename) { 277 250 my @stats = stat (_); 278 # $stats[9] holds the "last update" time and this needs to be in the last update period:279 if ($stats[9] > ($time - $time%$period{$scale})) {280 #print STDERR "Skipping munin-graph-run for \"$filename\".\n";281 #print STDERR ("Graph unexpired for $scale. ($stats[9] , $time, ". ($time%$period{$scale}). ", ". ($time - $time%$period{$scale}). ").\n"); 282 return 1;251 # $stats[9] holds the "last update" time and this needs 252 # to be in the last update period 253 my $last_update = $stats[9]; 254 if ($last_update > $time) { 255 return $last_update; 283 256 } else { 284 #print STDERR ("Graph expired for $scale. ($stats[9] , $time, ". ($time%$period{$scale}). ", ". ($time - $time%$period{$scale}). ").\n");285 257 return 0; 286 258 } 287 259 } 260 261 # No file found 288 262 return 0; 289 263 } … … 353 327 354 328 355 sub modified{329 sub rfctime_newer_than { 356 330 # See if the file has been modified since "the last time". 357 358 331 # Format of since_string If-Modified-Since: Wed, 23 Jun 2004 16:11:06 GMT 359 360 332 my $since_string = shift; 361 333 my $created = shift; people/snide/pre_1.5/master/lib/Munin/Master/HTMLOld.pm
r3376 r3389 983 983 984 984 for my $scale (@times) { 985 # Don't try to find the size if cgi is enabled, 986 # otherwise old data might pollute 987 next if ($method eq "cgi"); 985 988 if (my ($w, $h) 986 989 = get_png_size(munin_get_picture_filename($service, $scale))) { … … 994 997 $srv{imgyearsum} = "$srv{node}-year-sum.png"; 995 998 for my $scale (["week", "year"]) { 999 next if ($method eq "cgi"); 996 1000 if (my ($w, $h) 997 1001 = get_png_size(munin_get_picture_filename($service, $scale, 1)))
