Index: trunk/ippMonitor/czartool/czarDbSchema.sql
===================================================================
--- trunk/ippMonitor/czartool/czarDbSchema.sql	(revision 41072)
+++ trunk/ippMonitor/czartool/czarDbSchema.sql	(revision 41125)
@@ -404,4 +404,95 @@
 
 --
+-- Table structure for table `science_labels` (from current_labels)
+--
+
+DROP TABLE IF EXISTS `science_labels`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `science_labels` (
+  `server` varchar(128) default NULL,
+  `label` varchar(128) default NULL,
+  `telescope` varchar(128) NOT NULL,
+  `priority` int(11) NOT NULL default '0',
+  KEY `science_labels` (`server`,`label`, `telescope`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `science_nightlyscience` (from nightlyscience)
+--
+
+DROP TABLE IF EXISTS `science_nightlyscience`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `science_nightlyscience` (
+  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  `status` varchar(128) default 'NONE',
+  `telescope` varchar(128) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `science_reverts` (from reverts)
+--
+
+DROP TABLE IF EXISTS `science_reverts`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `science_reverts` (
+  `stage` varchar(128) default NULL,
+  `telescope` varchar(128) NOT NULL,
+  `reverting` tinyint(4) default NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `science_server_dates` (from server_dates)
+--
+
+DROP TABLE IF EXISTS `science_server_dates`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `science_server_dates` (
+  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  `server` varchar(64) default 'NONE',
+  `telescope` varchar(128) NOT NULL,
+  `date` varchar(64) default 'NONE'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `science_servers` (from servers)
+--
+
+DROP TABLE IF EXISTS `science_servers`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `science_servers` (
+  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  `server` varchar(128) default NULL,
+  `telescope` varchar(128) NOT NULL,
+  `alive` tinyint(4) default NULL,
+  `running` tinyint(4) default NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `live_servers` (from servers)
+--
+
+DROP TABLE IF EXISTS `live_servers`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `live_servers` (
+  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  `server` varchar(128) default NULL,
+  `telescope` varchar(128) NOT NULL,
+  `alive` tinyint(4) default NULL,
+  `running` tinyint(4) default NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
 -- Table structure for table `server_dates`
 --
Index: trunk/ippMonitor/czartool/czarpoll.pl
===================================================================
--- trunk/ippMonitor/czartool/czarpoll.pl	(revision 41072)
+++ trunk/ippMonitor/czartool/czarpoll.pl	(revision 41125)
@@ -236,4 +236,25 @@
         $pantasks->getServerStatus($server,'gpc2', \$alive, \$running);
         $czarDb->updateServerStatus($server,'gpc2', $alive, $running);
+   }
+}
+
+###########################################################################
+#
+# Updates pantasks server status TODO should really get info for all servers at once
+#
+###########################################################################
+sub updateServerStatusLive {
+    print "* Checking all pantasks servers\n";
+
+    my $servers = $pantasks->getServerList();
+
+    my $server = undef;
+    my $alive = undef;
+    my $running = undef;
+    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);
    }
 }
@@ -272,9 +293,10 @@
     my $newDayTime = $config->getMetricsStartTime();
     my $lastDayDailyTasks = "2010-01-01";
-
+    my $checkneb = 1; # 1 for nebulous, 0 for localhost test
     # main polling loop
     while (1) {
+
         my $iterationStartTime = time();
-
+ 
         #get the time of last czarpoll update
         $polldate = $czarDb->getPollDate();
@@ -287,9 +309,9 @@
         if($timediff > 120.) { 
             print "There is no recent Czarpoll iteration\n";
-            print "*Updating database entries*\n";
+            print "* Updating database entries*\n";
             $dbupdate = 1;
         } else {
             print "There is a recent Czarpoll iteration already made ($timediff sec ago)\n";
-            print "*Skipping database queries and entries*\n";
+            print "* Skipping database queries and entries\n";
             $dbupdate = 0;
         }
@@ -326,8 +348,8 @@
                 #TdB20190703: The ipp113 and ipp117 instances of czarpoll use the same stage DBs in czarDB. 
                 #Therefore, it makes no sense to run the cleanup+optimising twice
-                #print "* Performing database cleanup\n";
-                #$czarDb->cleanupDateRange($yesterday, $yesterday, $config->getCzarCleanupInterval());
-                #print "* Optimizing the database\n";
-                #$czarDb->optimize();
+                print "* Performing database cleanup\n";
+                $czarDb->cleanupDateRange($yesterday, $yesterday, $config->getCzarCleanupInterval());
+                print "* Optimizing the database\n";
+                $czarDb->optimize();
                 $lastDayDailyTasks = $yesterday;
             }
@@ -344,10 +366,18 @@
 
         # check nebulous
-        print "* Checking Nebulous\n";
-        if($dbupdate == 1) {$nebulous->updateClusterSpaceInfo();}
-        $plotter0->plotStorageTimeSeries($czarDb->subtractInterval($begin, "1 WEEK") , $end);
-        $plotter0->plotDiskUsageHistogram();
-        $plotter0->plotDiskUsageHistogramLarge();
+        if ($checkneb == 1) {
+            print "* Checking Nebulous\n";
+            if($dbupdate == 1) {$nebulous->updateClusterSpaceInfo();}
+            $plotter0->plotStorageTimeSeries($czarDb->subtractInterval($begin, "1 WEEK") , $end);
+            $plotter0->plotDiskUsageHistogram();
+            $plotter0->plotDiskUsageHistogramLarge();
+        }
+        else {
+            print "* Locahost, so no checking nebulous\n";
+        }
+
+        # check pantasks status
         if($dbupdate == 1) {updateServerStatus();}
+        if($dbupdate == 1) {updateServerStatusLive();}
 
         # check pantasks dates
Index: trunk/ippMonitor/czartool/czartool/CzarDb.pm
===================================================================
--- trunk/ippMonitor/czartool/czartool/CzarDb.pm	(revision 41072)
+++ trunk/ippMonitor/czartool/czartool/CzarDb.pm	(revision 41125)
@@ -166,4 +166,26 @@
 SQL
 
+       $query->execute;
+}
+
+###########################################################################
+#
+# Updates server table
+#
+###########################################################################
+sub updateServerStatusLive {
+    my ($self, $server,$telescope, $alive, $running) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    DELETE FROM live_servers where timestamp < CURRENT_TIMESTAMP - INTERVAL 12 hour;
+SQL
+       $query->execute;
+
+    $query = $self->{_db}->prepare(<<SQL);
+    INSERT INTO live_servers
+        (server,telescope, alive, running)
+        VALUES
+        ('$server','$telescope', $alive, $running);
+SQL
        $query->execute;
 }
Index: trunk/ippMonitor/czartool/extra_labels.dat
===================================================================
--- trunk/ippMonitor/czartool/extra_labels.dat	(revision 41125)
+++ trunk/ippMonitor/czartool/extra_labels.dat	(revision 41125)
@@ -0,0 +1,4 @@
+## TdB20190626: add extra labels for processing in this file. Syntax is as follows: [labelname] [telescope]
+## Priorities for the labels must be added to the priorities mySQL table for the relevant telescope, if desired.
+PV3.Pole.Reprocess.20180510 gpc1
+ps_ud_QUB gpc1
Index: trunk/ippMonitor/raw/czartool_labels.php
===================================================================
--- trunk/ippMonitor/raw/czartool_labels.php	(revision 41072)
+++ trunk/ippMonitor/raw/czartool_labels.php	(revision 41125)
@@ -214,105 +214,176 @@
 echo "<td style=height:200px;width:400px;text-align:top;\">";
 
-#echo "<br>";
+/////////////////////////////////////////
+// timer begin for status and links
+/////////////////////////////////////////
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$start = $time;
 
 // status table at top
 $nsStatus = getNightlyScienceStatus($czardb, $proj);
 $plotTypeLink = ($plotType == "linear") ? "log" : "linear";
-$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
+$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel . 
+        "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
+
 echo "<br>";
 echo $table;
-
-createTableTitle("Status and links", 3);
+createTableTitle("Status and links", 2);
 echo "<tr>\n";
-echo "<tr><td>Time of last update</td><td>$lastUpdateTime</td></tr>";
-echo "<tr><td>ippMonitor SVN version</td><td>"; include 'version.php'; echo "</td></tr>"; 
-echo "<tr><td>Current nightly science status</td><td>$nsStatus</td></tr>"; 
-echo "<tr><td>Postage stamp server status</td><td><a href=\"http://pstamp.ipp.ifa.hawaii.edu/status.php\"><font color=\"blue\">here</font></a></td></tr>";
-echo "<tr><td>Documentation</td><td><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\"><font color=\"blue\">here</font></a></td></tr>";
-echo "<tr><td>Cluster load</td><td><a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&hc=6&c=IPP%2520Production\"><font color=\"blue\">here</font></a> <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=cpu_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\"><font color=\"blue\">cpu_report</font></a> <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=mem_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\"><font color=\"blue\">mem_report</font></a></td></tr>";
-echo "<tr><td>IPP metrics</td><td><a href=\"https://ps1wiki.ifa.hawaii.edu/data/metrics/index.html\"><font color=\"blue\">here</font></a></td></tr>";
-echo "<tr><td>Czar log pages</td><td><a href=\"https://confluence.ipp.ifa.hawaii.edu/pages/viewrecentblogposts.action?key=IPPCZAR\"><font color=\"blue\">here</font></a></td></tr>";
-echo "<tr><td>Exposure summary</td><td><a href=\"czartool_exposures.php?pass=$pass&proj=$proj\"><font color=\"blue\">here</font></a></td></tr>";
-echo "<tr><td>Confluence</td><td><a href=\"https://confluence.ipp.ifa.hawaii.edu/display/IPPCZAR/IPP-Czaring+Home\"><font color=\"blue\">here</font></a></td></tr>";
-echo "<tr><td>JIRA</td><td><a href=\"https://jira.ipp.ifa.hawaii.edu/secure/Dashboard.jspa\"><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>Time of last update</td>
+          <td>$lastUpdateTime</td></tr>";
+echo "<tr><td>ippMonitor SVN version</td>
+          <td>"; include 'version.php'; echo "</td></tr>"; 
+echo "<tr><td>Current nightly science status</td>
+          <td>$nsStatus</td></tr>"; 
+echo "<tr><td>Postage stamp server status</td>
+          <td><a href=\"http://pstamp.ipp.ifa.hawaii.edu/status.php\" target=new><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>Documentation</td>
+          <td><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\" target=new><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>Cluster load</td>
+          <td><a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&hc=6&c=IPP%2520Production\">
+              <font color=\"blue\">here</font></a> 
+              <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=cpu_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\">
+              <font color=\"blue\">cpu_report</font></a> 
+              <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=mem_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\">
+              <font color=\"blue\">mem_report</font></a></td></tr>";
+echo "<tr><td>IPP metrics</td>
+          <td><a href=\"https://ps1wiki.ifa.hawaii.edu/data/metrics/index.html\"><font color=\"blue\" target=new>here</font></a></td></tr>";
+echo "<tr><td>Czar log pages</td>
+          <td><a href=\"https://confluence.ipp.ifa.hawaii.edu/pages/viewrecentblogposts.action?key=IPPCZAR\" target=new><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>Exposure summary</td>
+          <td><a href=\"czartool_exposures.php?pass=$pass&proj=$proj\"><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>Confluence</td>
+          <td><a href=\"https://confluence.ipp.ifa.hawaii.edu/display/IPPCZAR/IPP-Czaring+Home\" target=new><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>JIRA</td>
+          <td><a href=\"https://jira.ipp.ifa.hawaii.edu/secure/Dashboard.jspa\" target=new><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>data store</td>
+          <td><a href=\"https://svn.ifa.hawaii.edu/\" target=new><font color=\"blue\">here</font></a></td></tr>";
 
 $plotTypeLink = ($plotType == "linear") ? "log" : "linear";
-$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&mode=" . $selectedMode . "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
-
-echo "</table>\n";
-
-echo "<br>";
-
-       createLabelsTable($pass, 
-         $proj, 
-         $czardb, 
-         $selectedMode, 
-         $labels, 
-         $distLabelsExist, 
-         $pubLabelsExist, 
-         $stages, 
-         "new", 
-         $selectedLabel, 
-         $selectedStage, 
-         $plotType);
-
-      if ($selectedMode == "update") {echo "<br>"; createPStampDataTable();}
-      echo "<br>";
-
-      # XXX EAM : 2017.09.17 : debugging slowness
-      createServersTable($pass, $proj,$selectedMode,$czardb, $servers, $selectedLabel, $selectedStage, $plotType); echo "<br>";
-      createSummitDataTable($projectdb); echo "<br>"; // this is slow because of the join between summitExp and rawExp
-      createChunkDataTable($projectdb); echo "<br>"; 
-      createDatesTable($czardb, $proj); echo "<br>";
-
-      echo $table;
-      echo "<tr>";
-      createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\">here</a>)", 2);
-
-      echo "<tr>";
-      createTableColumnHeader("Database");
-      createTableColumnHeader("Status (sec behind master)");
-      showDatabaseStatus($HOST_GPC1, $USER_GPC1, $PASSWORD_GPC1, $DBNAME_GPC1);
-      showReplicationsStatus($REPL_HOST_GPC1, $REPL_USER_GPC1, $REPL_PASSWORD_GPC1, $REPL_DBNAME_GPC1);
-      showReplicationsStatus($REPL_HOST_GPC1_SECONDARY, $REPL_USER_GPC1_SECONDARY, $REPL_PASSWORD_GPC1_SECONDARY, $REPL_DBNAME_GPC1_SECONDARY);
-
-      echo "<tr>";
-
-      showDatabaseStatus($HOST_NEBULOUS, $USER_NEBULOUS, $PASSWORD_NEBULOUS, $DBNAME_NEBULOUS);
-      showReplicationsStatus($REPL_HOST_NEBULOUS, $REPL_USER_NEBULOUS, $REPL_PASSWORD_NEBULOUS, $REPL_DBNAME_NEBULOUS);
-      showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_DBNAME_NEBULOUS_SECONDARY);
-      showReplicationsStatus($REPL_HOST_DATASTORE_SECONDARY, $REPL_USER_DATASTORE_SECONDARY, $REPL_PASSWORD_DATASTORE_SECONDARY, $REPL_DBNAME_DATASTORE_SECONDARY);
-
-#     some mysql replication slaves to add when they are returned to service
-#     showReplicationsStatus($REPL_HOST_PSTAMP, $REPL_USER_PSTAMP, $REPL_PASSWORD_PSTAMP, $REPL_DBNAME_PSTAMP);
-#     showReplicationsStatus($REPL_HOST_ISP, $REPL_USER_ISP, $REPL_PASSWORD_ISP, $REPL_DBNAME_ISP);
-      echo "</table>";
-
-      echo $table;
-      echo "<tr>";
-      createTableTitle("Critical machine status", 2);
-
-      echo "<tr>";
-      createTableColumnHeader("Hostname");
-      createTableColumnHeader("Status");
-      showPingStatus($HOST_GATEWAY, $DBNAME_GATEWAY);
-      showPingStatus($HOST_GATEWAY_SECONDARY, $DBNAME_GATEWAY_SECONDARY);
-
-#      showPingStatus($HOST_APACHE1, $DBNAME_APACHE1);
-      showPingStatus($HOST_APACHE2, $DBNAME_APACHE2);
-      showPingStatus($HOST_APACHE3, $DBNAME_APACHE3);
-      showPingStatus($HOST_APACHE4, $DBNAME_APACHE4);
-      showPingStatus($HOST_APACHE5, $DBNAME_APACHE5);
-      showPingStatus($HOST_APACHE6, $DBNAME_APACHE6);
-      showPingStatus($HOST_APACHE7, $DBNAME_APACHE7);
-      showPingStatus($HOST_PROXY, $DBNAME_PROXY);
-      showPingStatus($HOST_SVN, $DBNAME_SVN);
-      showPingStatus($HOST_CONFLUENCE, $DBNAME_CONFLUENCE);
-
-      echo "</table>";
-
-echo "</table>";
+$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&mode=" . $selectedMode . 
+        "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
+
+// timer finished
+echo "<tr><th colspan=4>";
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$finish = $time;
+$total_time = round(($finish - $start), 3);
+echo "loading in $total_time seconds.";
+echo "</th></tr>";
+echo "</table><br>";
+
+createLabelsTable($pass, $proj, $czardb, $selectedMode, $labels, 
+  $distLabelsExist, $pubLabelsExist, $stages, "new", $selectedLabel, 
+  $selectedStage, $plotType);
+if ($selectedMode == "update") {echo "<br>"; createPStampDataTable();} 
+
+# XXX EAM : 2017.09.17 : debugging slowness
+# CCL : 2019.11.09 : debugging slowness
+//createSummitDataTable($projectdb); // this is slow because of the join between summitExp and rawExp, but not the major one
+createSummitDataTable2($projectdb); // this is slow because of the join between summitExp and rawExp, but not the major one
+
+createServersTable($pass, $proj,$selectedMode,$czardb, $servers, $selectedLabel, $selectedStage, $plotType); 
+// this was the major slowness part due to large table in czardb
+
+createChunkDataTable($projectdb);  // this is another part for slowness during nightly processing
+
+createDatesTable($czardb, $proj); 
+
+/////////////////////////////////////////
+// timer begin for Database status
+/////////////////////////////////////////
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$start = $time;
+
+// status table at top
+  echo $table;
+  echo "<tr>";
+  createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\">here</a>)", 2);
+  
+  echo "<tr>";
+  createTableColumnHeader("Database");
+  createTableColumnHeader("Status (sec behind master)");
+  showDatabaseStatus($HOST_GPC1, $USER_GPC1, $PASSWORD_GPC1, $DBNAME_GPC1);
+  showReplicationsStatus($REPL_HOST_GPC1, $REPL_USER_GPC1, $REPL_PASSWORD_GPC1, $REPL_DBNAME_GPC1);
+  showReplicationsStatus($REPL_HOST_GPC1_SECONDARY, $REPL_USER_GPC1_SECONDARY, $REPL_PASSWORD_GPC1_SECONDARY, $REPL_DBNAME_GPC1_SECONDARY);
+  
+  echo "<tr>";
+  showDatabaseStatus($HOST_NEBULOUS, $USER_NEBULOUS, $PASSWORD_NEBULOUS, $DBNAME_NEBULOUS);
+  showReplicationsStatus($REPL_HOST_NEBULOUS, $REPL_USER_NEBULOUS, $REPL_PASSWORD_NEBULOUS, $REPL_DBNAME_NEBULOUS);
+  showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_DBNAME_NEBULOUS_SECONDARY);
+  showReplicationsStatus($REPL_HOST_DATASTORE_SECONDARY, $REPL_USER_DATASTORE_SECONDARY, $REPL_PASSWORD_DATASTORE_SECONDARY, $REPL_DBNAME_DATASTORE_SECONDARY);
+  
+//  some mysql replication slaves to add when they are returned to service
+//  showReplicationsStatus($REPL_HOST_PSTAMP, $REPL_USER_PSTAMP, $REPL_PASSWORD_PSTAMP, $REPL_DBNAME_PSTAMP);
+//  showReplicationsStatus($REPL_HOST_ISP, $REPL_USER_ISP, $REPL_PASSWORD_ISP, $REPL_DBNAME_ISP);
+
+// timer finished
+echo "<tr><th colspan=2>";
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$finish = $time;
+$total_time = round(($finish - $start), 3);
+echo "loading in $total_time seconds.";
+echo "</th></tr>";
+echo "</table><br>";
+
+/////////////////////////////////////////
+// timer begin for critical machines
+/////////////////////////////////////////
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$start = $time;
+
+// status table at top
+  $PingStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">DOWN</font>";
+  echo $table;
+  echo "<tr>";
+  createTableTitle("Critical machine status", 3);
+
+  echo "<tr>";
+  createTableColumnHeader("Hostname");
+  createTableColumnHeader("Status");
+  createTableColumnHeader("Loading time");
+  showPingStatus($HOST_GATEWAY, $DBNAME_GATEWAY);
+  showPingStatus($HOST_GATEWAY_SECONDARY, $DBNAME_GATEWAY_SECONDARY);
+  showPingStatus($HOST_APACHE1, $DBNAME_APACHE1);
+  showPingStatus($HOST_APACHE2, $DBNAME_APACHE2);
+  showPingStatus($HOST_APACHE3, $DBNAME_APACHE3);
+  showPingStatus($HOST_APACHE4, $DBNAME_APACHE4);
+  showPingStatus($HOST_APACHE5, $DBNAME_APACHE5);
+  showPingStatus($HOST_APACHE6, $DBNAME_APACHE6);
+  showPingStatus($HOST_APACHE7, $DBNAME_APACHE7);
+  showPingStatus($HOST_APACHE8, $DBNAME_APACHE8);
+//     echo "<td>ippc70 (apache node) <td> $PingStatus <td> 0 seconds ";  // comment out if ippc70 is back
+  showPingStatus($HOST_PROXY, $DBNAME_PROXY);
+  showPingStatus($HOST_SVN, $DBNAME_SVN);
+  showPingStatus($HOST_CONFLUENCE, $DBNAME_CONFLUENCE);
+
+// timer finished
+echo "<tr><th colspan=3>";
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$finish = $time;
+$total_time = round(($finish - $start), 3);
+echo "loading in $total_time seconds.";
+echo "</th></tr>";
+echo "</table><br>";
+    
+
 menu_end();
 
