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.1 by tdb, Mon Mar 18 13:24:31 2002 UTC vs.
Revision 1.4 by tdb, Tue May 21 11:37:56 2002 UTC

# Line 1 | Line 1
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
# Line 31 | Line 50 | my($rrddir) = "/u1/i-scream/databases";
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);
# Line 49 | Line 83 | foreach my $machine (@rrddirlist) {
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);
# Line 144 | Line 191 | foreach my $machine (@rrddirlist) {
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines