Index: /trunk/tools/czarplot.pl
===================================================================
--- /trunk/tools/czarplot.pl	(revision 28844)
+++ /trunk/tools/czarplot.pl	(revision 28845)
@@ -21,4 +21,5 @@
 my $histogram = undef;
 my $timeSeries = undef;
+my $nebulous = undef;
 my $savingToFile = undef;
 
@@ -32,4 +33,5 @@
         "output|o=s" => \$path,
         "histogram|h" => \$histogram,
+        "nebulous|n" => \$nebulous,
         "timeseries|t" => \$timeSeries,
         "verbose|v" => \$verbose,
@@ -41,4 +43,6 @@
 if (!$timeSeries) {
     print "* OPTIONAL: plot timeseries                 -t                          (default=on)\n";} 
+if (!$nebulous) {
+    print "* OPTIONAL: plot nebulous disk space        -n                          (default=off)\n";} 
 if (!$label) {
     print "* OPTIONAL: choose a label                  -l <labellName>             (default='all_labels')\n";}
@@ -58,5 +62,5 @@
 # default values
 if (!$label) {$label = "all_labels";}
-if (!$histogram && !$timeSeries) {$timeSeries = 1; $histogram = 1;}
+if (!$nebulous && !$histogram && !$timeSeries) {$timeSeries = 1; $histogram = 0;}
 if (!$verbose) {$verbose = 0;}
 if (!$save_temps) {$save_temps = 0;}
@@ -78,5 +82,9 @@
 }
 
+my $diskUsage = 1; # TODO
+
 if ($timeSeries) {$czarplot->createTimeSeries($label, $stage, $begin, $end);}
 if ($histogram) {$czarplot->createHistogram($label, $begin, $end);}
+if ($nebulous) {$czarplot->plotDiskUsageHistogram();}
+if ($nebulous) {$czarplot->plotStorageTimeSeries($begin, $end);}
 
Index: /trunk/tools/czartool/Czarplot.pm
===================================================================
--- /trunk/tools/czartool/Czarplot.pm	(revision 28844)
+++ /trunk/tools/czartool/Czarplot.pm	(revision 28845)
@@ -154,10 +154,49 @@
     my ($self, $minY, $maxY) = @_;
 
-    ${$maxY} = ${$maxY} + (${$maxY}/10);
-    ${$minY} = ${$minY} - (${$minY}/10);
+    my $border = (${$maxY} - ${$minY})/10;
+
+    ${$maxY} += $border;
+    ${$minY} -= $border ;
     if (${$maxY} == 0) {${$maxY} = 1;}
     if (${$minY} == 0) {${$minY} = -1;}
 }
 
+
+###########################################################################
+#
+# Figures out suitable spacing for time tics on time-series pliots
+#
+###########################################################################
+sub getTimeSpacing {
+    my ($self, $timeDiff, $divX, $timeFormat) = @_;
+
+    # if less than a couple of hour's data plotted, show 30 mins tics
+    if ($timeDiff < 7200) {
+        ${$timeFormat} = "%H:%M";
+        ${$divX} = 1800;
+    }
+    # if less than half a day's data plotted, show hourly tics
+    elsif ($timeDiff < 43200) {
+        ${$timeFormat} = "%H:%M";
+        ${$divX} = 3600;
+    }
+    # if less than one day's data plotted, show 2 hourly tics
+    elsif ($timeDiff < 86400) {
+        ${$timeFormat} = "%H:%M";
+        ${$divX} = 7200;
+    }
+    # if less than 1 week's data is data plotted, show daily tics
+    elsif ($timeDiff < 604800) {
+
+        ${$timeFormat} = "%m/%d";
+        ${$divX} = 86400;
+    }
+    else {
+
+        ${$timeFormat} = "%m/%d";
+        ${$divX} = 172800;
+    }
+}
+
 ###########################################################################
 #
@@ -171,34 +210,7 @@
 
     my $timeFormat = undef;
-
-    my $divX = $timeDiff/4;
-
-    # if less than a couple of hour's data plotted, show 30 mins tics
-    if ($timeDiff < 7200) {
-        $timeFormat = "%H:%M";
-        $divX = 1800;
-    }
-    # if less than half a day's data plotted, show hourly tics
-    elsif ($timeDiff < 43200) {
-        $timeFormat = "%H:%M";
-        $divX = 3600;
-    }
-    # if less than one day's data plotted, show 2 hourly tics
-    elsif ($timeDiff < 86400) {
-        $timeFormat = "%H:%M";
-        $divX = 7200;
-    }
-    # if less than 1 week's data is data plotted, show daily tics
-    elsif ($timeDiff < 604800) {
-        
-        $timeFormat = "%m/%d";
-        $divX = 86400;
-    }
-    else {
-
-        $timeFormat = "%m/%d";
-        $divX = 172800;
-    }
-
+    my $divX = undef;
+
+    $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat);
 
     my $numOfPlots = keys %$gnuplotFiles;