+
+#############################################################################
+#############################  Functions Below  #############################
+#############################################################################
 
 ###########################################################################
@@ -361,90 +432,4 @@
 }
 
-###########################################################################
-#
-# Creates a table of summitExp against rawExp
-#
-###########################################################################
-function createSummitDataTable($projectdb) {
-
-    $date = date("Y-m-d");
-    $sql = "SELECT DISTINCT exp_type FROM summitExp WHERE dateobs > '$date'";
-
-    $qry = $projectdb->query($sql);
-    if (dberror($qry)) {
-        echo "<b>error reading newExp table</b><br>\n";
-        echo "<br><small><b> table query : $sql </b></small><br>\n";
-        menu_end();
-    }
-
-    // set up the table
-    global $table;
-    echo $table;
-    echo "<tr>";
-    createTableTitle("Status of last night's data", 4);
-    echo "<tr>";
-    createTableColumnHeader("Exposure type");
-    createTableColumnHeader("At summit");
-    createTableColumnHeader("Registered at MHPCC");
-    createTableColumnHeader("At summit (Dropped)");
-
-    $msg = "No science images taken since $date";
-
-    // list the results
-    while ($qry->fetchInto($expType)) {
-
-        $sql = "SELECT COUNT(*) FROM summitExp left join pzDownloadExp using (summit_id) WHERE dateobs > '$date' AND exp_type = '$expType[0]' and (state != 'drop' or state is null) and fault != 1042";
-#       $sql = "SELECT COUNT(*) FROM summitExp WHERE dateobs > '$date' AND exp_type = '$expType[0]'";
-        $qry2 = $projectdb->query($sql);
-        $qry2->fetchInto($summit);
-
-
-        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name WHERE summitExp.dateobs > '$date' AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
-        $qry2 = $projectdb->query($sql);
-        $qry2->fetchInto($mhpcc);
-
-        $sql = "SELECT COUNT(*) FROM summitExp join pzDownloadExp using (summit_id) WHERE dateobs > '$date' AND exp_type = '$expType[0]' and state = 'drop'";
-        $qry2 = $projectdb->query($sql);
-        $qry2->fetchInto($dropped);
-
-
-        #Query with 30 minutes delay to check during the night if any exposures are missing.
-        $datehour = gmdate("Y-m-d H:i:s");
-        $sql = "SELECT COUNT(*) FROM summitExp left join pzDownloadExp using (summit_id) WHERE dateobs > '$date' AND dateobs <= date_sub('$datehour', interval 30 minute) AND exp_type = '$expType[0]' and (state != 'drop' or state is null) and fault != 1042";
-        $qry2 = $projectdb->query($sql);
-        $qry2->fetchInto($summitdelay);
-
-        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name WHERE summitExp.dateobs > '$date' AND summitExp.dateobs <= date_sub('$datehour', interval 30 minute) AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
-        $qry2 = $projectdb->query($sql);
-        $qry2->fetchInto($mhpccdelay);
-
-        echo "<tr>";
-
-        $DLdiff = $summit[0] - $mhpcc[0];
-        if ($DLdiff == 0) $error = 0;
-        else $error = 1;
-
-        $delayDLdiff = $summitdelay[0] - $mhpccdelay[0];
-        if ($delayDLdiff == 0) $errordelay = 0;
-        else $errordelay = 1;
-
-        echo "<td>$expType[0]</td>";
-        echo "<td>$summit[0]</td>";
-        #createFormattedTableCell("", "", $mhpcc[0], $error, 0);
-        if ($delayDLdiff==0) {
-           createFormattedTableCell("", "", $mhpcc[0], $error, 0);
-        } else {
-           $DLStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">$mhpcc[0] ($delayDLdiff)</font>";
-           echo "<td>$DLStatus</td>";
-        }
-
-        echo "<td>$dropped[0]</td>";
-
-        echo "</tr>";
-    }
-
-    echo "</table>\n";
-
-}
 
 ###########################################################################
