--- /dev/null
+# Register routine with plugin registery
+$DATAFUNCS{'rrd_disks'} = \&data_rrd_disks;
+
+use Data::Dumper;
+
+# Take the disk status messages and create rrd databases for each of
+# mount point. Skipping the @DFIGNORE mount points.
+
+# RRA to be created for each RRD
+# "daily" 5min avg last 48hr
+# "weekly" 30min avg last 12days
+# "monthly 2hr avg last 48days
+# "yearly" 24hr avg last 576days
+$RRAS = "RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:576 RRA:AVERAGE:0.5:24:576 " .
+ "RRA:AVERAGE:0.5:288:576";
+
+$RRDTOOL = "/usr/local/rrdtool/bin/rrdtool";
+$RRDDIR = "/usr/local/spong/www/rrd";
+
+sub data_rrd_disks {
+ my( $host, $service, $color, $start, $time, $sum, $message ) = @_;
+
+ if ($service ne 'disk' ) { return; }
+
+ my( $line, $rawfs, $used, $pct, $name, %namemap, $target );
+
+ &main::save_data('>', "$RRDDIR/$host/disk-name-map", "");
+
+ foreach $line ( split(/\n/,$message) ) {
+ if ( $line =~ m!^(\S+)\s.*\s(\d+)\s+\d+\s+(\d+)%\s+[^/]*(/.*)$! ) {
+ ( $rawfs, $used, $pct, $name ) = ( $1, $2, $3, $4 );
+
+ foreach my $check (@main::DFIGNORE) { # FS's to skip
+ next if $rawfs =~ /$check/;
+ next if $name =~ /$check/;
+ }
+
+ # Reformat the mount point
+ if ( $name eq "/" ) {
+ $target = "root";
+ } else {
+ $target = substr($name,1); # strip of leading '/'
+ $cnt = $target =~ tr!/!-!; # Convert '/' to '-' and count 'em
+ # If path if too long, just use the basename of mount pont
+ if ($cnt > 1) {
+ $target = basename($name);
+ }
+ }
+
+ # If .rrd file not found, built it
+ if ( ! -f "$RRDDIR/$host/disk-$target.rrd" ) {
+ &debug("$RRDDIR/$host/disk-$target.rrd not found creating it");
+ { local $SIG{'PIPE'} = 'IGNORE';
+ local $SIG{'CHLD'} = 'IGNORE';
+
+ eval {
+ system "$RRDTOOL create $RRDDIR/$host/disk-$target.rrd " .
+ "DS:pct:GAUGE:600:0:100 DS:used:GAUGE:600:0:U $RRAS";
+ };
+ }
+ if (@?) { &error("Error: rrdtool create: $@"); }
+ }
+
+ # Update the .rrd file
+ &debug("Updating $host $name rrd file");
+ { local $SIG{'PIPE'} = 'IGNORE';
+ local $SIG{'CHLD'} = 'IGNORE';
+
+ system "$RRDTOOL update $RRDDIR/$host/disk-$target.rrd " .
+ "$time:$pct:$used";
+ if ($@) { &error("Error: rrdtool update: $@"); }
+ }
+
+ $namemap{$target} = $name;
+ }
+
+ }
+
+print Data::Dumper->Dump([\%namemap],['$namemap']);
+ $line = "";
+ while(($k,$v) = (each %namemap)) {
+print "\$k = $k, \$v = $v\n";
+ $line .= "$k:$v\n";
+ }
+
+ # Write the file name to mount map to
+ &main::save_data('>', "$RRDDIR/$host/disk-name-map", $line );
+
+}
+
+# I'm include perl code, I need this line.
+1;
+
--- /dev/null
+# Register routine with plugin registery
+$DATAFUNCS{'rrd_la'} = \&data_rrd_la;
+
+# Take the cpu status message and create rrd databases for load averages
+# and number of users
+
+# RRA to be created for each RRD
+# "daily" 5min avg last 48hr
+# "weekly" 30min avg last 12days
+# "monthly 2hr avg last 48days
+# "yearly" 24hr avg last 576days
+$RRAS = "RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:576 RRA:AVERAGE:0.5:24:576 " .
+ "RRA:AVERAGE:0.5:288:576";
+
+$RRDTOOL = "/usr/local/rrdtool/bin/rrdtool";
+$RRDDIR = "/usr/local/spong/www/rrd";
+
+sub data_rrd_la {
+ my( $host, $service, $color, $start, $time, $sum, $message ) = @_;
+
+ if ($service ne 'cpu' ) { return; }
+
+ my( $line, $rawfs, $used, $pct, $name, %namemap, $target );
+
+ &main::save_data('>', "$RRDDIR/$host/name-map", "");
+
+ if ( $sum =~ m/load\s+=\s+([^, ]),\s+([\d]+)\s+users,\s+(\d+)/ ) {
+ ( $load, $users, $jobs ) = ( $1, $2, $3 );
+
+ # If .rrd file not found, built it
+ if ( ! -f "$RRDDIR/$host/la.rrd" ) {
+ &debug("$RRDDIR/$host/la.rrd not found creating it");
+ { local $SIG{'PIPE'} = 'IGNORE';
+ local $SIG{'CHLD'} = 'IGNORE';
+
+ eval {
+ system "$RRDTOOL create $RRDDIR/$host/la.rrd " .
+ "DS:loadavg:GAUGE:600:0:100 DS:users:GAUGE:600:0:U " .
+ "DS:GAUGE:600:0:U $RRAS";
+ };
+ }
+ if (@?) { &error("Error: rrdtool create: $@"); }
+ }
+
+ # Update the .rrd file
+ &debug("Updating $host $name rrd file");
+ { local $SIG{'PIPE'} = 'IGNORE';
+ local $SIG{'CHLD'} = 'IGNORE';
+
+ system "$RRDTOOL update $RRDDIR/$host/la.rrd " .
+ "$time:$load:$users:$jobs";
+ if ($@) { &error("Error: rrdtool update: $@"); }
+ }
+ }
+}
+
+# I'm include perl code, I need this line.
+1;
+