ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/rrdgraphing/graph.pl
(Generate patch)

Comparing projects/cms/source/reports/rrdgraphing/graph.pl (file contents):
Revision 1.3 by tdb, Mon May 20 16:11:23 2002 UTC vs.
Revision 1.4 by tdb, Tue May 21 11:37:56 2002 UTC

# Line 54 | Line 54 | my($hex_underscore) = "_5f";
54   # maximum age (last modified) before an rrd or graph get cleaned up
55   # (in seconds)
56   my($maxrrdage) = 3600; # 1 hour
57 < my($maxgraphage) = 3600; # 1 hour
57 > my($maximgage) = 3600; # 1 hour
58 >
59 > # delete rrd's when they get cleaned up?
60 > # if unset, will just ignore the rrd's
61 > #  - usually best to leave this off, we don't want to delete useful rrds :)
62 > my($deleterrds) = 0;
63 >
64 > # delete graphs when they get cleaned up?
65 > # if unset, won't bother checking at all
66 > #  - usually best to leave this on
67 > my($deleteimgs) = 1;
68      
69   # Read the contents of the base directory
70   # and pull out the list of subdirectories (except . and .. :)
# Line 78 | Line 88 | foreach my $machine (@rrddirlist) {
88           $ctime,$blksize,$blocks) = stat("$rrddir/$machine/$rrd");
89          # check if it's old enough to be deleted
90          if((time - $mtime) > $maxrrdage) {
91 < print "pruning rrd $rrddir/$machine/$rrd\n";
92 <            # if so, delete it
93 <            unlink("$rrddir/$machine/$rrd");
91 >            # do we delete the rrd, or just ignore it?
92 >            if($deleterrds) {
93 >                # if so, delete it
94 >                unlink("$rrddir/$machine/$rrd");
95 >            }
96              # no more processing required for this rrd
97              next;
98          }
# Line 180 | Line 192 | print "pruning rrd $rrddir/$machine/$rrd\n";
192          }
193      }
194      # have a last check, maybe we can remove the directory now?
195 <    # Read the contents of the directory
196 <    opendir(DIR, "$rrddir/$machine");
197 <    my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR);
198 <    closedir DIR;
199 <    if($#dirlist == -1) {
200 < print "pruning rrddir $rrddir/$machine\n";
201 <        rmdir "$rrddir/$machine";
195 >    # (only if we're deleting stuff)
196 >    if($deleterrds) {
197 >        # Read the contents of the directory
198 >        opendir(DIR, "$rrddir/$machine");
199 >        my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR);
200 >        closedir DIR;
201 >        if($#dirlist == -1) {
202 >            rmdir "$rrddir/$machine";
203 >        }
204      }
205   }
206  
207 < # Read the contents of the graphs directory
208 < # and pull out the list of subdirectories (except . and .. :)
209 < opendir(DIR, $imgdir);
210 < my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR);
211 < closedir DIR;
198 <
199 < # look through each directoty, as they might
200 < # contain images for a particular machine
201 < foreach my $machine (@imgdirlist) {
202 <    # Read the contents of the directory
203 <    opendir(DIR, "$imgdir/$machine");
204 <    my(@imglist) = grep { /\.png$/ && -f "$imgdir/$machine/$_" } readdir(DIR);
207 > if($deleteimgs) {
208 >    # Read the contents of the graphs directory
209 >    # and pull out the list of subdirectories (except . and .. :)
210 >    opendir(DIR, $imgdir);
211 >    my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR);
212      closedir DIR;
213  
214 <    # See what rrd we have, and generate the graphs accordingly
215 <    foreach my $img (@imglist) {
216 <        chomp $img;
217 <        # stat the img
218 <        my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
219 <         $ctime,$blksize,$blocks) = stat("$imgdir/$machine/$img");
220 <        # check if it's old enough to be deleted
221 <        if((time - $mtime) > $maxgraphage) {
222 < print "pruning img $imgdir/$machine/$img\n";
223 <            # if so, delete it
224 <            unlink("$imgdir/$machine/$img");
214 >    # look through each directoty, as they might
215 >    # contain images for a particular machine
216 >    foreach my $machine (@imgdirlist) {
217 >        # Read the contents of the directory
218 >        opendir(DIR, "$imgdir/$machine");
219 >        my(@imglist) = grep { /\.png$/ && -f "$imgdir/$machine/$_" } readdir(DIR);
220 >        closedir DIR;
221 >
222 >        # See what rrd we have, and generate the graphs accordingly
223 >        foreach my $img (@imglist) {
224 >            chomp $img;
225 >            # stat the img
226 >            my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
227 >             $ctime,$blksize,$blocks) = stat("$imgdir/$machine/$img");
228 >            # check if it's old enough to be deleted
229 >            if((time - $mtime) > $maximgage) {
230 >                # if so, delete it
231 >                unlink("$imgdir/$machine/$img");
232 >            }
233          }
234 +        # have a last check, maybe we can remove the directory now?
235 +        # Read the contents of the directory
236 +        opendir(DIR, "$imgdir/$machine");
237 +        my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR);
238 +        closedir DIR;
239 +        if($#dirlist == -1) {
240 +            rmdir "$imgdir/$machine";
241 +        }
242      }
220    # have a last check, maybe we can remove the directory now?
221    # Read the contents of the directory
222    opendir(DIR, "$imgdir/$machine");
223    my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR);
224    closedir DIR;
225    if($#dirlist == -1) {
226 print "pruning img dir $imgdir/$machine\n";
227        rmdir "$imgdir/$machine";
228    }
243   }
244 +
245 + exit(0);
246 +
247  
248   #
249   # subroutine to make some graphs

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines