--- projects/cms/source/reports/rrdgraphing/graph.pl 2002/05/20 16:11:23 1.3 +++ projects/cms/source/reports/rrdgraphing/graph.pl 2002/05/21 11:37:56 1.4 @@ -26,7 +26,7 @@ # Generates graphs from rrd databases for i-scream data. # # $Author: tdb $ -# $Id: graph.pl,v 1.3 2002/05/20 16:11:23 tdb Exp $ +# $Id: graph.pl,v 1.4 2002/05/21 11:37:56 tdb Exp $ #------------------------------------------------------------ ## TODO @@ -54,7 +54,17 @@ my($hex_underscore) = "_5f"; # maximum age (last modified) before an rrd or graph get cleaned up # (in seconds) my($maxrrdage) = 3600; # 1 hour -my($maxgraphage) = 3600; # 1 hour +my($maximgage) = 3600; # 1 hour + +# delete rrd's when they get cleaned up? +# if unset, will just ignore the rrd's +# - usually best to leave this off, we don't want to delete useful rrds :) +my($deleterrds) = 0; + +# delete graphs when they get cleaned up? +# if unset, won't bother checking at all +# - usually best to leave this on +my($deleteimgs) = 1; # Read the contents of the base directory # and pull out the list of subdirectories (except . and .. :) @@ -78,9 +88,11 @@ foreach my $machine (@rrddirlist) { $ctime,$blksize,$blocks) = stat("$rrddir/$machine/$rrd"); # check if it's old enough to be deleted if((time - $mtime) > $maxrrdage) { -print "pruning rrd $rrddir/$machine/$rrd\n"; - # if so, delete it - unlink("$rrddir/$machine/$rrd"); + # do we delete the rrd, or just ignore it? + if($deleterrds) { + # if so, delete it + unlink("$rrddir/$machine/$rrd"); + } # no more processing required for this rrd next; } @@ -180,53 +192,58 @@ print "pruning rrd $rrddir/$machine/$rrd\n"; } } # have a last check, maybe we can remove the directory now? - # Read the contents of the directory - opendir(DIR, "$rrddir/$machine"); - my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR); - closedir DIR; - if($#dirlist == -1) { -print "pruning rrddir $rrddir/$machine\n"; - rmdir "$rrddir/$machine"; + # (only if we're deleting stuff) + if($deleterrds) { + # Read the contents of the directory + opendir(DIR, "$rrddir/$machine"); + my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR); + closedir DIR; + if($#dirlist == -1) { + rmdir "$rrddir/$machine"; + } } } -# Read the contents of the graphs directory -# and pull out the list of subdirectories (except . and .. :) -opendir(DIR, $imgdir); -my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); -closedir DIR; - -# look through each directoty, as they might -# contain images for a particular machine -foreach my $machine (@imgdirlist) { - # Read the contents of the directory - opendir(DIR, "$imgdir/$machine"); - my(@imglist) = grep { /\.png$/ && -f "$imgdir/$machine/$_" } readdir(DIR); +if($deleteimgs) { + # Read the contents of the graphs directory + # and pull out the list of subdirectories (except . and .. :) + opendir(DIR, $imgdir); + my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); closedir DIR; - # See what rrd we have, and generate the graphs accordingly - foreach my $img (@imglist) { - chomp $img; - # stat the img - my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, - $ctime,$blksize,$blocks) = stat("$imgdir/$machine/$img"); - # check if it's old enough to be deleted - if((time - $mtime) > $maxgraphage) { -print "pruning img $imgdir/$machine/$img\n"; - # if so, delete it - unlink("$imgdir/$machine/$img"); + # look through each directoty, as they might + # contain images for a particular machine + foreach my $machine (@imgdirlist) { + # Read the contents of the directory + opendir(DIR, "$imgdir/$machine"); + my(@imglist) = grep { /\.png$/ && -f "$imgdir/$machine/$_" } readdir(DIR); + closedir DIR; + + # See what rrd we have, and generate the graphs accordingly + foreach my $img (@imglist) { + chomp $img; + # stat the img + my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, + $ctime,$blksize,$blocks) = stat("$imgdir/$machine/$img"); + # check if it's old enough to be deleted + if((time - $mtime) > $maximgage) { + # if so, delete it + unlink("$imgdir/$machine/$img"); + } } + # have a last check, maybe we can remove the directory now? + # Read the contents of the directory + opendir(DIR, "$imgdir/$machine"); + my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR); + closedir DIR; + if($#dirlist == -1) { + rmdir "$imgdir/$machine"; + } } - # have a last check, maybe we can remove the directory now? - # Read the contents of the directory - opendir(DIR, "$imgdir/$machine"); - my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR); - closedir DIR; - if($#dirlist == -1) { -print "pruning img dir $imgdir/$machine\n"; - rmdir "$imgdir/$machine"; - } } + +exit(0); + # # subroutine to make some graphs