Changeset 1323
- Timestamp:
- 21/09/07 15:06:12 (4 years ago)
- Files:
-
- trunk/server/munin-cgi-graph.in (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/server/munin-cgi-graph.in
r1322 r1323 18 18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 19 # 20 #21 20 # $Id$ 21 # 22 # Please see http://munin.projects.linpro.no/wiki/CgiHowto for how to 23 # use this, and how to convert it to fastcgi which will improve speed. 24 # 22 25 23 26 use RRDs; … … 27 30 use Date::Manip; 28 31 use POSIX qw(strftime); 32 use IPC::SysV qw(IPC_CREAT); 29 33 30 34 my $GRAPHER = "@@LIBDIR@@/munin-graph"; … … 51 55 my $dom = ""; 52 56 my $lock = ""; 57 my $IPC_KEY = 89340; 53 58 54 59 my $config = &munin_readconfig ($conffile); … … 107 112 # third value is the default maximum. 108 113 109 # NOTE: The munin_*lock functions are not exactly ideal for race prone 110 # locking, they're a bit fuzzy. A better solution, which would not 111 # imply a "sleep 1" would be to use semaphores. See "perldoc perlipc" 112 # and "man semop". 114 # Fox kindly submitted a patch to convert to SysV IPC semaphores. 115 # Lovely! (ticket #499). 113 116 114 117 my $max_cgi_graph_jobs = &munin_get ($config, "max_cgi_graph_jobs" , 6, $dom); 115 118 116 until ( $lock ) { 117 foreach my $n ( 1 .. $max_cgi_graph_jobs ) { 118 if (&munin_getlock ("$config->{rundir}/munin-cgi-graph-$n.lock")) { 119 $lock = "munin-cgi-graph-$n.lock"; 120 last; 121 } 122 } 123 sleep 1; 124 } 119 my $opstring; 120 121 # Get semaphore handle 122 my $semid = semget($IPC_KEY, 0, 0 ); 123 124 if(!$semid) { 125 # Or create it if needed 126 $semid = semget($IPC_KEY, 1 , 0666 | IPC_CREAT ) || 127 die "Creating semaphore: $!"; 128 129 # And initialize to max_cgi_graph_jobs 130 $opstring = pack("s!s!s!",0, $max_cgi_graph_jobs,0); 131 semop($semid,$opstring) || die "$!"; 132 } 133 134 # Decrement, or lock/hang/yield if already 0 135 $opstring = pack("s!s!s!",0, -1, 0); 136 semop($semid,$opstring); 125 137 126 138 &graph ($filename); 127 139 128 munin_removelock($config->{rundir}.'/'.$lock); 140 # Increment (and release waiting processes) 141 $opstring = pack("s!s!s!",0, 1, 0); 142 semop($semid,$opstring); 129 143 130 144 sub graph { … … 227 241 } 228 242 229 sub graph_usable 230 { 243 sub graph_usable { 231 244 my $filename = shift; 232 245 my $time = shift; 233 246 234 if (-f $filename) 235 { 247 if (-f $filename) { 236 248 my @stats = stat (_); 237 if (($stats[9]) > ($time - $time%$period{$scale})) 238 { 249 my $expire = ($stats[9] - $time%$period{$scale}+$period{$scale})-$time; 250 #print STDERR "Expires in: $expire\n"; 251 252 if ($expire >= 0) { 239 253 #print STDERR "Skipping munin-graph-run for \"$filename\".\n"; 240 #print STDERR ("Graph unexpired for $scale. ($stats[9] , $time, " , ($time%$period{$scale}), ", ", ($time - $time%$period{$scale}),").\n");254 #print STDERR ("Graph unexpired for $scale. ($stats[9] , $time, ". ($time%$period{$scale}). ", ". ($time - $time%$period{$scale}). ").\n"); 241 255 return 1; 242 } 243 else 244 { 245 #print STDERR ("Graph expired for $scale. ($stats[9] , $time, ", ($time%$period{$scale}), ", ", ($time - $time%$period{$scale}), ").\n"); 256 } else { 257 #print STDERR ("Graph expired for $scale. ($stats[9] , $time, ". ($time%$period{$scale}). ", ". ($time - $time%$period{$scale}). ").\n"); 246 258 return 0; 247 259 } … … 250 262 } 251 263 252 sub draw_graph 253 { 264 sub draw_graph { 254 265 my $host = shift; 255 266 my $serv = shift; 256 267 my $scale = shift; 257 268 258 $serv =~ s/[^\w_\/"'\[\]\(\)+=-]/_/; $serv =~ /^(.+)$/; $serv = $1; 259 $host =~ s/[^\w_\/"'\[\]\(\)+=-]/_/; $host =~ /^(.+)$/; $host = $1; 269 $serv =~ s/[^\w_\/"'\[\]\(\)+=-]/_/; $serv =~ /^(.+)$/; $serv = $1; #" 270 $host =~ s/[^\w_\/"'\[\]\(\)+=-]/_/; $host =~ /^(.+)$/; $host = $1; #" 260 271 261 272 my @params = ($GRAPHER); 262 273 push @params, @$scale; 263 push @params, "--skip-locking", "--skip-stats" ;274 push @params, "--skip-locking", "--skip-stats", "--nolazy"; 264 275 push @params, "--host", $host, "--service", $serv; 265 276 push @params, "STDERR>&STDOUT"; … … 276 287 } 277 288 278 sub modified 279 { 289 sub modified { 280 290 # Format of since_string If-Modified-Since: Wed, 23 Jun 2004 16:11:06 GMT 281 291
