ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/reports/graphing/watch.pl
(Generate patch)

Comparing experimental/reports/graphing/watch.pl (file contents):
Revision 1.1 by tdb, Sat Mar 9 19:53:24 2002 UTC vs.
Revision 1.2 by tdb, Sun Mar 10 00:26:24 2002 UTC

# Line 1 | Line 1
1   #!/usr/bin/perl -w
2  
3 + # -----------------------------------------------------------
4 + # i-scream graph generation scripts
5 + # http://www.i-scream.org.uk
6 + #
7 + # Generates rrd databases for i-scream data by connecting to
8 + # the i-scream server and collecting data.
9 + #
10 + # $Author$
11 + # $Id$
12 + #------------------------------------------------------------
13 +
14   $| = 1;
15  
16   use strict;
# Line 7 | Line 18 | use iscream::XMLParser;
18   use IO::Socket;
19   use RRDs;
20  
21 + # Base directory for images
22 + # (a directory will be constructed for each host under this)
23 + my($imgdir) = "/home/tdb/public_html/rrd";
24 +
25 + # Location of RRD databases
26 + my($rrddir) = "/u1/i-scream/rrd";
27 +
28 + # for reference:
29 + # ch -> hex: $hex = sprintf("%02x", ord($ch));
30 + # hex -> ch: $ch = chr(hex($hex));
31 +
32 + # / converted to a decimal then hex'd
33 + my($hex_slash) = "_2f";
34 + # _ converted to a decimal then hex'd
35 + my($hex_underscore) = "_5f";
36 +
37   if (@ARGV != 2) {
38      die "Usage: ihost.pl [i-scream client interface] [TCP port]\n";
39   }
# Line 14 | Line 41 | if (@ARGV != 2) {
41   my($addr) = $ARGV[0];
42   my($cport) = $ARGV[1];
43  
17 #print `rm -f *.rrd *.png`;
18
44   my($csock) = new IO::Socket::INET(
45      PeerAddr => $addr,
46      PeerPort => $cport,
# Line 45 | Line 70 | if ($response && $response ne "OK\n") {
70      exit(1);
71   }
72  
48 #print $csock "SETHOSTLIST\n";
49 #$response = <$csock>;
50 #if ($response && $response ne "OK\n") {
51 #    print "Received odd response: $response\n";
52 #    close($csock);
53 #    exit(1);
54 #}
55
56 #print $csock "myrtle.ukc.ac.uk\n";
57 #$response = <$csock>;
58 #if ($response && $response ne "OK\n") {
59 #    print "Received odd response: $response\n";
60 #    close($csock);
61 #    exit(1);
62 #}
63
73   print $csock "STARTDATA\n";
74   $response = <$csock>;
75  
# Line 82 | Line 91 | if (!defined $dsock) {
91      exit(1);
92   }
93  
94 + ## below here has been "improved"
95 + ## above is still a mess ;)
96 +
97   while(1) {
98 +    # read data
99      $response = <$dsock>;
100 < #print "$response\n";
100 >    
101 >    # attemp to parse the data
102      my($err, %xmlhash) = &iscream::XMLParser::parse($response);
103      if($err) {
104 <        print "SKIPPED (bad xml): $response";
104 >        print STDERR "Skipped, XML did not parse: $response";
105 >        next;
106      }
107 <    ## -- mental note, think about ordering checks for optimal speed ;)
108 <    # take a look to see if we have a shutdown packet...
107 >    
108 >    # standard data packet
109      if($xmlhash{"packet.attributes.type"} eq "data") {
110          my($machine) = $xmlhash{"packet.attributes.machine_name"};
111          my($date) = $xmlhash{"packet.attributes.date"};
112 +        
113          # make directory for machine
114 <        if(! -d "$machine") {
114 >        if(! -d "$rrddir/$machine") {
115              # not sure on this umask, but it seems to work?
116 <            mkdir "$machine", 0777;
116 >            mkdir "$rrddir/$machine", 0777;
117          }
118 +        
119 +        my(@data);
120 +        
121          # cpu
122 <        my($cpu_idle) = $xmlhash{"packet.cpu.idle"};
123 <        my($cpu_user) = $xmlhash{"packet.cpu.user"};
124 <        my($cpu_kernel) = $xmlhash{"packet.cpu.kernel"};
125 <        my($cpu_swap) = $xmlhash{"packet.cpu.swap"};
126 <        my($cpu_iowait) = $xmlhash{"packet.cpu.iowait"};
127 <        if( ! -f "$machine/cpu.rrd") {
128 <            print "making new rrd for $machine\_cpu\n";
129 <            &makerrd_cpu($machine, $date);
111 <        }
112 <        #my($cmd) = "rrdtool update $machine\_cpu.rrd $date:$cpu_idle:$cpu_user:$cpu_kernel:$cpu_swap:$cpu_iowait";
113 <        RRDs::update ("$machine/cpu.rrd", "$date:$cpu_idle:$cpu_user:$cpu_kernel:$cpu_swap:$cpu_iowait");
114 <        #print "done $machine\n";
115 <        my($err_cpu) = RRDs::error;
116 <        die "Error_cpu: $err_cpu\n" if $err_cpu;
117 <        #print "$cmd\n";
118 <        #print `$cmd`;
122 >        @data = ( "packet.cpu.idle:idle:GAUGE",
123 >                  "packet.cpu.user:user:GAUGE",
124 >                  "packet.cpu.kernel:kernel:GAUGE",
125 >                  "packet.cpu.swap:swap:GAUGE",
126 >                  "packet.cpu.iowait:iowait:GAUGE",
127 >                 );
128 >        &updaterrd($machine, "cpu", $date, 15, \%xmlhash, @data);
129 >              
130          # mem
131 <        my($mem_free) = $xmlhash{"packet.memory.free"};
132 <        my($mem_total) = $xmlhash{"packet.memory.total"};
133 <        if( ! -f "$machine/mem.rrd") {
134 <            print "making new rrd for $machine\_mem\n";
135 <            &makerrd_mem($machine, $date);
125 <        }
126 <        RRDs::update ("$machine/mem.rrd", "$date:$mem_free:$mem_total");
127 <        my($err_mem) = RRDs::error;
128 <        die "Error_mem: $err_mem\n" if $err_mem;
131 >        @data = ( "packet.memory.free:free:GAUGE",
132 >                  "packet.memory.total:total:GAUGE",
133 >                 );
134 >        &updaterrd($machine, "mem", $date, 15, \%xmlhash, @data);
135 >                
136          # load
137 <        my($load_1) = $xmlhash{"packet.load.load1"};
138 <        my($load_5) = $xmlhash{"packet.load.load5"};
139 <        my($load_15) = $xmlhash{"packet.load.load15"};
140 <        if( ! -f "$machine/load.rrd") {
141 <            print "making new rrd for $machine\_load\n";
142 <            &makerrd_load($machine, $date);
136 <        }
137 <        RRDs::update ("$machine/load.rrd", "$date:$load_1:$load_5:$load_15");
138 <        my($err_load) = RRDs::error;
139 <        die "Error_load: $err_load\n" if $err_load;
137 >        @data = ( "packet.load.load1:load1:GAUGE",
138 >                  "packet.load.load5:load5:GAUGE",
139 >                  "packet.load.load15:load15:GAUGE",
140 >                 );
141 >        &updaterrd($machine, "load", $date, 15, \%xmlhash, @data);
142 >        
143          # processes
144 <        my($proc_cpu) = $xmlhash{"packet.processes.cpu"};
145 <        my($proc_sleeping) = $xmlhash{"packet.processes.sleeping"};  
146 <        my($proc_stopped) = $xmlhash{"packet.processes.stopped"};
147 <        my($proc_total) = $xmlhash{"packet.processes.total"};  
148 <        my($proc_zombie) = $xmlhash{"packet.processes.zombie"};
149 <        if( ! -f "$machine/proc.rrd") {
150 <            print "making new rrd for $machine\_proc\n";
151 <            &makerrd_proc($machine, $date);
149 <        }
150 <        RRDs::update ("$machine/proc.rrd", "$date:$proc_cpu:$proc_sleeping:$proc_stopped:$proc_total:$proc_zombie");
151 <        my($err_proc) = RRDs::error;
152 <        die "Error_proc: $err_proc\n" if $err_proc;
144 >        @data = ( "packet.processes.cpu:cpu:GAUGE",
145 >                  "packet.processes.sleeping:sleeping:GAUGE",
146 >                  "packet.processes.stopped:stopped:GAUGE",
147 >                  "packet.processes.total:total:GAUGE",
148 >                  "packet.processes.zombie:zombie:GAUGE",
149 >                 );
150 >        &updaterrd($machine, "proc", $date, 15, \%xmlhash, @data);
151 >        
152          # swap
153 <        my($swap_free) = $xmlhash{"packet.swap.free"};
154 <        my($swap_total) = $xmlhash{"packet.swap.total"};
155 <        if( ! -f "$machine/swap.rrd") {
156 <            print "making new rrd for $machine\_swap\n";
157 <            &makerrd_swap($machine, $date);
159 <        }
160 <        RRDs::update ("$machine/swap.rrd", "$date:$swap_free:$swap_total");
161 <        my($err_swap) = RRDs::error;
162 <        die "Error_swap: $err_swap\n" if $err_swap;
153 >        @data = ( "packet.swap.free:free:GAUGE",
154 >                  "packet.swap.total:total:GAUGE",
155 >                 );
156 >        &updaterrd($machine, "swap", $date, 15, \%xmlhash, @data);
157 >        
158          # users
159 <        my($users_count) = $xmlhash{"packet.users.count"};
160 <        if( ! -f "$machine/users.rrd") {
161 <            print "making new rrd for $machine\_users\n";
162 <            &makerrd_users($machine, $date);
168 <        }
169 <        RRDs::update ("$machine/users.rrd", "$date:$users_count");
170 <        my($err_users) = RRDs::error;
171 <        die "Error_users: $err_users\n" if $err_users;
159 >        @data = ( "packet.users.count:count:GAUGE",
160 >                 );
161 >        &updaterrd($machine, "users", $date, 15, \%xmlhash, @data);
162 >        
163          # disk
173        # some definitions
174        # ch -> hex: $hex = sprintf("%02x", ord($ch));
175        # hex -> ch: $ch = chr(hex($hex));
176        # / converted to a decimal then hex'd
177        my($hex_slash) = "_2f";
178        # _ converted to a decimal then hex'd
179        my($hex_underscore) = "_5f";
164          my($i) = 0;
165          while(defined $xmlhash{"packet.disk.p$i.attributes.mount"}) {
182            #my($name) = $xmlhash{"packet.disk.p$i.attributes.name"};
166              my($mount) = $xmlhash{"packet.disk.p$i.attributes.mount"};
167 <            #print "$response\n";
168 <            #print "$i: $machine $name\n";
169 <            #$mount =~ s/-/--/g;
170 <            my($encmount) = $mount;
171 <            $encmount =~ s/_/$hex_underscore/g;
172 <            $encmount =~ s/\//$hex_slash/g;
190 <            if( ! -f "$machine/disk-$encmount.rrd" ) {
191 <                print "making new database for $machine\_disk-$encmount\n";
192 <                &makerrd_disk($machine, $date, $encmount);
193 <            }
194 <            #my($avail) = $xmlhash{"packet.disk.p$i.attributes.avail"};
195 <            my($kbytes) = $xmlhash{"packet.disk.p$i.attributes.kbytes"};
196 <            my($used) = $xmlhash{"packet.disk.p$i.attributes.used"};
197 <            #print "$machine\_disk-$name.rrd $date:$kbytes:$used\n";
198 <            RRDs::update ("$machine/disk-$encmount.rrd", "$date:$kbytes:$used");
199 <            my($err_disk) = RRDs::error;
200 <            die "Error_disk: $err_disk\n" if $err_disk;
167 >            $mount =~ s/_/$hex_underscore/g;
168 >            $mount =~ s/\//$hex_slash/g;
169 >            @data = ( "packet.disk.p$i.attributes.kbytes:kbytes:GAUGE",
170 >                      "packet.disk.p$i.attributes.used:used:GAUGE",
171 >                     );
172 >            &updaterrd($machine, "disk-$mount", $date, 15, \%xmlhash, @data);
173              ++$i;
174          }
203
175      }
176 +    
177 +    # queue statistics packet
178      elsif($xmlhash{"packet.attributes.type"} eq "queueStat") {
179 +        # psuedo machine for internal server stuff
180 +        my($machine) = "i-scream-server";
181          # make directory
182 <        if(! -d "i-scream-server") {
182 >        if(! -d "$rrddir/$machine") {
183              # not sure on this umask, but it seems to work?
184 <            mkdir "i-scream-server", 0777;
184 >            mkdir "$rrddir/$machine", 0777;
185          }
186 +        my($hash) = $xmlhash{"packet.attributes.hashCode"};
187 +        my($date) = $xmlhash{"packet.attributes.date"};
188 +        my($name) = $xmlhash{"packet.attributes.name"};
189          # take a look to see if we have a shutdown packet...
190          if($xmlhash{"packet.attributes.shutdown"} && $xmlhash{"packet.attributes.shutdown"} eq "true") {
191 <            my($hash) = $xmlhash{"packet.attributes.hashCode"};
214 <            my($cmd) = "rm -f i-scream-server/$hash\_*.rrd /home/tdb/public_html/rrd/i-scream-server/$hash*.png i-scream-server/$hash.def";
215 <            print `$cmd`;
216 <            print "$cmd\n";
191 >            unlink <$rrddir/$machine/$hash\_*.rrd>, "$rrddir/$machine/$hash.def", <$imgdir/$machine/$hash*.png>;
192              next;
193          }
194 <        my($hash) = $xmlhash{"packet.attributes.hashCode"};
220 <        my($date) = $xmlhash{"packet.attributes.date"};
221 <        my($name) = $xmlhash{"packet.attributes.name"};
222 <        my($total) = $xmlhash{"packet.queue.attributes.total"};
194 >        # look through to see how many internal queues we have
195          my($i) = 0;
196          while(defined $xmlhash{"packet.queue.attributes.queue$i"}) {
225            if( ! -f "i-scream-server/$hash\_$i.rrd" ) {
226                print "making new database for $hash\_$i\n";
227                &makerrd_queue($hash, $i, $date, $name);
228            }
229            my($size) = $xmlhash{"packet.queue.attributes.queue$i"};
230            my($cmd);
197              # see if the queue has been removed
198 <            if($size eq "[deleted]") {
199 <                $cmd = "rm -f i-scream-server/$hash\_$i.rrd";
200 <                # are there any other rrd's left? if not, cleanup!
201 <                my($rrdcount) = `ls i-scream-server | grep $hash\_\\*.rrd | wc -l`;
198 >            if($xmlhash{"packet.queue.attributes.queue$i"} eq "[deleted]") {
199 >                # delete the queues rrd
200 >                unlink "$rrddir/$machine/$hash\_$i.rrd";
201 >                # are there any other rrd's left on this queue? if not, cleanup.
202 >                # get a list of any that may be still there..
203 >                opendir(DIR, "$rrddir/$machine");
204 >                my(@rrdcountfiles) = grep { -f "$rrddir/$machine/$_" && /^$hash\_\d+.rrd$/ } readdir(DIR);
205 >                closedir DIR;
206 >                # count them (+1 because an empty array is size -1)
207 >                my($rrdcount) = $#rrdcountfiles + 1;
208                  if($rrdcount == 0) {
209 <                    $cmd = $cmd . " && rm -f i-scream-server/$hash.def /home/tdb/public_html/rrd/i-scream-server/$hash*.png";
209 >                    # clean up the def file and any images
210 >                    unlink "$rrddir/$machine/$hash.def", <$imgdir/$machine/$hash*.png>;
211                  }
212 <                print `$cmd`;
212 >                ++$i;
213 >                next;
214              }
215 <            else {
216 <                RRDs::update ("i-scream-server/$hash\_$i.rrd", "$date:$size:$total");
217 <                my($err_disk) = RRDs::error;
218 <                die "Error_disk: $err_disk\n" if $err_disk;
215 >            # the &updaterrd will also do this check, but we want
216 >            # to write our def file out first
217 >            if( ! -f "$rrddir/$machine/$hash\_$i.rrd" ) {
218 >                open(DEF, ">$rrddir/$machine/$hash.def");
219 >                print DEF $name;
220 >                close DEF;
221              }
222 +            my(@data) = ( "packet.queue.attributes.queue$i:size:GAUGE",
223 +                          "packet.queue.attributes.total:total:GAUGE",
224 +                         );
225 +            &updaterrd($machine, "$hash\_$i", $date, 15, \%xmlhash, @data);
226              ++$i;
227          }
228      }
229      else {
230 <        #print "SKIPPED: valid xml, but not a data packet\n";
230 >        #print "SKIPPED: valid xml, but not a data or statistics packet\n";
231      }
232   }
233  
234 + # we'll never reach here... unless 1 becomes false for some reason ;)
235   exit 0;
236  
256 sub makerrd_cpu() {
257    my($machine, $start) = @_;
258    $start = $start - 15;
259    my($init) = "rrdtool create $machine/cpu.rrd --start $start --step 15";
260    my($ds1) = "DS:idle:GAUGE:600:U:U DS:user:GAUGE:600:U:U";
261    my($ds2) = "DS:kernel:GAUGE:600:U:U DS:swap:GAUGE:600:U:U DS:iowait:GAUGE:600:U:U";
262    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
263    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
264    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
265    my($cmd) = "$init $ds1 $ds2 $rra1 $rra2";
266    print `$cmd`;
267    print "$cmd\n";
268    print `chmod 600 $machine/cpu.rrd`;
269 }
237  
238 < sub makerrd_mem() {
239 <    my($machine, $start) = @_;
240 <    $start = $start - 15;
241 <    my($init) = "rrdtool create $machine/mem.rrd --start $start --step 15";
242 <    my($ds) = "DS:free:GAUGE:600:U:U DS:total:GAUGE:600:U:U";
243 <    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
244 <    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
245 <    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
246 <    my($cmd) = "$init $ds $rra1 $rra2";
247 <    print `$cmd`;
248 <    print "$cmd\n";
249 <    print `chmod 600 $machine/mem.rrd`;
238 > #
239 > # sub to update an rrd file
240 > #
241 > # $machine   = name of the machine
242 > #              (eg. kernow.ukc.ac.uk)
243 > # $type      = the type of graph for the machine
244 > #              (eg. cpu)
245 > # $date      = the date of the item we want to add
246 > #              (in seconds since the epoch)
247 > # $step      = the interval at which the database steps
248 > #              used when we create a new rrd
249 > # $xmlref    = reference to the xml data packet
250 > # @data      = array containing data items to add
251 > #              (eg. "packet.cpu.user:user:GAUGE")
252 > #
253 > sub updaterrd() {
254 >    my($machine, $type, $date, $step, $xmlref, @data) = @_;
255 >    # get hold of the xmlhash we have a reference to
256 >    my(%xmlhash) = %$xmlref;
257 >    # check if we need to create a new rrd
258 >    if( ! -f "$rrddir/$machine/$type.rrd") {
259 >        my(@createdata);
260 >        # pull the details out of the data we've been given
261 >        foreach my $dataitem (@data) {
262 >            if($dataitem =~ /^\S+:(\S+):(\S+)$/) {
263 >                push @createdata, "$1:$2";
264 >            }
265 >        }
266 >        # call the &makerrd to actually create the rrd
267 >        print "making new rrd for $rrddir/$machine/$type.rrd\n";
268 >        &makerrd($machine, $type, $date, $step, @createdata);
269 >    }
270 >    # get the details out of the data we've been given
271 >    my($updateparams) = "$date";
272 >    foreach my $dataitem (@data) {
273 >        if($dataitem =~ /^(\S+):\S+:\S+$/) {
274 >            # pull the values straight out of the xmlhash
275 >            $updateparams .= ":$xmlhash{$1}";
276 >        }
277 >    }
278 >    # perform the update
279 >    RRDs::update ("$rrddir/$machine/$type.rrd", $updateparams);
280 >    my($err) = RRDs::error;
281 >    print STDERR "Error updating $rrddir/$machine/$type.rrd: $err\n" if $err;
282   }
284            
285 sub makerrd_load() {
286    my($machine, $start) = @_;
287    $start = $start - 15;
288    my($init) = "rrdtool create $machine/load.rrd --start $start --step 15";
289    my($ds) = "DS:load1:GAUGE:600:U:U DS:load5:GAUGE:600:U:U DS:load15:GAUGE:600:U:U";
290    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
291    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
292    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
293    my($cmd) = "$init $ds $rra1 $rra2";
294    print `$cmd`;
295    print "$cmd\n";
296    print `chmod 600 $machine/load.rrd`;
297 }
283  
284 < sub makerrd_proc() {
285 <    my($machine, $start) = @_;
286 <    $start = $start - 15;
287 <    my($init) = "rrdtool create $machine/proc.rrd --start $start --step 15";
288 <    my($ds1) = "DS:cpu:GAUGE:600:U:U DS:sleeping:GAUGE:600:U:U";
289 <    my($ds2) = "DS:stopped:GAUGE:600:U:U DS:total:GAUGE:600:U:U DS:zombie:GAUGE:600:U:U";
290 <    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
291 <    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
292 <    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
293 <    my($cmd) = "$init $ds1 $ds2 $rra1 $rra2";
294 <    print `$cmd`;
295 <    print "$cmd\n";
296 <    print `chmod 600 $machine/proc.rrd`;
297 < }
298 <
299 < sub makerrd_swap() {
300 <    my($machine, $start) = @_;
301 <    $start = $start - 15;
302 <    my($init) = "rrdtool create $machine/swap.rrd --start $start --step 15";
303 <    my($ds) = "DS:free:GAUGE:600:U:U DS:total:GAUGE:600:U:U";  
304 <    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
305 <    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
306 <    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
307 <    my($cmd) = "$init $ds $rra1 $rra2";
308 <    print `$cmd`;
309 <    print "$cmd\n";
310 <    print `chmod 600 $machine/swap.rrd`;
311 < }
312 <    
313 < sub makerrd_users() {
314 <    my($machine, $start) = @_;
315 <    $start = $start - 15;
316 <    my($init) = "rrdtool create $machine/users.rrd --start $start --step 15";
317 <    my($ds) = "DS:count:GAUGE:600:U:U";
318 <    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
319 <    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
320 <    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
321 <    my($cmd) = "$init $ds $rra1 $rra2";
322 <    print `$cmd`;
323 <    print "$cmd\n";
324 <    print `chmod 600 $machine/users.rrd`;
325 < }
326 <
327 < sub makerrd_disk() {
328 <    my($machine, $start, $mount) = @_;
329 <    $start = $start - 15;
330 <    my($init) = "rrdtool create $machine/disk-$mount.rrd --start $start --step 15";
331 <    my($ds) = "DS:kbytes:GAUGE:600:U:U DS:used:GAUGE:600:U:U";
332 <    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
333 <    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
334 <    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
335 <    my($cmd) = "$init $ds $rra1 $rra2";
351 <    print `$cmd`;
352 <    print "$cmd\n";
353 <    print `chmod 600 $machine/disk-$mount.rrd`;
354 < }
355 <
356 < sub makerrd_queue() {
357 <    my($name, $queuenum, $start, $comment) = @_;
358 <    $start = $start - 15;
359 <    my($init) = "rrdtool create i-scream-server/$name\_$queuenum.rrd --start $start --step 15";
360 <    my($ds) = "DS:size:GAUGE:600:U:U DS:total:COUNTER:600:U:U";
361 <    #            3h in 15s samples     1d in 2m samples      1w in 15m samples      1m in 1hr samples
362 <    my($rra1) = "RRA:AVERAGE:0.5:1:720 RRA:AVERAGE:0.5:8:720 RRA:AVERAGE:0.5:60:672 RRA:AVERAGE:0.5:240:744";
363 <    my($rra2) = "RRA:MAX:0.5:1:720 RRA:MAX:0.5:8:720 RRA:MAX:0.5:60:672 RRA:MAX:0.5:60:744";
364 <    my($cmd) = "$init $ds $rra1 $rra2";
365 <    print `$cmd`;
366 <    print "$cmd\n";
367 <    print `echo "$comment" > i-scream-server/$name.def`;
368 <    print `chmod 600 i-scream-server/$name\_$queuenum.rrd i-scream-server/$name.def`;
369 < }
284 > #
285 > # sub to create a new rrd file
286 > #
287 > # $machine = name of the machine
288 > #            (eg. kernow.ukc.ac.uk)
289 > # $type    = the type of graph for the machine
290 > #            (eg. cpu)
291 > # $start   = the date of the first item we want to add
292 > #            (in seconds since the epoch)
293 > # $step    = the interval at which the database steps
294 > # @data    = the data items we want to put in the rrd
295 > #            in the form: $dsname:dstype
296 > #            (eg. "size:GAUGE")
297 > #
298 > sub makerrd() {
299 >    my($machine, $type, $start, $step, @data) = @_;
300 >    # check if directory exists for rrd
301 >    if(! -d "$rrddir/$machine") {
302 >        # not sure on this umask, but it seems to work?
303 >        mkdir "$rrddir/$machine", 0777;
304 >    }
305 >    my(@rrdcmd);
306 >    # we'll want to add our first data item at $start,
307 >    # so we start our rrd $step before that.
308 >    $start -= $step;
309 >    push @rrdcmd, "$rrddir/$machine/$type.rrd";
310 >    push @rrdcmd, "--start=$start";
311 >    push @rrdcmd, "--step=$step";
312 >    foreach my $dataitem (@data) {
313 >        # dataitem should be: "dsname:dstype"
314 >        if($dataitem =~ /^(\S+):(\S+)$/) {
315 >            push @rrdcmd, "DS:$1:$2:600:U:U";
316 >        }
317 >    }
318 >    push @rrdcmd, (
319 >        # 3h in 15s samples
320 >        "RRA:AVERAGE:0.5:1:720",
321 >        "RRA:MAX:0.5:1:720",
322 >        # 1d in 2m samples
323 >        "RRA:AVERAGE:0.5:8:720",
324 >        "RRA:MAX:0.5:8:720",
325 >        # 1w in 15m samples
326 >        "RRA:AVERAGE:0.5:60:672",
327 >        "RRA:MAX:0.5:60:672",
328 >        # 1m in 1hr samples
329 >        "RRA:AVERAGE:0.5:240:744",
330 >        "RRA:MAX:0.5:60:744",
331 >    );
332 >    RRDs::create (@rrdcmd);
333 >    my($err) = RRDs::error;
334 >    print STDERR "Error creating rrd for $rrddir/$machine/$type: $err\n" if $err;
335 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines