| 50 |
|
my($hex_slash) = "_2f"; |
| 51 |
|
# _ converted to a decimal then hex'd |
| 52 |
|
my($hex_underscore) = "_5f"; |
| 53 |
< |
|
| 53 |
> |
|
| 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 |
| 58 |
> |
|
| 59 |
|
# Read the contents of the base directory |
| 60 |
|
# and pull out the list of subdirectories (except . and .. :) |
| 61 |
|
opendir(DIR, $rrddir); |
| 73 |
|
# See what rrd we have, and generate the graphs accordingly |
| 74 |
|
foreach my $rrd (@rrdlist) { |
| 75 |
|
chomp $rrd; |
| 76 |
+ |
# stat the file |
| 77 |
+ |
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, |
| 78 |
+ |
$ctime,$blksize,$blocks) = stat("$rrddir/$machine/$rrd"); |
| 79 |
+ |
# check if it's old enough to be deleted |
| 80 |
+ |
if((time - $mtime) > $maxrrdage) { |
| 81 |
+ |
print "pruning rrd $rrddir/$machine/$rrd\n"; |
| 82 |
+ |
# if so, delete it |
| 83 |
+ |
unlink("$rrddir/$machine/$rrd"); |
| 84 |
+ |
# no more processing required for this rrd |
| 85 |
+ |
next; |
| 86 |
+ |
} |
| 87 |
|
if($rrd =~ /^(cpu)\.rrd$/) { |
| 88 |
|
my(@data); |
| 89 |
|
my(@rawdata); |
| 178 |
|
$comment = "unknown queue" if not defined $comment; |
| 179 |
|
&makegraph($machine, $baserrd, $comment, \@data, \@rawdata); |
| 180 |
|
} |
| 181 |
+ |
} |
| 182 |
+ |
# have a last check, maybe we can remove the directory now? |
| 183 |
+ |
# Read the contents of the directory |
| 184 |
+ |
opendir(DIR, "$rrddir/$machine"); |
| 185 |
+ |
my(@dirlist) = grep { !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
| 186 |
+ |
closedir DIR; |
| 187 |
+ |
if($#dirlist == -1) { |
| 188 |
+ |
print "pruning rrddir $rrddir/$machine\n"; |
| 189 |
+ |
rmdir "$rrddir/$machine"; |
| 190 |
+ |
} |
| 191 |
+ |
} |
| 192 |
+ |
|
| 193 |
+ |
# Read the contents of the graphs directory |
| 194 |
+ |
# and pull out the list of subdirectories (except . and .. :) |
| 195 |
+ |
opendir(DIR, $imgdir); |
| 196 |
+ |
my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
| 197 |
+ |
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); |
| 205 |
+ |
closedir DIR; |
| 206 |
+ |
|
| 207 |
+ |
# See what rrd we have, and generate the graphs accordingly |
| 208 |
+ |
foreach my $img (@imglist) { |
| 209 |
+ |
chomp $img; |
| 210 |
+ |
# stat the img |
| 211 |
+ |
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, |
| 212 |
+ |
$ctime,$blksize,$blocks) = stat("$imgdir/$machine/$img"); |
| 213 |
+ |
# check if it's old enough to be deleted |
| 214 |
+ |
if((time - $mtime) > $maxgraphage) { |
| 215 |
+ |
print "pruning img $imgdir/$machine/$img\n"; |
| 216 |
+ |
# if so, delete it |
| 217 |
+ |
unlink("$imgdir/$machine/$img"); |
| 218 |
+ |
} |
| 219 |
+ |
} |
| 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 |
|
} |
| 229 |
|
} |
| 230 |
|
|