@@ -455,4 +440,11 @@
 function createChunkDataTable($projectdb) {
 
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // function begin
     #First find the reference exposure ID to speed up the subsequent queries
     $date = gmdate("Y-m-d");
@@ -592,5 +584,17 @@
         echo "</tr>";
     }
-    echo "</table>\n";
+
+
+    // timer finished
+    echo "<tr><th colspan=5>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    echo "loading in $total_time seconds.";
+    $start= $finish;
+    echo "</th></tr>";
+    echo "</table></br>";
 
 }
@@ -634,4 +638,11 @@
         $selectedLabel, $selectedStage, $plotType) {
 
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // function begin
     $isUpdate = ($selectedMode == "update");
     global $headerColor;
@@ -757,5 +768,16 @@
 
     echo "</tr>\n";
-    echo "</table>\n";
+
+    // timer finished
+    echo "<tr><th colspan=11>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    echo "loading in $total_time seconds.";
+    $start= $finish;
+    echo "</th></tr>";
+    echo "</table><br>";
 }
 
@@ -905,4 +927,11 @@
 function createDatesTable($db, $proj) {
 
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // function begin
     global $table;
     echo $table;
@@ -917,5 +946,16 @@
     createServerDateRow($db, $proj, "registration");
 
-    echo "</table>\n";
+    // timer finished
+    echo "<tr><th colspan=11>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    echo "loading in $total_time seconds.";
+    $start= $finish;
+    echo "</th></tr>";
+    echo "</table><br>";
+
 }
 
