| 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($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 .. :) |
| 71 |
|
opendir(DIR, $rrddir); |
| 83 |
|
# See what rrd we have, and generate the graphs accordingly |
| 84 |
|
foreach my $rrd (@rrdlist) { |
| 85 |
|
chomp $rrd; |
| 86 |
+ |
# stat the file |
| 87 |
+ |
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, |
| 88 |
+ |
$ctime,$blksize,$blocks) = stat("$rrddir/$machine/$rrd"); |
| 89 |
+ |
# check if it's old enough to be deleted |
| 90 |
+ |
if((time - $mtime) > $maxrrdage) { |
| 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 |
+ |
} |
| 99 |
|
if($rrd =~ /^(cpu)\.rrd$/) { |
| 100 |
|
my(@data); |
| 101 |
|
my(@rawdata); |
| 191 |
|
&makegraph($machine, $baserrd, $comment, \@data, \@rawdata); |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
+ |
# have a last check, maybe we can remove the directory now? |
| 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 |
+ |
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 |
+ |
# 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 |
+ |
} |
| 243 |
+ |
} |
| 244 |
+ |
|
| 245 |
+ |
exit(0); |
| 246 |
+ |
|
| 247 |
|
|
| 248 |
|
# |
| 249 |
|
# subroutine to make some graphs |