Index: /trunk/ippMonitor/czartool/czarpoll.pl
===================================================================
--- /trunk/ippMonitor/czartool/czarpoll.pl	(revision 42857)
+++ /trunk/ippMonitor/czartool/czarpoll.pl	(revision 42858)
@@ -229,11 +229,15 @@
 
     my $server = undef;
-    my $alive = undef;
-    my $running = undef;
+
+    my ($alive, $running);
+
     foreach $server (@{$servers}) {
+        # For gpc1
         $pantasks->getServerStatus($server,'gpc1', \$alive, \$running);
         $czarDb->updateServerStatus($server,'gpc1', $alive, $running);
+        # For gpc2
         $pantasks->getServerStatus($server,'gpc2', \$alive, \$running);
         $czarDb->updateServerStatus($server,'gpc2', $alive, $running);
+
    }
 }
@@ -245,16 +249,20 @@
 ###########################################################################
 sub updateServerStatusLive {
-    print "* Checking all pantasks servers\n";
+    print "* Checking all pantasks live servers\n";
 
     my $servers = $pantasks->getServerList();
 
     my $server = undef;
-    my $alive = undef;
-    my $running = undef;
+    my ($alive, $running, $pan_host);
+
     foreach $server (@{$servers}) {
-        $pantasks->getServerStatus($server,'gpc1', \$alive, \$running);
-        $czarDb->updateServerStatusLive($server,'gpc1', $alive, $running);
-        $pantasks->getServerStatus($server,'gpc2', \$alive, \$running);
-        $czarDb->updateServerStatusLive($server,'gpc2', $alive, $running);
+        # For gpc1
+        $pantasks->getServerStatus($server,'gpc1', \$alive, \$running, \$pan_host);
+        $czarDb->updateServerStatusLive($server,'gpc1', $alive, $running, $pan_host);
+        print "Server: $server | Telescope: gpc1 | Alive: $alive | Running: $running | Host: " . (defined $pan_host ? $pan_host : "undef") . "\n";
+        # For gpc2
+        $pantasks->getServerStatus($server,'gpc2', \$alive, \$running, \$pan_host);
+        $czarDb->updateServerStatusLive($server,'gpc2', $alive, $running, $pan_host);
+        print "Server: $server | Telescope: gpc2 | Alive: $alive | Running: $running | Host: " . (defined $pan_host ? $pan_host : "undef") . "\n";
    }
 }
@@ -637,7 +645,7 @@
 
             # Convert KB to TB
-            my $total_tb     = sprintf("%.1f", $blocks    / 1024 / 1024 / 1024);
-            my $used_tb      = sprintf("%.1f", $used      / 1024 / 1024 / 1024);
-            my $available_tb = sprintf("%.1f", $available / 1024 / 1024 / 1024);
+            my $total_tb     = sprintf("%.3f", $blocks    / 1024 / 1024 / 1024 );
+            my $used_tb      = sprintf("%.3f", $used      / 1024 / 1024 / 1024 );
+            my $available_tb = sprintf("%.3f", $available / 1024 / 1024 / 1024 );
 
             my $used_percent      = sprintf("%.3f", $used / $blocks * 100);
@@ -650,7 +658,8 @@
 
             # Example: ippdb01.0(3.5T)
