Index: /trunk/tools/czartool/CzarDb.pm
===================================================================
--- /trunk/tools/czartool/CzarDb.pm	(revision 28842)
+++ /trunk/tools/czartool/CzarDb.pm	(revision 28843)
@@ -152,4 +152,46 @@
     }
 }
+
+###########################################################################
+#
+# Updates hosts table
+#
+###########################################################################
+sub updateHost {
+    my ($self, $host, $total, $available, $used) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    DELETE FROM hosts WHERE host LIKE '$host';
+SQL
+
+    $query->execute;
+    $query = $self->{_db}->prepare(<<SQL);
+    INSERT INTO hosts
+        (host, total, available, used)
+        VALUES
+        ('$host', $total, $available, $used);
+SQL
+    $query->execute;
+
+}
+
+###########################################################################
+#
+# Inserts new cluster space info
+#
+###########################################################################
+sub insertNewClusterSpace {
+    my ($self, $total, $available, $used, $hostsOver98) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    INSERT INTO cluster_space
+        (total, available, used, hostsOver98)
+        VALUES
+        ( $total, $available, $used, $hostsOver98);
+SQL
+
+        $query->execute;
+}
+
 ###########################################################################
 #
@@ -193,6 +235,4 @@
 SQL
 
-
-
     if (!$query->execute) {return undef;}
 
@@ -308,4 +348,82 @@
 ###########################################################################
 #
+# Gets host data and stores it to temp file
+#
+###########################################################################
+sub createHostsData {
+    my ($self) = @_;
+
+    my $dataFile = "/tmp/czarplot_hosts.dat";
+    open (GNUDAT, ">$dataFile");
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT 
+        host, used, available 
+        FROM hosts
+        ORDER BY host;
+SQL
+
+    $query->execute;
+
+    # loop round results
+    while (my @row = $query->fetchrow_array()) {
+
+        my ($host, $used, $available) = @row;
+        print GNUDAT "$host $used $available\n";
+    }
+    close(GNUDAT);
+
+    return $dataFile;
+}
+
+###########################################################################
+#
+# Gets time series data for cluster storage and saves it to file 
+#
+###########################################################################
+sub createStorageTimeSeriesData {
+    my ($self, $fromTime, $toTime, $minX, $maxX, $minY, $maxY, $timeDiff) = @_;
+
+    my $dataFile = "/tmp/czarplot_gnuplot_storage_timeseries.dat";
+    open (GNUDAT, ">$dataFile");
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT 
+        MAX(available), MIN(available),  
+        DATE_FORMAT(MAX(timestamp),'$self->{_dateFormat}'), 
+        DATE_FORMAT(MIN(timestamp),'$self->{_dateFormat}'),
+        TIME_TO_SEC(TIMEDIFF(max(timestamp ), min(timestamp)))
+            FROM cluster_space 
+            WHERE timestamp >= '$fromTime' AND timestamp <= '$toTime'; 
+SQL
+
+
+    if (!$query->execute) {return undef;}
+
+    (${$maxY}, ${$minY}, ${$maxX}, ${$minX}, ${$timeDiff}) = $query->fetchrow_array();
+
+
+    $query = $self->{_db}->prepare(<<SQL);
+    SELECT 
+        DATE_FORMAT(timestamp, '$self->{_dateFormat}'), available 
+        FROM cluster_space 
+        WHERE timestamp >= '$fromTime' AND timestamp <= '$toTime' 
+        ORDER BY timestamp;
+SQL
+
+    $query->execute;
+
+    # loop round results
+    while (my @row = $query->fetchrow_array()) {
+
+        my ($timestamp, $available) = @row;
+        print GNUDAT "$timestamp $available\n";
+    }
+    close(GNUDAT);
+
+    return $dataFile;
+}
+###########################################################################
+#
 # Determines how much has been processed in the provided interval of time 
 # (format: 1 HOUR, 1 MINUTE 1 DAY etc)
@@ -336,5 +454,5 @@
 
     my $currentRevision = -1;
-    my $latestRevision = 8;
+    my $latestRevision = 9;
 
     while ($currentRevision != $latestRevision) {
@@ -351,4 +469,5 @@
         elsif ($currentRevision == 6) {$self->createRevision_7();}
         elsif ($currentRevision == 7) {$self->createRevision_8();}
+        elsif ($currentRevision == 8) {$self->createRevision_9();}
     }
 }
@@ -581,4 +700,43 @@
 #######################################################################################
 # 
+# Create revision 9 of the database 
+#
+#######################################################################################
+sub createRevision_9 {
+    my ($self) = @_;
+
+    print "* Creating revision 9 of '$self->{_dbName}'\n";
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    CREATE TABLE cluster_space (
+            timestamp TIMESTAMP DEFAULT NOW(),
+            total FLOAT, 
+            available FLOAT, 
+            used FLOAT, 
+            hostsOver98 SMALLINT);
+SQL
+
+      $query->execute;
+    $query = $self->{_db}->prepare(<<SQL);
+    CREATE TABLE hosts (
+            host VARCHAR(128), 
+            total FLOAT, 
+            available FLOAT, 
+            used FLOAT); 
+SQL
+
+      $query->execute;
+
+        $query = $self->{_db}->prepare(<<SQL);
+        CREATE INDEX clusterSpaceIndex ON cluster_space (timestamp);
+SQL
+
+      $query->execute;
+
+    $self->setRevision(9);
+}
+
+#######################################################################################
+# 
 # Sets current revision of ippToPsps database
 #
