| 1 |
|
#!/usr/bin/perl -w |
| 2 |
|
|
| 3 |
+ |
# |
| 4 |
+ |
# i-scream central monitoring system |
| 5 |
+ |
# Copyright (C) 2000-2002 i-scream |
| 6 |
+ |
# |
| 7 |
+ |
# This program is free software; you can redistribute it and/or |
| 8 |
+ |
# modify it under the terms of the GNU General Public License |
| 9 |
+ |
# as published by the Free Software Foundation; either version 2 |
| 10 |
+ |
# of the License, or (at your option) any later version. |
| 11 |
+ |
# |
| 12 |
+ |
# This program is distributed in the hope that it will be useful, |
| 13 |
+ |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
+ |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
+ |
# GNU General Public License for more details. |
| 16 |
+ |
# |
| 17 |
+ |
# You should have received a copy of the GNU General Public License |
| 18 |
+ |
# along with this program; if not, write to the Free Software |
| 19 |
+ |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 |
+ |
# |
| 21 |
+ |
|
| 22 |
|
# ----------------------------------------------------------- |
| 23 |
|
# i-scream graph generation script |
| 24 |
|
# http://www.i-scream.org.uk |
| 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 |
|
|