-            my $host_label = "$host.$suffix(${total_tb}T)";
-            $czarDb->updateHost($host_label, 100, $available_percent, $used_percent, $readable, $writable);
-        }
-    }
-}
+            #my $host_label = "$host.$suffix(${total_tb}T)";
+            my $host_label = "$host.$suffix";
+            $czarDb->updateHost($host_label, $total_tb, $available_tb, $used_tb, $readable, $writable);
+        }
+    }
+}
Index: /trunk/ippMonitor/czartool/czartool/CzarDb.pm
===================================================================
--- /trunk/ippMonitor/czartool/czartool/CzarDb.pm	(revision 42857)
+++ /trunk/ippMonitor/czartool/czartool/CzarDb.pm	(revision 42858)
@@ -175,5 +175,5 @@
 ###########################################################################
 sub updateServerStatusLive {
-    my ($self, $server,$telescope, $alive, $running) = @_;
+    my ($self, $server,$telescope, $alive, $running, $pan_host) = @_;
 
     my $query = $self->{_db}->prepare(<<SQL);
@@ -184,7 +184,7 @@
     $query = $self->{_db}->prepare(<<SQL);
     INSERT INTO live_servers
-        (server,telescope, alive, running)
+        (server,telescope, alive, running, host)
         VALUES
-        ('$server','$telescope', $alive, $running);
+        ('$server','$telescope', $alive, $running, '$pan_host');
 SQL
        $query->execute;
Index: /trunk/ippMonitor/czartool/czartool/Pantasks.pm
===================================================================
--- /trunk/ippMonitor/czartool/czartool/Pantasks.pm	(revision 42857)
+++ /trunk/ippMonitor/czartool/czartool/Pantasks.pm	(revision 42858)
@@ -179,16 +179,26 @@
 ###########################################################################
 sub getServerStatus {
-    my ($self, $server,$telescope, $alive, $running) = @_;
-
-    my $ipphome;
-
-    if ($telescope eq 'gpc1') {
-       $ipphome = $ipphome1;
-    }
-    elsif ($telescope eq 'gpc2') {
-       $ipphome = $ipphome2;
-    }
-    else {
-        print "WARNING: Must specify a telescope for connecting to the right pantask\n";
+    my ($self, $server,$telescope, $alive, $running, $pan_host) = @_;
+
+    my $ipphome;
+
+    if ($telescope eq 'gpc1') {
+       $ipphome = $ipphome1;
+    }
+    elsif ($telescope eq 'gpc2') {
+       $ipphome = $ipphome2;
+    }
+    else {
+        print "WARNING: Must specify a telescope for connecting to the right pantask\n";
+    }
+
+    my $pan_host_cmd = "grep \"PANTASKS_SERVER \" $ipphome/$server/ptolemy.rc 2>/dev/null | awk '{print \$2}'";
+    ${$pan_host} = `$pan_host_cmd`;
+    chomp(${$pan_host});
+    
+    #print "DEBUG: pan_host for server $server ($telescope) is: " . (defined $pan_host ? $pan_host : "undef") . "\n";
+
+    if ($? != 0 || ${$pan_host} eq '') {
+        ${$pan_host} = undef;
     }
 
Index: /trunk/ippMonitor/raw/czartool_labels.php
===================================================================
--- /trunk/ippMonitor/raw/czartool_labels.php	(revision 42857)
+++ /trunk/ippMonitor/raw/czartool_labels.php	(revision 42858)
@@ -266,9 +266,10 @@
     $start = microtime(true);
     echo "<tr>";
-    createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\"><font color=\"blue\">here</a>)", 2);
+    createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\"><font color=\"blue\">here</a>)", 3);
       
     echo "<tr>";
     createTableColumnHeader("Database");
-    createTableColumnHeader("Status (sec behind master)");
+    createTableColumnHeader("disk (TB)");
+    createTableColumnHeader("Status");
     // gpc dbs
     showDatabaseStatus($HOST_GPC1, $USER_GPC1, $PASSWORD_GPC1, $LABEL_GPC1);
@@ -287,5 +288,5 @@
     
     // end time
-    echo "<tr><th colspan=2>";
+    echo "<tr><th colspan=3>";
     $total_time = round((microtime(true) - $start), 3);
     echo "loading in $total_time seconds.";
@@ -375,5 +376,5 @@
 echo getSpaces($czardb);
 # storage plot
- echo getHosts($czardb);
+echo getHosts($czardb);
 
 # timer for main page end
@@ -1252,9 +1253,9 @@
     echo $table;
     echo "<tr>";
-    createTableTitle("Pantasks server status", 3);
+    createTableTitle("Pantasks server status", 4);
     echo "<tr>";
 
     // Define column headers in an array for flexibility
-    $columnHeaders = array("Server", "Alive?", "Running?");
+    $columnHeaders = array("Server", "Host", "Alive?", "Running?");
     foreach ($columnHeaders as $header) {
         createTableColumnHeader($header);
@@ -1263,5 +1264,5 @@
 
     foreach ($servers as &$server) {
-        getServerStatus($db,$proj, $server, $alive, $running);
+        getServerStatus($db,$proj, $server, $alive, $running, $host);
 
         echo "<tr>\n";
@@ -1275,9 +1276,13 @@
             ."&stage=".$selectedStage
             ."&plottype=".$plotType;
+       // ganglia
+       $link2 = "http://ganglia.pan-starrs.ifa.hawaii.edu/?m=load_one&r=hour&s=descending&c=IPP+Production&h=".$host.".ifa.hawaii.edu&sh=1&hc=7&z=small";
 
         // Display server row cells
         createFormattedTableCell(1, $link, $server, 0, 0);
+        createFormattedTableCell(1, $link2, $host, 0 , 0);
         createFormattedTableCell(0, "", $alive ? "yes" : "NO", !$alive, 0);
         createFormattedTableCell(0, "", $running ? "yes" : "NO", !$running, 0);
+
 
         echo "</tr>\n";
@@ -1328,8 +1333,8 @@
 #
 ###########################################################################
-function getServerStatus($db,$proj, $server, &$alive, &$running) {
+function getServerStatus($db,$proj, $server, &$alive, &$running, &$host) {
 
 #    $sql = "SELECT alive, running FROM science_servers WHERE server LIKE '$server' AND telescope LIKE '$proj' ORDER BY timestamp DESC LIMIT 1";
-    $sql = "SELECT alive, running FROM live_servers WHERE server LIKE '$server' AND telescope LIKE '$proj' ORDER BY timestamp DESC LIMIT 1";
+    $sql = "SELECT alive, running, host FROM live_servers WHERE server LIKE '$server' AND telescope LIKE '$proj' ORDER BY timestamp DESC LIMIT 1";
     if($debug){echo "$sql<br>";}
 
@@ -1340,4 +1345,5 @@
     $alive = $row[0];
     $running = $row[1];
+    $host = $row[2];
 }
 
@@ -1385,61 +1391,121 @@
 ###########################################################################
 function showReplicationsStatus($replHost, $replUser, $replPassword, $replDatabaseName) {
-    #print "<br>$replHost, $replUser, $replPassword, $replDatabaseName<br/>";
+    //print "<br>$replHost, $replUser, $replPassword, $replDatabaseName<br/>";
+    global $czardb;
+
+    // Prepare storage info early, https://panstarrs.atlassian.net/browse/IPP-2338
+    $storageInfo = '';
+    $hostPrefixParts = explode(' ', $replDatabaseName);
+    $hostPrefix = addslashes($hostPrefixParts[0]);
+
+    $sql = sprintf(
+        "SELECT host, FORMAT(total,1), FORMAT(available,2), FORMAT(used,2), writable, readable, FORMAT(used/total*100,1)
+         FROM hosts
+         WHERE host LIKE '%s%%' order by available desc
+         LIMIT 1",
+         $hostPrefix
+    );
+
+    $qry = $czardb->query($sql);
+    if (PEAR::isError($qry)) {
+        $storageInfo = "<td style=\"background-color: red; color: white;\">Storage query error</td>";
+    } else {
+        if ($qry->fetchInto($row)) {
+            list($host, $total, $available, $used, $writable, $readable, $ratio) = $row;
+            $storageInfo = "<td>$ratio% of $total</td>";
+        } else {
+            $storageInfo = "<td>No host storage data</td>";
+        }
+    }
+
     $dbRepl = DB::connect("mysql://$replUser:$replPassword@$replHost");
     if (PEAR::isError($dbRepl)) {
-        echo "<tr><td>$replDatabaseName</td><td bgcolor=\"red\">MySQL DB connection error - check configuration</td></tr>";
-        //die("MySQL DB connection error: Check the configuration for $replDatabaseName");
-        //die("");
+        echo "<tr><td>$replDatabaseName</td>$storageInfo<td style=\"background-color: red; color: white;\">MySQL DB connection error - check configuration</td></tr>";
+        return -1; // Don't stop the rest of the script
+    }
+
+    // Query replication status
+    $res = $dbRepl->query('SHOW SLAVE STATUS');
+    if (PEAR::isError($res)) {
+        echo "<tr><td>$replDatabaseName</td>$storageInfo<td style=\"background-color: red; color: white;\">MySQL query error - invalid user or privileges</td></tr>";
+        $dbRepl->disconnect();
         return -1;
-
-    }
-
-    # note: mysql user must have either SUPER or REPLICATION CLIENT privileges on the database 
-    $res = $dbRepl->query('SHOW SLAVE STATUS');
-    if (dberror($res)) {
-        echo "<tr><td>$replDatabaseName</td><td bgcolor=\"red\">MySQL query error - invalid user? check configuration</td></tr>";
-        //die("MySQL DB connection error: Check the configuration for $replDatabaseName");
-        //die("");
-        return -1;
-    }
-
-    while ($res->fetchInto($row)) {
-        # Have a look for Last_Errno in http://dev.mysql.com/doc/refman/5.0/en/show-slave-status.html
-        $errorStatusInMySql = $row[18];
-	$sec_behind = $row[32];
-	if ($sec_behind===NULL) {
-	    $sec_behind = 99999999;
-	    $errorStatusInMySql = 999999999;
-	}   
-        $replStatus = ($errorStatusInMySql==0?"OK ($sec_behind)":"<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">PROBLEM</font>");
-        echo "<tr><td>$replDatabaseName</td><td>$replStatus</td></tr>";
-        if ($errorStatusInMySql!=0) {
-            echo "<tr><td colspan=\"2\">Connect to $replDatabaseName replication host, execute 'SHOW SLAVE STATUS', and fix the problem.<br/>";
-            echo "Information <a href=\"http://dev.mysql.com/doc/refman/5.0/en/show-slave-status.html\">here</a></td></tr>";
+    }
+
+    if (!$res->fetchInto($row)) {
+        echo "<tr><td>$replDatabaseName</td>$storageInfo<td>No replication data available</td></tr>";
+        $dbRepl->disconnect();
+        return 0;
+    }
+
+    $errorStatusInMySql = $row[18];
+    $sec_behind = $row[32];
+
+    if ($sec_behind === NULL) {
+        $sec_behind = 99999999;
+        $errorStatusInMySql = 999999999;
+    }
+
+    $replStatus = ($errorStatusInMySql == 0)
+        ? "OK ($sec_behind sec behind)"
+        : "<span style=\"background-color: yellow; color: red;\">PROBLEM</span>";
+
+    echo "<tr><td>$replDatabaseName</td>$storageInfo";
+
+    if ($errorStatusInMySql != 0) {
+        echo "<tr><td colspan=\"5\">Connect to <strong>$replDatabaseName</strong>, run <code>SHOW SLAVE STATUS</code>, and resolve the issue. ";
+        echo "See <a href=\"https://dev.mysql.com/doc/refman/5.0/en/show-slave-status.html\" target=\"_blank\">MySQL Docs</a>.</td></tr>";
+    }
+
+    echo "<td>$replStatus</td>";
+
+    $dbRepl->disconnect();
+
+}
+
+###########################################################################
+#
+# Shows the status of the various replication mysql servers
+#
+###########################################################################
+function showDatabaseStatus($Host, $User, $Password, $DatabaseName) {
+    //print "<br>$Host, $User, $Password, $DatabaseName<br/>";
+    global $czardb;
+    // Prepare storage info early, https://panstarrs.atlassian.net/browse/IPP-2338
+    $storageInfo = '';
+    $hostPrefixParts = explode(' ', $DatabaseName);
+    $hostPrefix = addslashes($hostPrefixParts[0]);
+
+    $sql = sprintf(
+        "SELECT host, FORMAT(total,1), FORMAT(available,2), FORMAT(used,2), writable, readable, FORMAT(used/total*100,1)
+         FROM hosts
+         WHERE host LIKE '%s%%' order by available desc
+         LIMIT 1",
+         $hostPrefix
+    );
+
+    $qry = $czardb->query($sql);
+    if (PEAR::isError($qry)) {
+        $storageInfo = "<td style=\"background-color: red; color: white;\">Storage query error</td>";
+    } else {
+        if ($qry->fetchInto($row)) {
+            list($host, $total, $available, $used, $writable, $readable, $ratio) = $row;
+            $storageInfo = "<td>$ratio% of $total </td>";
+        } else {
+            $storageInfo = "<td>No host storage data</td>";
         }
     }
-    $dbRepl->disconnect();
-}
-
-###########################################################################
-#
-# Shows the status of the various replication mysql servers
-#
-###########################################################################
-function showDatabaseStatus($Host, $User, $Password, $DatabaseName) {
-    #print "<br>$replHost, $replUser, $replPassword, $replDatabaseName<br/>";
+
     $db = DB::connect("mysql://$User:$Password@$Host");
     if (PEAR::isError($db)) {
-        echo "<tr><td>$DatabaseName</td><td bgcolor=\"red\">MySQL DB connection error</td></tr>";
-        //die("MySQL DB connection error: Check the configuration for $DatabaseName");
-        //die("");
+        echo "<tr><td>$DatabaseName</td>$storageInfo<td>$Status</td>";
         return -1;
-
     }
     $Status = ($errorStatusInMySql==0?"OK":"<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">PROBLEM</font>");
-    echo "<tr><td>$DatabaseName</td><td>$Status</td></tr>";
+    echo "<tr><td>$DatabaseName</td>$storageInfo<td>$Status</td>";
 
     $db->disconnect();
 }
+
 
 ###########################################################################
@@ -1664,5 +1730,5 @@
     echo "     'free', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}],";
 
-    $sql = "SELECT host, format(total,1), format(available,2), format(used,2), writable, readable, format(used/total*100,2) FROM hosts order by host";
+    $sql = "SELECT host, format(total,1), format(available,2), format(used,2), writable, readable, format(used/total*100,2) FROM hosts where host like 'ipp1%' or host like 'ippb%' order by host";
     if ($debug) {echo "$sql<br>";}
     $qry = $db->query($sql);