@@ -237,7 +249,7 @@
         if ($numOfPlots == 1) {
 
-            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"processed\" with lines lt 2,";
-            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:2 title \"pending\" with lines lt 3,";
-            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:3 title \"faults\" with lines lt 1";
+            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"Processed\" with lines lt 2,";
+            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:2 title \"Pending\" with lines lt 4,";
+            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:3 title \"Faults\" with lines lt 7";
         }
         # when plotting multiple stages, show only processed
@@ -249,4 +261,50 @@
 
     print GP "\n";
+    close GP;
+}
+
+###########################################################################
+#
+# Plots a time-series of cluster storage
+#
+###########################################################################
+sub plotStorageTimeSeries {
+    my ($self, $fromTime, $toTime) = @_;
+
+    my $outputFile = "/tmp/czarplot_cluster.png";
+    my ($minX, $maxX, $minY, $maxY, $timeDiff);
+
+    my $gnuplotFile = $self->{_czarDb}->createStorageTimeSeriesData($fromTime, $toTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
+
+    $self->sortOutMaxMinY(\$minY, \$maxY);
+
+    my $timeFormat = undef;
+    my $divX = undef;
+
+    $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat);
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        "set term $self->{_outputFormat};" .
+        "set output \"$outputFile\";" .
+        "set title \"hmjhhjhj\";" .
+        "set key left top;" .
+        "set xdata time;" .
+        "set timefmt \"$self->{_dateFormat}\";" .
+        "set xrange [\"$minX\":\"$maxX\"];" .
+        "set yrange [\"$minY\":\"$maxY\"];" .
+        "set format x \"$timeFormat\";" .
+        "set xtics \"$minX\", $divX, \"$maxX\";" .
+        "set grid xtics;" .
+        "set xlabel \"Time\";" .
+        "set ylabel \"Available (TB)\";" .
+        "plot " . 
+#        "'$gnuplotFile' using 1:2 title \"Total\" with lines lt 1," .
+        "'$gnuplotFile' using 1:2 title \"Available\" with lines lt 2\n";
+
+        print GP "\n";
     close GP;
 }
@@ -275,8 +333,40 @@
         "set bmargin 5;" .
         "set ylabel \"Exposures\";" .
-        "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 3, '' using 4 title \"Faults\" lt 1\n";
+        "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 4, '' using 4 title \"Faults\" lt 7;" . 
+        "\n";
 
     close GP;
 }
 
+###########################################################################
+#
+# Plots disk usage across cluster as a stacked histogram
+#
+###########################################################################
+sub plotDiskUsageHistogram {
+    my ($self) = @_;
+
+    my $outputFile = "/tmp/czarplot_hosts.png";
+
+    my $inputFile = $self->{_czarDb}->createHostsData();
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        "set term $self->{_outputFormat};" .
+        "set output \"$outputFile\";" .
+        "set title \"Nebulous disk use across IPP cluster\";" .
+        "set style fill solid 1.00 border -1;" .
+        "set style histogram rowstacked;" .
+        "set style data histograms;" .
+        "set ylabel \"Space (TB)\";" .
+        "set xtic rotate by -90 scale 0;" .
+        "plot '$inputFile' using 2:xtic(1) t \"Used\" , '' using 3 t \"Available\";" .
+
+        "\n";
+
+    close GP;
+}
 1;