@@ -959,4 +999,11 @@
 function createServersTable($pass, $proj, $selectedMode, $db, $servers, $selectedLabel, $selectedStage, $plotType) {
 
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // function begin
     // set up table columns
     global $table;
@@ -1045,5 +1092,15 @@
     }
 
-    echo "</table>\n";
+    // timer finished
+    echo "<tr><th colspan=5>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    echo "loading in $total_time seconds.";
+    $start= $finish;
+    echo "</th></tr>";
+    echo "</table><br>\n";
 }
 
@@ -1087,5 +1144,6 @@
 function getServerStatus($db,$proj, $server, &$alive, &$running) {
 
-    $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 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";
     if($debug){echo "$sql<br>";}
 
@@ -1206,4 +1264,11 @@
 ###########################################################################
 function showPingStatus($Host, $DatabaseName) {
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // function begin
     exec("ping -c 1 $Host", $res, $rval);
     if ($rval == 0){
@@ -1212,7 +1277,186 @@
       $PingStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">DOWN</font>";
     }
-    echo "<tr><td>$DatabaseName</td><td>$PingStatus</td></tr>";
-}
-
+    echo "<tr><td>$DatabaseName</td>";
+
+    echo "</td><td>$PingStatus</td>";
+    // timer finished
+    echo "<td>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    echo "$total_time seconds";
+    $start= $finish;
+    echo "</td></tr>";
+}
+
+
+###########################################################################
+#
+# Creates a table of summitExp against rawExp
+#
+###########################################################################
+function createSummitDataTable($projectdb) {
+
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // function begin
+    $date = date("Y-m-d");
+    $sql = "SELECT DISTINCT exp_type FROM summitExp WHERE dateobs > '$date'";
+
+    $qry = $projectdb->query($sql);
+    if (dberror($qry)) {
+        echo "<b>error reading newExp table</b><br>\n";
+        echo "<br><small><b> table query : $sql </b></small><br>\n";
+        menu_end();
+    }
+
+    // set up the table
+    global $table;
+    echo $table;
+    echo "<tr>";
+    createTableTitle("Data status > $date", 4);
+    echo "<tr>";
+    createTableColumnHeader("Exposure type");
+    createTableColumnHeader("At summit");
+    createTableColumnHeader("Registered at MHPCC");
+    createTableColumnHeader("Summit (Drop/Null)");
+
+    $msg = "No science images taken since $date";
+
+    // list the results
+    while ($qry->fetchInto($expType)) {
+
+        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id) 
+                WHERE dateobs > '$date' AND exp_type = '$expType[0]'";
+             //   AND state != 'drop' AND state is not null AND fault != 1042";
+        $qry2 = $projectdb->query($sql);
+        $qry2->fetchInto($summit);
+
+        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name 
+                WHERE summitExp.dateobs > '$date' AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
+        $qry2 = $projectdb->query($sql);
+        $qry2->fetchInto($mhpcc);
+
+        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id) 
+                WHERE dateobs > '$date' AND exp_type = '$expType[0]' AND (state = 'drop' OR state is null)";
+        $qry2 = $projectdb->query($sql);
+        $qry2->fetchInto($dropped);
+
+
+        #Query with 30 minutes delay to check during the night if any exposures are missing.
+        $datehour = gmdate("Y-m-d H:i:s");
+        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id) 
+                WHERE dateobs > '$date' AND dateobs <= date_sub('$datehour', interval 30 minute) 
+                AND exp_type = '$expType[0]' AND (state != 'drop' OR state is null) and fault != 1042";
+
+        $qry2 = $projectdb->query($sql);
+        $qry2->fetchInto($summitdelay);
+
+        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name 
+                WHERE summitExp.dateobs > '$date' AND summitExp.dateobs <= date_sub('$datehour', interval 30 minute) 
+                AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
+        $qry2 = $projectdb->query($sql);
+        $qry2->fetchInto($mhpccdelay);
+
+        echo "<tr>";
+
+        $DLdiff = $summit[0] - $mhpcc[0];
+        if ($DLdiff == 0) $error = 0;
+        else $error = 1;
+
+        $delayDLdiff = $summitdelay[0] - $mhpccdelay[0];
+        if ($delayDLdiff == 0) $errordelay = 0;
+        else $errordelay = 1;
+
+        echo "<td>$expType[0]</td>";
+        echo "<td>$summit[0]</td>";
+        if ($delayDLdiff==0) {
+           createFormattedTableCell("", "", $mhpcc[0], $error, 0);
+        } else {
+           $DLStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">$mhpcc[0] ($delayDLdiff)</font>";
+           echo "<td>$DLStatus</td>";
+        }
+
+        echo "<td>$dropped[0]</td>";
+
+        echo "</tr>";
+    }
+
+    // timer finished
+    echo "<tr><th colspan=4>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    echo "loading in $total_time seconds.";
+    $start= $finish;
+    echo "</th></tr>";
+    echo "</table><br>";
+}
+
+
+function createSummitDataTable2($projectdb) {
+
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // function begin
+    $date = date("Y-m-d");
+    // set up the table
+    global $table;
+    global $columnHeaderColor;
+    echo $table;
+    echo "<tr>";
+    createTableTitle("Data status > $date", 4);
+    echo "<tr>";
+    createTableColumnHeader("Exp_type at summit");
+    createTableColumnHeader("Status at summit");
+    createTableColumnHeader("Status at mhpcc");
+    createTableColumnHeader("Number");
+    $sql = "SELECT summitExp.exp_type,pzDownloadExp.state,rawExp.state,COUNT(*) FROM summitExp 
+            LEFT JOIN pzDownloadExp USING (summit_id) LEFT JOIN rawExp on summitExp.exp_name = rawExp.exp_name 
+            WHERE summitExp.dateobs > '$date' group by summitExp.exp_type,pzDownloadExp.state,rawExp.state";
+    $qry = $projectdb->query($sql);
+    while ($qry->fetchInto($tmp)) {
+        if ($tmp[1] == NULL) { 
+          echo  "<tr><td>$tmp[0]<td> null <td> null <td bgcolor=\"yellow\"> <font color=\"red\">$tmp[3]";
+        }
+        else {
+          if ($tmp[1] == 'run') { 
+            echo  "<tr><td>$tmp[0]<td> loading <td> null <td bgcolor=$columnHeaderColor> <font color=\"red\">$tmp[3]"; 
+          }
+          else {
+            if ($tmp[2] == NULL) { 
+              echo  "<tr><td>$tmp[0] <td> $tmp[1] <td> loading <td bgcolor=$columnHeaderColor> <font color=\"blue\">$tmp[3]";
+            }
+            else {
+              echo  "<tr><td>$tmp[0]<td> $tmp[1] <td> downloaded <td> $tmp[3]";
+            }
+          }
+        }
+    }
+
+    // timer finished
+    echo "<tr><th colspan=4>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    echo "loading in $total_time seconds.";
+    $start= $finish;
+    echo "</th></tr>";
+    echo "</table><br>";
+}
 ?>
 