Index: /trunk/tools/czartool/Nebulous.pm
===================================================================
--- /trunk/tools/czartool/Nebulous.pm	(revision 28845)
+++ /trunk/tools/czartool/Nebulous.pm	(revision 28845)
@@ -0,0 +1,127 @@
+#!/usr/bin/perl -w
+
+use warnings;
+use strict;
+
+package czartool::Nebulous;
+
+###########################################################################
+#
+# Constructor TODO put in check that we can run nebulous
+#
+###########################################################################
+sub new {
+    my $class = shift;
+    my $self = {_czarDb => shift};
+
+    $self->{_totalAvail} = undef;
+    $self->{_totalUsed} = undef;
+    $self->{_totalUsedAsPercent} = undef;
+    $self->{_totalCluster} = undef;
+    $self->{_totalHosts} = undef;
+    $self->{_hostsOverNinetyEightPC} = undef;
+
+    bless $self, $class;
+    return $self;
+}
+
+###########################################################################
+#
+# Converts Kb to Tb 
+# 
+###########################################################################
+sub convertKbToTb {
+    my ($self, $Kb) = @_;
+
+    return $Kb/1073741824;
+}
+
+###########################################################################
+#
+# Returns total cluster usage as percentage
+#
+###########################################################################
+sub getTotalUsedAsPercentage {
+    my ($self) = @_;
+
+    return $self->{_totalUsedAsPercent};
+}
+
+###########################################################################
+#
+# Returns total cluster usage in T 
+#
+###########################################################################
+sub getTotalUsedInTb {
+    my ($self) = @_;
+
+    return $self->convertKbToTb($self->{_totalUsed});
+}
+
+###########################################################################
+#
+# Returns total cluster space in T 
+#
+###########################################################################
+sub getTotalClusterInTb {
+    my ($self) = @_;
+
+    return $self->convertKbToTb($self->{_totalCluster});
+}
+
+###########################################################################
+#
+# Returns total cluster available in T 
+#
+###########################################################################
+sub getTotalAvailInTb {
+    my ($self) = @_;
+
+    return $self->convertKbToTb($self->{_totalAvail});
+}
+
+###########################################################################
+#
+# Runs neb-df and puts output in gnuplot ready format 
+#
+###########################################################################
+sub updateClusterSpaceInfo {
+    my ($self) = @_;
+
+    my @cmdOut = `neb-df`;
+    my $line;
+    $self->{_totalHosts} = 0;
+    $self->{_hostsOverNinetyEightPC} = 0;
+    foreach $line (@cmdOut) {
+
+        chomp($line);
+        if ($line =~ m/.*Filesystem.*/i) {next;}
+        elsif ($line =~ m/.*summmary.*/i) {next;}
+        elsif ($line =~ m/.*total.*/i) {next;}
+        elsif ($line =~ m/\s+[0-9]+\s+([0-9]+)\s+([0-9]+)\s+.*allocated.*/i) {
+
+            $self->{_totalUsed} = $self->convertKbToTb($1);
+            $self->{_totalAvail} = $self->convertKbToTb($2);
+            $self->{_totalCluster} = $self->convertKbToTb($1 + $2);
+            $self->{_totalUsedAsPercent} = ($self->{_totalUsed}/$self->{_totalCluster})*100;
+
+            next;
+        }
+        elsif ($line =~ m/(ipp[0-9]+)\s.+[0-9]+\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)%.*/i) {
+        
+            $self->{_totalHosts}++;
+            if ($4 >= 98) {$self->{_hostsOverNinetyEightPC}++;}
+
+#            print $1 . " " . $self->convertKbToTb($2+$3) . " " . $self->convertKbToTb($2) . " " . $self->convertKbToTb($3) . " $4PC \n" ; 
+            $self->{_czarDb}->updateHost($1, $self->convertKbToTb($2+$3), $self->convertKbToTb($3), $self->convertKbToTb($2));
+        }
+    }
+
+    $self->{_czarDb}->insertNewClusterSpace(
+            $self->{_totalCluster}, 
+            $self->{_totalAvail},  
+            $self->{_totalUsed}, 
+            $self->{_hostsOverNinetyEightPC});
+
+}
+1;
Index: /trunk/tools/roboczar.pl
===================================================================
--- /trunk/tools/roboczar.pl	(revision 28844)
+++ /trunk/tools/roboczar.pl	(revision 28845)
@@ -10,6 +10,6 @@
 use czartool::Gpc1Db;
 use czartool::Pantasks;
+use czartool::Nebulous;
 use czartool::Czarplot;
-
 
 my $period = 60;
@@ -24,4 +24,5 @@
 my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", 0, $save_temps); # TODO last arg here is save_temps, should get as arg
 my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
+my $nebulous = new czartool::Nebulous($czarDb);
 my $pantasks = new czartool::Pantasks();
 my $czarplot = new czartool::Czarplot($czarDb, "%Y%m%d-%H%M%S", "png", "/tmp", $save_temps);
@@ -101,6 +102,8 @@
     my $end = undef;
     my $priority = undef;
-
     while (1) {
+
+        print "* Checking Nebulous\n";
+        $nebulous->updateClusterSpaceInfo();
 
         updateServerStatus();
