Index: trunk/ippMonitor/raw/czartool_labels.php
===================================================================
--- trunk/ippMonitor/raw/czartool_labels.php	(revision 41558)
+++ trunk/ippMonitor/raw/czartool_labels.php	(revision 41677)
@@ -19,5 +19,4 @@
 $LD_LIBRARY_PATH = getenv("LD_LIBRARY_PATH");
 putenv("LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH");
-
 
 if ($ID['menu']) {$myMenu = $ID['menu'];}
@@ -38,5 +37,4 @@
         "pub",
 	);
-        # "chipbackground");
 
 $getFailures = array(
@@ -86,23 +84,17 @@
 if ($proj == 'gpc1') {
     $servers=array(
-        #"addstar",
-        #"addstarlap",
-	"ippqub:stdscience_ws",
         "cleanup",
-        #"detrend",
         "distribution",
+        "ippqub:stdscience_ws",
         "pstamp",
-        # "update",
-        # "publishing",
         "registration",
         "stack",
-        # "deepstack",
         "stdscience",
         "summitcopy");
 } else {
     $servers=array(
-	"ippqub2:stdscience_ws",
         "cleanup",
         "distribution",
+        "ippqub2:stdscience_ws",
         "registration",
         "stdscience",
@@ -110,7 +102,5 @@
 }
 
-
-// The Update mode of czartool is obsolete since we don't use the update
-// pantasks. 
+// The Update mode of czartool is obsolete since we don't use the update pantasks. 
 // $selectedMode = $_GET[mode];
 $selectedMode = "stdscience";
@@ -141,5 +131,4 @@
 // tell all servers to stop or run
 if ($allServerCmd) {
-
     foreach ($servers as &$server) serverStopRun($czardb, $server,  $allServerCmd);
 }
@@ -147,5 +136,5 @@
 
 $debug = 0;
-$table = "<table bgcolor=\"#FFFFFF\" width=\"900\" align=\"middle\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\" style=\"font-size:80%\">\n";
+$table = "<table bgcolor=\"#FFFFFF\" width=\"100%\" align=\"middle\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\" style=\"font-size:80%\">\n";
 
 // $labels is generated with sequential integer key values
@@ -187,5 +176,4 @@
 // set up the form
 echo "<form action=\"czartool_labels.php\" method=\"POST\">\n";
-
 echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
 echo "<input type=\"hidden\" name=\"proj\" value=\"$proj\">\n";
@@ -194,39 +182,88 @@
 
 echo "<table border=\"0\">";
-
+// timer begin for main page
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$mainstart = $time;
+
+# headers
 echo "<tr>";
-echo "<td colspan=\"3\" style=\"background-color:#0080c0;\">";
-echo "<h1 align=\"middle\">Czartool</h1>";
-echo "<h2 align=\"middle\">$modeText (change to <a href=\"$link&proj=$newproj\"><font color=\"blue\">$newproj</font></a>)</h2>";
-echo "</td>";
+echo "  <td colspan=\"3\" style=\"background-color:#0080c0;\">";
+echo "  <h1 align=\"middle\">Czartool</h1>";
+echo "  <h2 align=\"middle\">$modeText (change to <a href=\"$link&proj=$newproj\"><font color=\"blue\">$newproj</font></a>)</h2>";
+echo "  </td>";
 echo "</tr>";
 
-// PLOTS
+# table rows
 echo "<tr valign=\"top\">";
-echo "<td style=width:100px;text-align:top;\">";
- # time series plot
-echo "<br><img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br>";
-# log time series plot
-echo "<br><img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=log\"><br>";
- # rate time series plot
-echo "<br><img src=\"czartool_getplot.php?mode=$selectedMode&type=rt&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br>";
- # histogram plot
-# echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=h&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br>";
- # storage plot
-echo "<br><a href=\"czartool_getplot.php?type=sl\"><img title=\"Click to enlarge me\" src=\"czartool_getplot.php?type=s\"></a><br>";
- # storage timeseries
-echo "<br><img src=\"czartool_getplot.php?type=st\"><br>";
- # pantasks server status, if requested
+
+#1st table column for status
+echo "<td style=height:200px;width:800px;text-align:top;\">";
+
+// status table at top
+exec("svnversion /data/ippc64.1/ippitc/ippMonitor", $svnversion);
+$phpversion = phpversion();
+$ganglia = "http://ganglia.pan-starrs.ifa.hawaii.edu";
+$svnlink = "https://svn.pan-starrs.ifa.hawaii.edu/trac/ipp";
+$conflink = "https://confluence.ipp.ifa.hawaii.edu";
+$jiralink = "https://jira.ipp.ifa.hawaii.edu";
+$hsttime1 = date("Y-m-d H:i:s", strtotime("$lastUpdateTime"));
+$utctime1 = gmdate("Y-m-d H:i:s", strtotime("$lastUpdateTime"));
+
 echo "<br>";
- if ($selectedServer && !$serverCmd) showServerStatus($selectedServer);
-echo "</td>";
-
-
-echo "<td style=height:200px;width:10px;text-align:top;\">";
-echo "<td style=height:200px;width:400px;text-align:top;\">";
-
-/////////////////////////////////////////
-// timer begin for status and links
-/////////////////////////////////////////
+echo $table;
+createTableTitle("Status and links", 2);
+echo "<tr><td>ippMonitor Notes </td> 
+          <td> PHP: v.$phpversion 
+  &nbsp|&nbsp <a href=\"$svnlink/browser/trunk/ippMonitor\" target=new><font color=\"blue\">SVN: v.$svnversion[0]</font></a>
+  &nbsp|&nbsp <a href=\"$jiralink/browse/IPP-86\" target=new><font color=\"blue\">Jira</font></a> 
+  &nbsp|&nbsp <a href=\"http://ippmonitor.ipp.ifa.hawaii.edu/ippMonitor/czartool_labels.php?pass=$pass&proj=$proj\"><font color=\"blue\">online</font></a>,
+       &nbsp <a href=\"http://ipp117.ipp.ifa.hawaii.edu/ippMonitor/czartool_labels.php?pass=$pass&proj=$proj\"><font color=\"blue\">dev</font></a>,
+       &nbsp <a href=\"czartool_labels_last.php?pass=$pass&proj=$proj\"><font color=\"blue\">last</font></a>
+       version </td></tr>"; 
+echo "<tr><td>Pan-STARRS Data Store</td>
+          <td><a href=\"https://svn.ifa.hawaii.edu/\" target=new><font color=\"blue\">Home</font></a>
+  &nbsp|&nbsp <a href=\"https://svn.ifa.hawaii.edu/summit/ds/gpc1/\" target=new><font color=\"blue\">GPC1</font></a>
+  &nbsp|&nbsp <a href=\"https://svn.ifa.hawaii.edu/conductorb/ds/gpc2/\" target=new><font color=\"blue\">GPC2</font></a>
+  &nbsp|&nbsp <a href=\"http://ipp.ifa.hawaii.edu/skycoverage.20201110\" target=new><font color=\"blue\">Sky Coverage</font></a></td></tr>";
+echo "<tr><td>Observations Metrics</td>
+          <td><a href=\"https://ps1wiki.ifa.hawaii.edu/data/metrics/index.html\" target=new><font color = \"blue\"> PS1</font></a>
+  &nbsp|&nbsp <a href=\"https://ps1wiki.ifa.hawaii.edu/data/ps2metrics/index.html\"  target=new><font color = \"blue\"> PS2</font></a>
+  &nbsp|&nbsp <a href=\"http://ippmonitor.ipp.ifa.hawaii.edu/ippMonitor/ippMetrics/index.html\" target=new><font color=\"blue\">IPP</font></a></td></tr>";
+echo "<tr><td>Postage Stamp Server</td>
+          <td><a href=\"http://pstamp.ipp.ifa.hawaii.edu/pshome.php\" target=new><font color=\"blue\">Home</font></a>
+  &nbsp|&nbsp <a href=\"http://pstamp.ipp.ifa.hawaii.edu/status.php\" target=new><font color=\"blue\">Status</font></a>
+  &nbsp|&nbsp <a href=\"http://pstamp.ipp.ifa.hawaii.edu/dsroot.php\" target=new><font color=\"blue\">Data Store</font></a></td></tr>";
+echo "<tr><td>IPP Cluster Ganglia Monitor</td>
+          <td><a href=\"$ganglia/?r=hour&s=descending&hc=6&c=IPP%2520Production\" target=new> <font color=\"blue\">Load_reports</font></a> 
+  &nbsp|&nbsp <a href=\"$ganglia/?m=cpu_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\" target=new> <font color=\"blue\">CPU_reports</font></a> 
+  &nbsp|&nbsp <a href=\"$ganglia/?m=mem_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\" target=new> <font color=\"blue\">Memory_reports</font></a></td></tr>";
+echo "<tr><td>Documentations for IPP</td>
+          <td><a href=\"$conflink/pages/viewrecentblogposts.action?key=IPPCZAR\" target=new><font color=\"blue\">Czarblog</font></a>
+  &nbsp|&nbsp <a href=\"$conflink/display/IPPCZAR/IPP-Czaring+Home\" target=new><font color=\"blue\">Confluence</font></a>
+  &nbsp|&nbsp <a href=\"$jiralink/projects/IPP/issues/filter=allissues\" target=new><font color=\"blue\">Jira</font></a>
+  &nbsp|&nbsp <a href=\"$svnlink/\" target=new><font color=\"blue\">trac</font></a></td></tr>";
+echo "<tr><td>Current nightly science status</td> 
+          <td>".getNightlyScienceStatus($czardb, $proj)."</td></tr>"; 
+echo "<tr><td>Czardb last update time</td> 
+          <td> $hsttime1 (HST), $utctime1 (UTC)</td></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, $pass, $proj); // this is slow because of the join between summitExp and rawExp, but not the major one
+
+createChunkDataTable($projectdb);  // this is another part for slowness during nightly processing
+
+createDatesTable($czardb, $proj); 
+
+// Database status
+// timer begin for Database status
 $time = microtime();
 $time = explode(' ', $time);
@@ -234,111 +271,20 @@
 $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";
-
-echo "<br>";
 echo $table;
-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 PHP version: </td>
-          <td>" . phpversion(); 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>";
-echo "<tr><td>Pan-STARRS data overview plots</td>
-          <td><a href=\"http://ipp.ifa.hawaii.edu/skycoverage.20201110\" 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";
-
-// 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>";
+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);
   
-  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_NEBULOUS_THIRD, $REPL_USER_NEBULOUS_THIRD, $REPL_PASSWORD_NEBULOUS_THIRD, $REPL_DBNAME_NEBULOUS_THIRD);
-  showReplicationsStatus($REPL_HOST_NEBULOUS_FOURTH, $REPL_USER_NEBULOUS_FOURTH, $REPL_PASSWORD_NEBULOUS_FOURTH, $REPL_DBNAME_NEBULOUS_FOURTH);
-  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 "<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);
+showReplicationsStatus($REPL_HOST_GPC1_THIRD, $REPL_USER_GPC1_THIRD, $REPL_PASSWORD_GPC1_THIRD, $REPL_DBNAME_GPC1_THIRD);
+showDatabaseStatus($HOST_NEBULOUS, $USER_NEBULOUS, $PASSWORD_NEBULOUS, $DBNAME_NEBULOUS);
+showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_DBNAME_NEBULOUS_SECONDARY);
+showReplicationsStatus($REPL_HOST_NEBULOUS_THIRD, $REPL_USER_NEBULOUS_THIRD, $REPL_PASSWORD_NEBULOUS_THIRD, $REPL_DBNAME_NEBULOUS_THIRD);
+showReplicationsStatus($REPL_HOST_NEBULOUS_FOURTH, $REPL_USER_NEBULOUS_FOURTH, $REPL_PASSWORD_NEBULOUS_FOURTH, $REPL_DBNAME_NEBULOUS_FOURTH);
+showReplicationsStatus($REPL_HOST_DATASTORE_SECONDARY, $REPL_USER_DATASTORE_SECONDARY, $REPL_PASSWORD_DATASTORE_SECONDARY, $REPL_DBNAME_DATASTORE_SECONDARY);
 
 // timer finished
@@ -353,7 +299,7 @@
 echo "</table><br>";
 
-/////////////////////////////////////////
+
+// critical machines status
 // timer begin for critical machines
-/////////////////////////////////////////
 $time = microtime();
 $time = explode(' ', $time);
@@ -361,29 +307,29 @@
 $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);
-
+$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_NAGIOS, $DBNAME_NAGIOS);
+showPingStatus($HOST_HOME, $DBNAME_HOME);
+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);
+showPingStatus($HOST_PROXY, $DBNAME_PROXY);
+showPingStatus($HOST_SVN, $DBNAME_SVN);
+showPingStatus($HOST_CONFLUENCE, $DBNAME_CONFLUENCE);
+//  echo "<td>ippc70 (apache node) <td> $PingStatus <td> 0 seconds ";  // comment out if ippc70 is back
 // timer finished
 echo "<tr><th colspan=3>";
@@ -396,12 +342,56 @@
 echo "</th></tr>";
 echo "</table><br>";
-    
+
+createServersTable($pass, $proj,$selectedMode,$czardb, $servers, $selectedLabel, $selectedStage, $plotType); // this was the major slowness part due to large table in czardb
+
+# pantasks server status, if requested
+if ($selectedServer && !$serverCmd) showServerStatus($selectedServer, $proj);
+
+#2nd table column for space
+echo "<td style=height:200px;width: 10px;text-align:top;\"><br>";
+
+#3rd table column for plots
+echo "<td style=height:200px;width:600px;text-align:top;\"><br>";
+# plots
+if ($selectedStage == "all_stages" & $selectedLabel == "all") { 
+   # with all stages and all labels, the rate query is too slow so I use the old method until it get improved. CCL 20210117
+   # gnuplots
+   # time series plot
+   echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br><br>";
+   echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=log\"><br><br>";
+   # rate series plot
+   echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=rt&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br><br>";
+} else {
+   # google chart
+   # time series plot
+   echo Gettimeseries($czardb, $selectedMode, $selectedLabel, $proj, $selectedStage);
+   # rate series plot
+   echo Getrate($czardb, $selectedMode, $selectedLabel, $proj, $selectedStage);
+}
+
+# storage timeseries
+echo getSpaces($czardb);
+# storage plot
+echo getHosts($czardb);
+
+# timer for main page end
+echo "<tr><th colspan=3>";
+$time = microtime();
+$time = explode(' ', $time);
+$time = $time[1] + $time[0];
+$finish = $time;
+$total_time = round(($finish - $mainstart), 3);
+echo "overall loading in $total_time seconds.";
+echo "</th></tr>";
+echo "</table>";
 
 menu_end();
 
 
-#############################################################################
-#############################  Functions Below  #############################
-#############################################################################
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//                               Functions                                 //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
 
 ###########################################################################
@@ -436,16 +426,11 @@
     // list the results
     while ($qry->fetchInto($row)) {
-
         echo "<tr>";
-
         echo "<td>$row[0]</td>";
         echo "<td>$row[1]</td>";
         echo "<td>$row[2]</td>";
-        
         echo "</tr>";
     }
-
     echo "</table>\n";
-
 }
 
@@ -480,11 +465,9 @@
     #do a query of raw/chip/cam/warp counts for this night, split by chunk. 
     #we need to do a subquery to find the total number of skycells in warpSkyfile, as well as the number of those with a bad quality
-    $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad,suba.uniNvis1,suba.uniNvis2,suba.uniNvis3,suba.uniNvis4 FROM ";
+    $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad FROM ";
     $query .= "    (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(if(rawExp.comment LIKE '%visit 1%',1,NULL)) AS Nvis1,";
     $query .= "    count(if(rawExp.comment LIKE '%visit 2%',1,NULL)) AS Nvis2,count(if(rawExp.comment LIKE '%visit 3%',1,NULL)) AS Nvis3,";
     $query .= "    count(if(rawExp.comment LIKE '%visit 4%',1,NULL)) AS Nvis4, count(if(camProcessedExp.sigma_ra <= 5 AND camProcessedExp.sigma_dec <= 5 AND camProcessedExp.quality = 0,1,NULL)) AS Ncamgood,";
-    $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad, COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 1%' THEN rawExp.comment END) AS uniNvis1,";
-    $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 2%' THEN rawExp.comment END) AS uniNvis2,COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 3%' THEN rawExp.comment END) AS uniNvis3,";
-    $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 4%' THEN rawExp.comment END) AS uniNvis4";
+    $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad";
     $query .= "    FROM rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) JOIN camProcessedExp USING (cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id)";
     $query .= "    WHERE dateobs like '$date%' AND exp_id > $refExpID[0] AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%'";
@@ -540,8 +523,4 @@
         $NexpWWdiff = 0;
         $Npubwarps = 0;
-        $uniNvis1 = 0;
-        $uniNvis2 = 0;
-        $uniNvis3 = 0;
-        $uniNvis4 = 0;
 
         $chunkname = $row[0];
@@ -554,8 +533,4 @@
         if($row[7] > 0) $Nwarpgood = $row[7];
         if($row[8] > 0) $Nwarpbad = $row[8];
-        if($row[9] > 0) $uniNvis1 = $row[9];
-        if($row[10] > 0) $uniNvis2 = $row[10];
-        if($row[11] > 0) $uniNvis3 = $row[11];
-        if($row[12] > 0) $uniNvis4 = $row[12];
 
         #set flags if present
@@ -629,11 +604,12 @@
         if(($NWWdiffbad >= 1) or ($NWSdiffbad >= 1)) $baddiffflag = 1;
 
-        if (($uniNvis1 != $uniNvis2) or ($uniNvis1 != $uniNvis3) or ($uniNvis1 != $uniNvis4)) {
+        if ($Nvis1 != $Nvis4) {
           if ($NWWdiffpub != $NexpWWdiff) $complete = "chunk incomplete, not done";  
           if ($NWWdiffpub == $NexpWWdiff) $complete = "chunk incomplete, done";  
         }
-        if (($uniNvis1 == $uniNvis2) and ($uniNvis1 == $uniNvis3) and ($uniNvis1 == $uniNvis4)) {
+        if ($Nvis1 == $Nvis4) {
           if ($NWWdiffpub != $NexpWWdiff) $complete = "chunk complete, not done";  
           if ($NWWdiffpub == $NexpWWdiff) $complete = "chunk complete, done";  
+
         }
 
@@ -920,6 +896,5 @@
         $pubLabelsExist, 
         $stages, 
-        $selectedState, 
-        $selectedLabel, $selectedStage, $plotType) {
+        $selectedState, $selectedLabel, $selectedStage, $plotType) {
 
     // timer start
@@ -951,5 +926,5 @@
     createFormattedTableCell(($selectedStage != "all_stages"), $link, "All stages", 0, "$columnHeaderColor");
 
-    #echo "<th>Label (in order of priority)</th>";
+    //echo "<th>Label (in order of priority)</th>";
     foreach ($stages as &$stage) {
 
@@ -965,5 +940,5 @@
 
         createFormattedTableCell($showLink, $link, $stage, 0, "$columnHeaderColor");
-#        createTableColumnHeader("Dates");
+        #createTableColumnHeader("Dates");
     }
 
@@ -1006,26 +981,26 @@
         foreach ($stages as &$stage) {
           // Note: Do not include the state for chip, cam, and warp so that both new and update faults are listed
-	  $myTable    = $mainTable[$stage];
-	  $myFailures = $getFailures[$stage];
+      $myTable    = $mainTable[$stage];
+      $myFailures = $getFailures[$stage];
           # echo "myTable: $myTable";
 
-	  if ("$myFailures" == "NONE") {
+      if ("$myFailures" == "NONE") {
             $link = $defaultlink;
           } else {
             $link = $myFailures . "?pass=" . $pass . "&proj=" . $proj . "&" . $myTable . ".label=" . $thisLabel;
-	    if ($addSearchState[$stage]) {
+        if ($addSearchState[$stage]) {
               // Note: Do not include the state for chip, cam, and warp so that both new and update faults are listed
               $link .= "&" . $myTable . ".state=" . $searchState;
             }
           }
-	  // echo "getStateAndFaults $db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults<br>";
-	  getStateAndFaults($db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults);
-
-	  $cellcolor = 0;
-	  if ("$stage" == "dist") { 
-	    $cellcolor = (!$isUpdate && !$distributing) ? "gray" : 0;
+      // echo "getStateAndFaults $db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults<br>";
+      getStateAndFaults($db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults);
+
+      $cellcolor = 0;
+      if ("$stage" == "dist") { 
+        $cellcolor = (!$isUpdate && !$distributing) ? "gray" : 0;
           }
           if ("$stage" == "pub") {
-	    $cellcolor = (!$isUpdate && !$publishing) ? "gray" : 0;
+        $cellcolor = (!$isUpdate && !$publishing) ? "gray" : 0;
           }
           createFormattedTableCell($anyFaults, $link, $str, $anyFaults, $cellcolor);
@@ -1232,5 +1207,5 @@
 
     // timer finished
-    echo "<tr><th colspan=11>";
+#    echo "<tr><th colspan=11>";
     $time = microtime();
     $time = explode(' ', $time);
@@ -1238,7 +1213,7 @@
     $finish = $time;
     $total_time = round(($finish - $start), 3);
-    echo "loading in $total_time seconds.";
+#    echo "loading in $total_time seconds.";
     $start= $finish;
-    echo "</th></tr>";
+#    echo "</th></tr>";
     echo "</table><br>";
 
@@ -1261,7 +1236,5 @@
     $firstIn = true;
     while ($qry->fetchInto($row)) {
-
         if ($firstIn) {
-
             $dates = $row[0];
             $firstIn = false;
@@ -1300,25 +1273,4 @@
     createTableColumnHeader("Alive?");
     createTableColumnHeader("Running?");
-
-    //write_header_cell($class, "Server");
-    //write_header_cell($class, "Alive?");
-    //$link = "czartool_labels.php?pass=".$pass
-    //    ."&proj=".$proj
-    //    ."&label=".$selectedLabel
-    //    ."&stage=".$selectedStage
-    //    ."&plottype=".$plotType
-    //    ."&allservercmd=stop";
-
-    //$link = ""; # TODO removed links temporarily
-    //    write_table_cell($class, '%s', $link, "Stop all");
-    //$link = "czartool_labels.php?pass=".$pass
-    //    ."&proj=".$proj
-    //    ."&label=".$selectedLabel
-    //    ."&stage=".$selectedStage
-    //    ."&plottype=".$plotType
-    //    ."&allservercmd=run";
-
-    //$link = ""; # TODO removed links temporarily
-    //    write_table_cell($class, '%s', $link, "Run all");
     echo "</tr>\n";
 
@@ -1336,42 +1288,7 @@
             ."&plottype=".$plotType;
 
-        #$link = ""; # TODO removed links temporarily
-        //write_table_cell($class, '%s', $link, $server);
-        //write_table_cell($class, '%s', "", $alive ? "yes" : "NO");
-        //echo "<td>$server</td>";
         createFormattedTableCell(1, $link, $server, 0, 0);
         createFormattedTableCell(0, "", $alive ? "yes" : "NO", !$alive, 0);
         createFormattedTableCell(0, "", $running ? "yes" : "NO", !$running, 0);
-
-        //if ($alive) {
-
-          //  $link = "czartool_labels.php?pass=".$pass
-            //    ."&proj=".$proj
-              //  ."&label=".$selectedLabel
-              //  ."&stage=".$selectedStage
-              //  ."&plottype=".$plotType
-              //  ."&server=".$server
-              //  ."&servercmd=";
-
-            //if ($running)  {
-
-              //  $link = $link . "stop";
-              //  $link = ""; # TODO removed links temporarily
-              //      write_table_cell($class, '%s', $link, "stop");
-              //  write_table_cell($class, '%s', "", "");
-           // }
-           // else {
-
-             //   $link = $link . "run";
-              //  write_table_cell($class, '%s', "", "");
-              //  $link = ""; # TODO removed links temporarily
-               //     write_table_cell($class, '%s', $link, "run");
-           // }
-       // }
-       // else {
-
-         //   write_table_cell($class, '%s', "", "");
-         //   write_table_cell($class, '%s', "", "");
-       // }
         echo "</tr>\n";
     }
@@ -1464,10 +1381,10 @@
 #
 ###########################################################################
-function showServerStatus($server) {
-
-    echo "<p> Status for $server server </p>";
+function showServerStatus($server, $proj) {
+
+    echo "<p> $server server status for $proj</p>";
 
     $results=array();
-    exec("czartool_getServerStatus.pl -s $server", $results, $status);
+    exec("czartool_getServerStatus.pl -s $server -p $proj", $results, $status);
 
     foreach ($results as &$line) {
@@ -1475,5 +1392,4 @@
         echo "$line\n";
         echo "</pre>\n";
-
     }
 }
@@ -1583,5 +1499,5 @@
 #
 ###########################################################################
-function createSummitDataTable2($projectdb) {
+function createSummitDataTable2($projectdb, $pass, $proj) {
 
     // timer start
@@ -1601,10 +1517,12 @@
     echo $table;
     echo "<tr>";
-    createTableTitle("Data status tonight $date (UT) <br> current time $datetime", 4);
+    createTableTitle("Data status tonight $date <br> current time $datetime (UTC)", 4);
     echo "<tr>";
-    createTableColumnHeader("Exp_type at summit");
-    createTableColumnHeader("Status at summit");
-    createTableColumnHeader("Status at mhpcc");
-    createTableColumnHeader("Number");
+
+    createTableColumnHeader("Exposure type");
+    createTableColumnHeader("<a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=summitExp\"><font color=\"blue\">summitExp status</font></a>");
+    createTableColumnHeader("<a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=downloadExp\"><font color=\"blue\">downloadExp status</font></a>");
+    createTableColumnHeader("<a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=rawExp\"><font color=\"blue\">rawExp </a>/
+                             <a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=newExp\"><font color=\"blue\"> newExp</font></a>");
     $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 
@@ -1614,14 +1532,11 @@
         if ($tmp[1] == NULL) { 
           echo  "<tr><td>$tmp[0]<td> null <td> null <td bgcolor=\"yellow\"> <font color=\"red\">$tmp[3]";
-        }
-        else {
+        } else {
           if ($tmp[1] == 'run') { 
             echo  "<tr><td>$tmp[0]<td> loading <td> null <td bgcolor=$columnHeaderColor> <font color=\"red\">$tmp[3]"; 
-          }
-          else {
+          } else {
             if ($tmp[2] == NULL) { 
               echo  "<tr><td>$tmp[0] <td> $tmp[1] <td> loading <td bgcolor=$columnHeaderColor> <font color=\"blue\">$tmp[3]";
-            }
-            else {
+            } else {
               echo  "<tr><td>$tmp[0]<td> $tmp[1] <td> downloaded <td> $tmp[3]";
             }
@@ -1630,5 +1545,5 @@
     }
 
-    echo "<tr><th colspan=4>Last night $datem1 (UT)";
+    echo "<tr><th colspan=4>Last night $datem1 (UTC)";
     $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 
@@ -1638,14 +1553,11 @@
         if ($tmp[1] == NULL) { 
           echo  "<tr><td>$tmp[0]<td> null <td> null <td bgcolor=\"yellow\"> <font color=\"red\">$tmp[3]";
-        }
-        else {
+        } else {
           if ($tmp[1] == 'run') { 
             echo  "<tr><td>$tmp[0]<td> loading <td> null <td bgcolor=$columnHeaderColor> <font color=\"red\">$tmp[3]"; 
-          }
-          else {
+          } else {
             if ($tmp[2] == NULL) { 
               echo  "<tr><td>$tmp[0] <td> $tmp[1] <td> loading <td bgcolor=$columnHeaderColor> <font color=\"blue\">$tmp[3]";
-            }
-            else {
+            } else {
               echo  "<tr><td>$tmp[0]<td> $tmp[1] <td> downloaded <td> $tmp[3]";
             }
@@ -1665,110 +1577,1125 @@
     echo "</table><br>";
 }
-////////////////////////////////////////////////////////////////////////////////
-///                         no needed functions                              ///
-////////////////////////////////////////////////////////////////////////////////
-//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>";
-//}
+###########################################################################
+#
+# Gets disk status
+#
+###########################################################################
+function getHosts($db) {
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
+    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
+    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640px\">"; 
+    echo "  <div id=\"disk_div\" style=\"width:640px; height:1200px\"></div>";
+    echo "  <div class=\"overlay\" style=\"position: absolute; width: 100px; top: 35px; right: 20px;\">";
+    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #00ff00\"><center>Free</div>";
+    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ffff00\"><center>Used</div>";
+    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ff0000\"><center>> 97% limit</div>";
+    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #bbbbbb\"><center>Down | Repair</div>";
+    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ffffff\"><center>Power Off</div>";
+    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ffffff\"><center>
+                 <a href=\"https://confluence.ipp.ifa.hawaii.edu/display/IKB/IPP+Hardware+Status#IPPHardwareStatus-StorageNodes\" target=new><font color=\"blue\">Notes</font></a></div>";
+    echo "  </div>";
+    echo "</div>";
+
+    echo "<script type=\"text/javascript\">";
+    echo "google.charts.load('current', {packages: ['corechart', 'bar']});";
+    echo "google.charts.setOnLoadCallback(drawBarColors);";
+    echo "function drawBarColors() {";
+    echo "  var data = google.visualization.arrayToDataTable([";
+    echo "    ['Host', ";
+    echo "     'used', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}, ";
+    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";
+    if ($debug) {echo "$sql<br>";}
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+    # not sure why neb-host doesn't work on ipp113 CCL.20210216
+    exec("neb-host |cut -b 17-30,86-", $hostnoteall);
+    while ($qry->fetchInto($row)) {
+        list($host, $total, $available, $used, $writable, $readable, $ratio) = $row;
+       $hostnotes = preg_grep("/$host/", $hostnoteall);
+       $hostnote = array_values($hostnotes);
+       if ($writable == 1 && $readable == 1) {
+          if ($ratio >= 97) {
+            # space used over limits, up mode (read/write ok).
+            echo "[ \"$host\", ";
+            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ff0000;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", ";
+            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],";
+          }
+          else {
+            # enough space, up mode (read/write ok).
+            echo "[ \"$host\", ";
+            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", ";
+            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],";
+         }
+       }
+       else if ($writable == 0 && $readable == 1) {
+          if ($ratio >= 97) {
+            # space used over limits, repair mode (read only).
+            echo "[ \"$host\", ";
+            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ff0000;\", \"<i><b>$host: $ratio% of $total TB used<br><font color=red>$hostnote[0]\", ";
+            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
+          }
+          else {
+            # enough space, but hosts are unstable, repair mode (read only).
+            echo "[ \"$host\", ";
+            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used<br>$hostnote[0]\", ";
+            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
+          }
+       }
+       else {
+            # down mode (can't read or write).
+            echo "[ \"$host\", ";
+            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $ratio% used<br>$hostnote[0]\", ";
+            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
+       }
+    }
+   echo "  ]);";
+   echo "   var options = {";
+   echo "     title: 'Nebulous Disk Use across IPP Clusters',";
+   echo "     titleTextStyle: {color: 'black', fontSize: 15},";
+   echo "     width: '100%',";
+   echo "     height: '100%',";
+   echo "     tooltip: {isHtml: true},";
+   echo "     legend: { position: 'none',";
+   echo "               alignment: 'end',";
+   echo "               maxLines: 3},";
+   echo "     hAxis: {  title: 'Space (TB)',";
+   echo "               gridlines: {count: 10}";
+   echo "     },";
+   echo "     bar: { groupWidth: '95%' },";
+   echo "     chartArea: {left:70, top:30, right:20, bottom:40},";
+   echo "     fontSize: 12,";
+   echo "     isStacked: true";
+   echo "   };";
+   echo "   var chart = new google.visualization.BarChart(document.getElementById('disk_div'));";
+   echo "   chart.draw(data, options);";
+   echo " }";
+   echo "</script>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    $start= $finish;
+    echo "<center>loading in $total_time seconds<br></center>";
+}
+
+###########################################################################
+#
+# Gets disk spaces status
+#
+###########################################################################
+function getSpaces($db) {
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    $db->query("SELECT sum(format(available, 2)) FROM hosts where host like 'ippb%'")->fetchInto($row);
+    $ippbusable = $row[0];
+    $db->query("SELECT sum(format(available, 2)) FROM hosts where host like 'ippb%' and writable = 1")->fetchInto($row);
+    $ippbfree = $row[0];
+
+    $db->query("SELECT sum(format(available, 2)) FROM hosts where host not like 'ippb%'")->fetchInto($row);
+    $ippusable = $row[0];
+    $db->query("SELECT sum(format(available, 2)) FROM hosts where host not like 'ippb%' and writable = 1")->fetchInto($row);
+    $ippfree = $row[0];
+
+    $sql = "select format(used/total*100,1), usable from cluster_space order by timestamp desc limit 1;";
+    if ($debug) {echo "$sql<br>";}
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+    $qry->fetchInto($row);
+    $allocated = $row[0];
+    $usable    = $row[1];
+
+    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
+    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
+    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640; height:400\">"; 
+    echo "  <div id=\"space_div\" style=\"width:640; \"></div>";
+    echo "  <div class=\"overlay\" style=\"position: absolute; width: 400px; bottom: 60px; left: 85px;\">";
+    echo "    <div style=\"font-size: 16px; color:#0000ff; background-color:#ffffff\"><b>ipp + ippb nodes: $ippusable + $ippbusable TB (latest usable)</b></div>";
+    echo "    <div style=\"font-size: 16px; color:#33a532; background-color:#ffffff\"><b>ipp + ippb nodes: $ippfree + $ippbfree TB (latest free)</b></div>";
+    echo "  </div>";
+    echo "</div>";
+
+    echo "<script type=\"text/javascript\">";
+    echo "google.charts.load('current', {packages: ['corechart']});";
+    echo "google.charts.setOnLoadCallback(drawChart);";
+    echo "function drawChart() {";
+    echo "  var data = new google.visualization.DataTable();";
+    echo "        data.addColumn('datetime', 'Day');";
+    echo "        data.addColumn('number', 'Usable');";
+    echo "        data.addColumn('number', 'Free');";
+    echo "   data.addRows([";
+    $interval = 10;
+    $sql = "select sub.dated, sub.usable, sub.available from (select date_format(timestamp, \"%Y.%m.%d.%H.%i\") as dated, usable, available from cluster_space where timestamp > curdate() - INTERVAL $interval DAY) as sub group by dated;";
+    if ($debug) {echo "$sql<br>";}
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+    while ($qry->fetchInto($row)) {
+        $tsp = explode('.', $row[0]);
+	$mon = $tsp[1]-1;
+        $timestamp = $row[0];
+        $usable    = $row[1];
+        $available = $row[2];
+#	new Date(Year, Month, Day, Hours, Minutes, Seconds, Milliseconds)
+       echo "[new Date($tsp[0], $mon, $tsp[2], $tsp[3], $tsp[4]), $usable, $available],";
+    }
+   echo "  ]);";
+   echo "   var options = {";
+   echo "      chart: {";  
+   echo "               position: 'center', " ;
+   echo "              },";
+   echo "     title: 'Total Available Cluster Space in the Past $interval Days ($allocated% of total allocated)',";
+   echo "     titleTextStyle: {color: 'black', fontSize: 15},";
+   echo "     width: '100%',";
+   echo "     height: 400,";
+   echo "     legend: { position: 'top',";
+   echo "               alignment: 'center',";
+   echo "              },";
+   echo "     lineWidth: 2, ";
+   echo "     series: {";
+   echo "         0: { color: '#0000ff', lineWidth: 3 },      ";
+   echo "         1: { color: '#33a532', lineWidth: 3 },      ";
+   echo "              },";
+   echo "     hAxis: {  ";
+   echo "             title: 'Date/Time (HST)',";
+   echo "             format: 'MMM dd',";
+   echo "            gridlines: {count: -1},"; 
+   echo "     },";
+   echo "     vAxis: {  ";
+   echo "                  title: 'Available (TB)',";
+   echo "     viewWindow: {   min: 500    },  ";
+   echo "     },";
+   echo "     chartArea: {left:80, top:50, right:20, bottom:50},";
+   echo "     fontSize: 12,";
+   echo "   };";
+   echo "   var chart = new google.visualization.LineChart(document.getElementById('space_div'));";
+   echo "   chart.draw(data, options);";
+   echo " }";
+   echo "</script>";
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    $start= $finish;
+    echo "<center>loading in $total_time seconds<br></center>";
+}
+
+###########################################################################
+#
+# Gets time series plot
+#
+###########################################################################
+function Gettimeseries($db, $selectedMode, $selectedLabel, $proj, $selectedStage) {
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    // google chart javascript source code
+    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
+    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
+
+    // if button doesn't work, maybe plot linear and log chart separately
+    #echo "<div id=\"time_series_div_lin\" style=\"width:640; height:400;\"></div><br>";
+    #echo "<div id=\"time_series_div_log\" style=\"width:640; height:400;\"></div>";
+    echo "<div id=\"time_series_div\" style=\"width:640; height:400;\"></div>";
+
+    // click button to switch linear or log plot, but sometimes it doesn't work well.
+    echo "<div><center><button id=\"linlogchart\"></button></div>";
+
+    // javascript start
+    echo "<script type=\"text/javascript\">";
+    echo "google.charts.load('current', {'packages': ['corechart', 'line']});";
+    echo "google.charts.setOnLoadCallback(drawChart);";
+    // draw funciton start
+    echo "function drawChart() {";
+    echo "  var button   = document.getElementById('linlogchart');";  // for linear and log button
+    echo "  var chartDiv = document.getElementById('time_series_div');"; 
+    echo "  var data = new google.visualization.DataTable();";
+    
+    // plot data
+    $dayshift = -0; // query back to N-th day
+    // check labels
+    if ($selectedLabel == "all") { 
+      $selectedLabel = "stdscience_labels";
+      $plotlabel = "all"; 
+    } else {
+      $plotlabel = $selectedLabel; 
+    }
+
+    // check stages
+    if ($selectedStage == "all_stages") {
+      $plotstage = "all";
+      if ($selectedLabel == "stdscience_labels") {
+        // all stages and all labels
+        $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
+        $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, "; 
+        $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, "; 
+        $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, "; 
+        $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, "; 
+        $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, "; 
+        $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, "; 
+        $plotseries .= "             10: { color: 'cyan'    , lineWidth: 2, lineDashStyle: [3, 4]}, "; 
+        $plotseries .= "             11: { color: '#c51b7d' , lineWidth: 2, lineDashStyle: [3, 4]}, "; 
+        $plotseries .= "             12: { color: '#b15928' , lineWidth: 2, lineDashStyle: [3, 4]}, "; 
+        $plotseries .= "             13: { color: '#000004' , lineWidth: 2, lineDashStyle: [3, 4]}, },";
+        
+        // data header
+        echo "  data.addColumn('datetime',        'Time');";
+        echo "  data.addColumn(  'number',        'chip'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'cam'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'fake'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'warp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',       'stack'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'staticsky'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'diff'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'fullforce'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'dist'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'pub'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'summitExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number', 'downloadExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',      'newExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',      'rawExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        // data content
+        echo "  data.addRows([";
+  
+        //  query data from czardb
+        $sql = "select date_format(addtime(rawrun.timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, summrun.proc as sumproc, downrun.proc as downproc, newrun.proc as newproc, rawrun.proc as rawproc, timestamp";
+        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from rawExp   ,   (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as rawrun                "; 
+        $sql.= " join (select @rank2:=@rank2+1 AS rank,            processed as proc from newExp   ,   (select @rank2:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as newrun   using (rank) ";
+        $sql.= " join (select @rank3:=@rank3+1 AS rank,            processed as proc from summitExp,   (select @rank3:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as summrun  using (rank) ";
+        $sql.= " join (select @rank4:=@rank4+1 AS rank,            processed as proc from downloadExp, (select @rank4:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as downrun  using (rank) ";
+        $sql.= " join (select @rank5:=@rank5+1 AS rank,            processed as proc from chip,        (select @rank5:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as chiprun  using (rank) ";
+        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as camrun   using (rank) ";
+        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as fakerun  using (rank) ";
+        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as warprun  using (rank) ";
+        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as stackrun using (rank) ";
+        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as statrun  using (rank) ";
+        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as diffrun  using (rank) ";
+        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as ffrun    using (rank) ";
+        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as distrun  using (rank) ";
+        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as pubrun   using (rank);";
+
+        // define last process and total process
+        list($lastproc1 , $sumproc1 ) = array(-1, 0);
+        list($lastproc2 , $sumproc2 ) = array(-1, 0);
+        list($lastproc3 , $sumproc3 ) = array(-1, 0);
+        list($lastproc4 , $sumproc4 ) = array(-1, 0);
+        list($lastproc5 , $sumproc5 ) = array(-1, 0);
+        list($lastproc6 , $sumproc6 ) = array(-1, 0);
+        list($lastproc7 , $sumproc7 ) = array(-1, 0);
+        list($lastproc8 , $sumproc8 ) = array(-1, 0);
+        list($lastproc9 , $sumproc9 ) = array(-1, 0);
+        list($lastproc10, $sumproc10) = array(-1, 0);
+        list($lastproc11, $sumproc11) = array(-1, 0);
+        list($lastproc12, $sumproc12) = array(-1, 0);
+        list($lastproc13, $sumproc13) = array(-1, 0);
+        list($lastproc14, $sumproc14) = array(-1, 0);
+
+        // query from czardb  
+        if ($debug) {echo "$sql<br>";}
+        $qry = $db->query($sql);
+        if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+        // define plot title 
+        //$plottitle = "title: 'Items + N x 150 offset',";
+        $plottitle = "title: 'Items',";
+
+        // loading all the data
+        while ($qry->fetchInto($row)) {
+          // get UTC time info.
+          $tsp = explode('.', $row[0]);
+
+          // get processing info. from all stages and get time series.
+          $thisproc1  = $row[1] ; list($thisproc1 , $lastproc1 , $sumproc1 ) = gettotalprocessed($thisproc1 , $lastproc1 , $sumproc1 ); // chip
+          $thisproc2  = $row[2] ; list($thisproc2 , $lastproc2 , $sumproc2 ) = gettotalprocessed($thisproc2 , $lastproc2 , $sumproc2 ); // cam
+          $thisproc3  = $row[3] ; list($thisproc3 , $lastproc3 , $sumproc3 ) = gettotalprocessed($thisproc3 , $lastproc3 , $sumproc3 ); // fake
+          $thisproc4  = $row[4] ; list($thisproc4 , $lastproc4 , $sumproc4 ) = gettotalprocessed($thisproc4 , $lastproc4 , $sumproc4 ); // warp
+          $thisproc5  = $row[5] ; list($thisproc5 , $lastproc5 , $sumproc5 ) = gettotalprocessed($thisproc5 , $lastproc5 , $sumproc5 ); // stack
+          $thisproc6  = $row[6] ; list($thisproc6 , $lastproc6 , $sumproc6 ) = gettotalprocessed($thisproc6 , $lastproc6 , $sumproc6 ); // staticsky
+          $thisproc7  = $row[7] ; list($thisproc7 , $lastproc7 , $sumproc7 ) = gettotalprocessed($thisproc7 , $lastproc7 , $sumproc7 ); // diff
+          $thisproc8  = $row[8] ; list($thisproc8 , $lastproc8 , $sumproc8 ) = gettotalprocessed($thisproc8 , $lastproc8 , $sumproc8 ); // fullforce
+          $thisproc9  = $row[9] ; list($thisproc9 , $lastproc9 , $sumproc9 ) = gettotalprocessed($thisproc9 , $lastproc9 , $sumproc9 ); // dist
+          $thisproc10 = $row[10]; list($thisproc10, $lastproc10, $sumproc10) = gettotalprocessed($thisproc10, $lastproc10, $sumproc10); // pub
+          $thisproc11 = $row[11]; list($thisproc11, $lastproc11, $sumproc11) = gettotalprocessed($thisproc11, $lastproc11, $sumproc11); // rawExp
+          $thisproc12 = $row[12]; list($thisproc12, $lastproc12, $sumproc12) = gettotalprocessed($thisproc12, $lastproc12, $sumproc12); // newExp
+          $thisproc13 = $row[13]; list($thisproc13, $lastproc13, $sumproc13) = gettotalprocessed($thisproc13, $lastproc13, $sumproc13); // summitExp
+          $thisproc14 = $row[14]; list($thisproc14, $lastproc14, $sumproc14) = gettotalprocessed($thisproc14, $lastproc14, $sumproc14); // downloadExp
+
+          // get HST time info.
+          $hsttime    = $row[15];
+
+          // data content
+          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
+          echo "$sumproc1 , \"<i><b>$hsttime (HST) $sumproc1   chip        </i></b> \",";  //+ 7*150 chip
+          echo "$sumproc2 , \"<i><b>$hsttime (HST) $sumproc2   cam         </i></b> \",";  //+ 6*150 cam
+          echo "$sumproc3 , \"<i><b>$hsttime (HST) $sumproc3   fake        </i></b> \",";  //+ 5*150 fake
+          echo "$sumproc4 , \"<i><b>$hsttime (HST) $sumproc4   warp        </i></b> \",";  //+ 4*150 warp
+          echo "$sumproc5 , \"<i><b>$hsttime (HST) $sumproc5   stack       </i></b> \",";  //+ 0*150 stack
+          echo "$sumproc6 , \"<i><b>$hsttime (HST) $sumproc6   staticsky   </i></b> \",";  //+ 0*150 staticsky
+          echo "$sumproc7 , \"<i><b>$hsttime (HST) $sumproc7   diff        </i></b> \",";  //+10*150 diff
+          echo "$sumproc8 , \"<i><b>$hsttime (HST) $sumproc8   fullforce   </i></b> \",";  //+ 0*150 fullforce
+          echo "$sumproc9 , \"<i><b>$hsttime (HST) $sumproc9   dist        </i></b> \",";  //+ 8*150 dist
+          echo "$sumproc10, \"<i><b>$hsttime (HST) $sumproc10  pub         </i></b> \",";  //+ 9*150 pub
+          echo "$sumproc11, \"<i><b>$hsttime (HST) $sumproc11  summitExp   </i></b> \",";  //+ 3*150 summitExp
+          echo "$sumproc12, \"<i><b>$hsttime (HST) $sumproc12  downloadExp </i></b> \",";  //+ 2*150 downloadExp
+          echo "$sumproc13, \"<i><b>$hsttime (HST) $sumproc13  newExp      </i></b> \",";  //+ 1*150 newExp
+          echo "$sumproc14, \"<i><b>$hsttime (HST) $sumproc14  rawExp      </i></b> \" ";  //+ 0*150 rawExp
+          echo "], ";
+        }
+      } else {
+        // all stages, but selected label
+        $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
+        $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, "; 
+        $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, "; 
+        $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, "; 
+        $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, "; 
+        $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, "; 
+        $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, },"; 
+
+        // data header
+        echo "  data.addColumn('datetime',        'Time');";
+        echo "  data.addColumn(  'number',        'chip'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'cam'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'fake'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'warp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',       'stack'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'staticsky'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'diff'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'fullforce'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'dist'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'pub'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+
+        // data content
+        echo "  data.addRows([";
+  
+        //  query data from czardb
+        $sql = "select date_format(addtime(chiprun.timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, timestamp";
+        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from chip,        (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as chiprun              "; 
+        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as camrun   using (rank) ";
+        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as fakerun  using (rank) ";
+        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as warprun  using (rank) ";
+        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as stackrun using (rank) ";
+        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as statrun  using (rank) ";
+        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as diffrun  using (rank) ";
+        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as ffrun    using (rank) ";
+        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as distrun  using (rank) ";
+        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as pubrun   using (rank);";
+  
+        // define last process and total process
+        list($lastproc1 , $sumproc1 ) = array(-1, 0);
+        list($lastproc2 , $sumproc2 ) = array(-1, 0);
+        list($lastproc3 , $sumproc3 ) = array(-1, 0);
+        list($lastproc4 , $sumproc4 ) = array(-1, 0);
+        list($lastproc5 , $sumproc5 ) = array(-1, 0);
+        list($lastproc6 , $sumproc6 ) = array(-1, 0);
+        list($lastproc7 , $sumproc7 ) = array(-1, 0);
+        list($lastproc8 , $sumproc8 ) = array(-1, 0);
+        list($lastproc9 , $sumproc9 ) = array(-1, 0);
+        list($lastproc10, $sumproc10) = array(-1, 0);
+
+        // query from czardb  
+        if ($debug) {echo "$sql<br>";}
+        $qry = $db->query($sql);
+        if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+        // define plot title 
+        //$plottitle = "title: 'Items + N x 30 offset',";
+        $plottitle = "title: 'Items',";
+
+        // loading all the data
+        while ($qry->fetchInto($row)) {
+          // get UTC time info.
+          $tsp = explode('.', $row[0]);
+
+          // get processing info. from all stages and get time series.
+          $thisproc1  = $row[1] ; list($thisproc1 , $lastproc1 , $sumproc1 ) = gettotalprocessed($thisproc1 , $lastproc1 , $sumproc1 ); // chip
+          $thisproc2  = $row[2] ; list($thisproc2 , $lastproc2 , $sumproc2 ) = gettotalprocessed($thisproc2 , $lastproc2 , $sumproc2 ); // cam 
+          $thisproc3  = $row[3] ; list($thisproc3 , $lastproc3 , $sumproc3 ) = gettotalprocessed($thisproc3 , $lastproc3 , $sumproc3 ); // fake
+          $thisproc4  = $row[4] ; list($thisproc4 , $lastproc4 , $sumproc4 ) = gettotalprocessed($thisproc4 , $lastproc4 , $sumproc4 ); // warp
+          $thisproc5  = $row[5] ; list($thisproc5 , $lastproc5 , $sumproc5 ) = gettotalprocessed($thisproc5 , $lastproc5 , $sumproc5 ); // stack
+          $thisproc6  = $row[6] ; list($thisproc6 , $lastproc6 , $sumproc6 ) = gettotalprocessed($thisproc6 , $lastproc6 , $sumproc6 ); // staticsky
+          $thisproc7  = $row[7] ; list($thisproc7 , $lastproc7 , $sumproc7 ) = gettotalprocessed($thisproc7 , $lastproc7 , $sumproc7 ); // diff
+          $thisproc8  = $row[8] ; list($thisproc8 , $lastproc8 , $sumproc8 ) = gettotalprocessed($thisproc8 , $lastproc8 , $sumproc8 ); // fullforce
+          $thisproc9  = $row[9] ; list($thisproc9 , $lastproc9 , $sumproc9 ) = gettotalprocessed($thisproc9 , $lastproc9 , $sumproc9 ); // dist
+          $thisproc10 = $row[10]; list($thisproc10, $lastproc10, $sumproc10) = gettotalprocessed($thisproc10, $lastproc10, $sumproc10); // pub
+
+          // get HST time info.
+          $hsttime  = $row[11];
+
+          // data content
+          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
+          echo "$sumproc1 , \"<i><b>$hsttime (HST) $sumproc1  chip      </i></b> \", "; //+ 3*30 chip
+          echo "$sumproc2 , \"<i><b>$hsttime (HST) $sumproc2  cam       </i></b> \", "; //+ 2*30 cam 
+          echo "$sumproc3 , \"<i><b>$hsttime (HST) $sumproc3  fake      </i></b> \", "; //+ 1*30 fake
+          echo "$sumproc4 , \"<i><b>$hsttime (HST) $sumproc4  warp      </i></b> \", "; //+ 0*30 warp
+          echo "$sumproc5 , \"<i><b>$hsttime (HST) $sumproc5  stack     </i></b> \", "; //+ 0*30 stack
+          echo "$sumproc6 , \"<i><b>$hsttime (HST) $sumproc6  staticsky </i></b> \", "; //+ 0*30 staticsky
+          echo "$sumproc7 , \"<i><b>$hsttime (HST) $sumproc7  diff      </i></b> \", "; //+ 6*30 diff
+          echo "$sumproc8 , \"<i><b>$hsttime (HST) $sumproc8  fullforce </i></b> \", "; //+ 0*30 fullforce
+          echo "$sumproc9 , \"<i><b>$hsttime (HST) $sumproc9  dist      </i></b> \", "; //+ 5*30 dist
+          echo "$sumproc10, \"<i><b>$hsttime (HST) $sumproc10 pub       </i></b> \"  "; //+ 4*30 pub
+          echo "],";
+        } 
+      }  
+    } else {
+      // selected stages and selected label
+      $plottitle = "title: 'Items',";
+      $plotseries  = "    series: { 0: { color: '#33a532', lineWidth: 3 }, ";   // traffic light green code
+      $plotseries .= "              1: { color: '#e7b416', lineWidth: 3 }, ";   // traffic light yellow code
+      $plotseries .= "              2: { color: '#cc3232', lineWidth: 3 }, },"; // traffic light red code
+      $plotstage = $selectedStage;
+
+      // data header
+      echo "   data.addColumn('datetime', 'Time');";
+      echo "   data.addColumn('number', 'Processed'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+      echo "   data.addColumn('number', 'Pending')  ; data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+      echo "   data.addColumn('number', 'Faults')   ; data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+      echo "   data.addRows([";
+
+      //  query data from czardb
+      $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, processed, pending, faults, timestamp "
+            ."from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) "
+            ."and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and label like '$selectedLabel';";
+      if ($debug) {echo "$sql<br>";}
+      $qry = $db->query($sql);
+      if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+
+      // define last process and total process
+      list($lastproc, $sumproc) = array(-1, 0);
+      while ($qry->fetchInto($row)) {
+        // get UTC time info.
+        $tsp = explode('.', $row[0]);
+        $pending  = $row[2];
+        $faults   = $row[3];
+
+        // get HST time info.
+        $hsttime  = $row[4];
+
+        // get processing info. from selected stages and get time series.
+        $thisproc = $row[1]; list($thisproc, $lastproc, $sumproc) = gettotalprocessed($thisproc, $lastproc, $sumproc);
+        if ($pending < 200 & $faults < 200) {
+          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
+          echo "$sumproc, \"<i><b>$hsttime (HST) $sumproc $selectedStage processed </i></b> \", ";
+          echo "$pending, \"<i><b>$hsttime (HST) $pending $selectedStage pendings  </i></b> \", ";
+          echo "$faults , \"<i><b>$hsttime (HST) $faults  $selectedStage faults    </i></b> \" ], ";
+        } else {
+          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
+          echo "$sumproc, \"<i><b>$hsttime (HST) $sumproc $selectedStage processed </i></b> \", ";
+          echo "0,        \"<i><b>$hsttime (HST) $pending $selectedStage pendings  </i></b> \", ";
+          echo "0 ,       \"<i><b>$hsttime (HST) $faults  $selectedStage faults    </i></b> \" ], ";
+        }
+      }
+    }
+    // data content end
+    echo "  ]);";
+   
+    // define x-axis range in terms of UTC from 0 to current time
+    $utcyy = gmdate("Y", strtotime("$dayshift day"));
+    $utcmm = gmdate("m", strtotime("$dayshift day"));
+    $utcdd = gmdate("d", strtotime("$dayshift day"));
+    if ($dayshift != 0) {
+      $utchh = 23;
+      $utcmn = 59;
+    } else {
+      $utchh = gmdate("H", strtotime("$dayshift day"));
+      $utcmn = gmdate("i", strtotime("$dayshift day"));
+    }
+
+    // linear plot options
+    echo " var opt_linear = {
+      title: 'Processed Items: $plotstage stages for $plotlabel labels on $proj',
+      titleTextStyle: {color: 'black', fontSize: 16},
+      width:  640, height: 400, fontSize: 12,
+      legend: { position: 'top', maxLines: 3 }, 
+      chartArea: {left:60, top:70, right:20, bottom:40},
+      tooltip: {isHtml: true},
+      hAxis: {  
+        title: 'Time on $utcyy-$utcmm-$utcdd (UTC)',
+        format: 'HH:mm',
+        gridlines: {count: -1},
+        viewWindow: { 
+          min: new Date($utcyy, $utcmm-1, $utcdd, 0, 0, 0), 
+          max: new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn) 
+        },  
+      },
+      vAxis: {  
+        title: 'Items',
+        gridlines: {count: -1},
+        viewWindow: { 
+          min: 0.1
+        },  
+      },
+      $plotseries
+    };";
+ 
+    // draw linear function
+    echo "      function drawLinearChart() { ";
+    // for separately plot 
+    # echo "        var linearChart = new google.visualization.LineChart(time_series_div_lin);";
+    echo "        var linearChart = new google.visualization.LineChart(time_series_div);";
+    echo "        linearChart.draw(data, opt_linear);";
+    echo "        button.innerText = 'Change y-axis to Log scale'  ; ";
+    echo "        button.onclick = drawLogChart; ";
+    echo "      } ";
+ 
+    // log scale options
+    echo " var opt_log = {
+      title: 'Processed Items: $plotstage stages for $plotlabel labels on $proj',
+      titleTextStyle: {color: 'black', fontSize: 16},
+      width:  640, height: 400, fontSize: 12,
+      legend: { position: 'top', maxLines: 3 }, 
+      chartArea: {left:60, top:70, right:20, bottom:40},
+      tooltip: {isHtml: true},
+      hAxis: {  
+        title: 'Time on $utcyy-$utcmm-$utcdd (UTC)',
+        format: 'HH:mm',
+        gridlines: {count: -1},
+        viewWindow: { 
+          min: new Date($utcyy, $utcmm-1, $utcdd, 0, 0, 0), 
+          max: new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn) 
+        },  
+      },
+      vAxis: {  
+        title: 'Log(Items)',
+        scaleType: 'log',
+        gridlines: {count: -1},
+        viewWindow: { 
+          min: 0.1
+        },  
+      },
+      $plotseries
+    };";
+ 
+    // draw log function
+    echo "      function drawLogChart() { ";
+    // for separately plot 
+    #echo "        var logChart    = new google.visualization.LineChart(time_series_div_log);";
+    echo "        var logChart    = new google.visualization.LineChart(time_series_div);";
+    echo "        logChart.draw(data,       opt_log);";
+    echo "        button.innerText = 'Change y-axis to Linear scale';";
+    echo "        button.onclick = drawLinearChart; ";
+    echo "      } ";
+ 
+    // default plot in linear scale
+    echo "   drawLinearChart(); ";
+    #echo "   drawLogChart(); ";
+    echo " }";
+ 
+    // end javascript
+    echo "</script>";
+ 
+    // timer end
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    $start= $finish;
+    echo "<center>loading in $total_time seconds</center>";
+}
+
+// sub function to find total processed items
+function gettotalprocessed ($thisProcessed, $lastProcessed, $totalProcessed) {
+  if($thisProcessed > $lastProcessed & $lastProcessed != -1) {
+      if ($thisProcessed - $lastProcessed < 50) {
+          $totalProcessed = $totalProcessed + $thisProcessed - $lastProcessed;
+      } else {
+          $totalProcessed = $totalProcessed;
+      }
+  }
+  $lastProcessed = $thisProcessed;
+  return array($thisProcessed, $lastProcessed, $totalProcessed);
+}
+
+###########################################################################
+#
+# Gets rate series plot
+#
+###########################################################################
+function Getrate($db, $selectedMode, $selectedLabel, $proj, $selectedStage) {
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
+    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
+    echo "<br><div id=\"rate_series_div\" style=\"width:640; height:400\"></div>";
+
+    echo "<script type=\"text/javascript\">";
+    echo "google.charts.load('current', {packages: ['corechart']});";
+    echo "google.charts.setOnLoadCallback(drawChart);";
+    // draw funciton start
+    echo "function drawChart() {";
+    echo "  var data = new google.visualization.DataTable();";
+
+    if ($selectedLabel == "all") { 
+       $selectedLabel = "stdscience_labels";
+       $plotlabel = "all"; }
+    else {
+       $plotlabel = $selectedLabel; 
+    }
+
+    $dayshift = -0;
+    $binsize = 30; // 30 mins gap
+    $bshift  = 5; // 10 mins step 
+    $difflimit = 100; // diff items limit for a time interval
+    $plotscale = 50; // diff items limit for a time interval
+    if ($selectedStage == "all_stages") {
+      $plotstage = "all";
+      $plottitle = "title: 'Items per hour + N x 50 offset',";
+      $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
+      $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, "; 
+      $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+      $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, "; 
+      $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, "; 
+      $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+      $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, "; 
+      $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+      $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, "; 
+      $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, "; 
+      $plotseries .= "             10: { color: 'cyan'    , lineWidth: 2, lineDashStyle: [3, 4]}, "; 
+      $plotseries .= "             11: { color: '#c51b7d' , lineWidth: 2, lineDashStyle: [3, 4]}, "; 
+      $plotseries .= "             12: { color: '#b15928' , lineWidth: 2, lineDashStyle: [3, 4]}, "; 
+      $plotseries .= "             13: { color: '#000004' , lineWidth: 2, lineDashStyle: [3, 4]}, },";
+      if ($selectedLabel == "stdscience_labels") {
+        echo "  data.addColumn('datetime',        'Time');";
+        echo "  data.addColumn(  'number',        'chip');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'cam');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'fake');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'warp');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',       'stack');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'staticsky');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'diff');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'fullforce');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'dist');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'pub');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'summitExp');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number', 'downloadExp');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',      'newExp');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',      'rawExp');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "   data.addRows([";
+
+      $datemin  = -$dayshift*1440+gmdate("H")*60+gmdate("i");
+      for ($t_i = 0; $t_i <= $datemin/$bshift; $t_i++) {
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, summrun.proc as sumproc, downrun.proc as downproc, newrun.proc as newproc, rawrun.proc as rawproc, timestamp";
+        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from rawExp   ,   (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as rawrun                "; 
+        $sql.= " join (select @rank2:=@rank2+1 AS rank,            processed as proc from newExp   ,   (select @rank2:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as newrun   using (rank) ";
+        $sql.= " join (select @rank3:=@rank3+1 AS rank,            processed as proc from summitExp,   (select @rank3:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as summrun  using (rank) ";
+        $sql.= " join (select @rank4:=@rank4+1 AS rank,            processed as proc from downloadExp, (select @rank4:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as downrun  using (rank) ";
+        $sql.= " join (select @rank5:=@rank5+1 AS rank,            processed as proc from chip,        (select @rank5:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun  using (rank) ";
+        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
+        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
+        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
+        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
+        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
+        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
+        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
+        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
+        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp limit 1;";
+        $qry = $db->query($sql);
+        $qry->fetchInto($row);
+        list($tstamp, $chipproc0, $camproc0, $fakeproc0, $warpproc0, $stackproc0, $statproc0, $diffproc0, $ffproc0, $distproc0, $pubproc0, $sumproc0, $downproc0, $newproc0, $rawproc0, $hsttime) = $row;
+//        $tsp = explode('.', $tstamp);
+  
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, summrun.proc as sumproc, downrun.proc as downproc, newrun.proc as newproc, rawrun.proc as rawproc, timestamp";
+        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from rawExp   ,   (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as rawrun                "; 
+        $sql.= " join (select @rank2:=@rank2+1 AS rank,            processed as proc from newExp   ,   (select @rank2:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as newrun   using (rank) ";
+        $sql.= " join (select @rank3:=@rank3+1 AS rank,            processed as proc from summitExp,   (select @rank3:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as summrun  using (rank) ";
+        $sql.= " join (select @rank4:=@rank4+1 AS rank,            processed as proc from downloadExp, (select @rank4:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as downrun  using (rank) ";
+        $sql.= " join (select @rank5:=@rank5+1 AS rank,            processed as proc from chip,        (select @rank5:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun  using (rank) ";
+        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
+        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
+        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
+        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
+        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
+        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
+        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
+        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
+        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp desc limit 1;";
+        $qry = $db->query($sql);
+        $qry->fetchInto($row);
+        list($tstamp, $chipproc1, $camproc1, $fakeproc1, $warpproc1, $stackproc1, $statproc1, $diffproc1, $ffproc1, $distproc1, $pubproc1, $sumproc1, $downproc1, $newproc1, $rawproc1, $hsttime) = $row;
+        list( $chip_diff,  $chip_rate) = getprocrate( $chipproc1 ,  $chipproc0, $binsize);
+        list(  $cam_diff,   $cam_rate) = getprocrate(  $camproc1 ,   $camproc0, $binsize);
+        list( $fake_diff,  $fake_rate) = getprocrate( $fakeproc1 ,  $fakeproc0, $binsize);
+        list( $warp_diff,  $warp_rate) = getprocrate( $warpproc1 ,  $warpproc0, $binsize);
+        list($stack_diff, $stack_rate) = getprocrate($stackproc1 , $stackproc0, $binsize);
+        list( $stat_diff,  $stat_rate) = getprocrate( $statproc1 ,  $statproc0, $binsize);
+        list( $diff_diff,  $diff_rate) = getprocrate( $diffproc1 ,  $diffproc0, $binsize);
+        list(   $ff_diff,    $ff_rate) = getprocrate(   $ffproc1 ,    $ffproc0, $binsize);
+        list( $dist_diff,  $dist_rate) = getprocrate( $distproc1 ,  $distproc0, $binsize);
+        list(  $pub_diff,   $pub_rate) = getprocrate(  $pubproc1 ,   $pubproc0, $binsize);
+        list(  $raw_diff,   $raw_rate) = getprocrate(  $rawproc1 ,   $rawproc0, $binsize);
+        list(  $new_diff,   $new_rate) = getprocrate(  $newproc1 ,   $newproc0, $binsize);
+        list(  $sum_diff,   $sum_rate) = getprocrate(  $sumproc1 ,   $sumproc0, $binsize);
+        list( $down_diff,  $down_rate) = getprocrate( $downproc1 ,  $downproc0, $binsize);
+
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp)) - 14*3600 ), \"%H.%i.%s\"), date_format(timestamp, \"%Y-%m-%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp))), \"%H:%i:%s\") from rawExp where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj'";
+        $qry = $db->query($sql);
+        $qry->fetchinto($row);
+        list($datestamp, $timestamp, $hstdate, $hsttime) = $row;
+        $dsp = explode('.', $datestamp);
+        $tsp = explode('.', $timestamp);
+
+        $utcyy = gmdate("Y", strtotime("$dayshift day"));
+        $utcmm = gmdate("m", strtotime("$dayshift day"));
+        $utcdd = gmdate("d", strtotime("$dayshift day"));
+        $utchh = floor($t_i*$bshift/60);
+        $utcmn = $t_i*$bshift % 60;
+        $hstdatetime = date("Y-m-d H:i", strtotime($utcyy."-".$utcmm."-".$utcdd." ".$utchh.":".$utcmn.":00"." UTC"));
+        if ($row[0] != NULL & $dsp[2] == $utcdd) {
+          if ($chip_diff < 0 || $cam_diff < 0 || $fake_diff < 0 || $warp_diff < 0 || $stack_diff < 0 || $stat_diff < 0 || $diff_diff < 0 || $ff_diff < 0 || $dist_diff < 0 || $pub_diff < 0 || $raw_diff < 0 || $new_diff < 0 || $sum_diff < 0 || $down_idff < 0 || $chip_diff > $difflimit || $cam_diff > $difflimit || $fake_diff > $difflimit || $warp_diff > $difflimit || $stack_diff > $difflimit || $stat_diff > $difflimit || $diff_diff > $difflimit || $ff_diff > $difflimit || $dist_diff > $difflimit || $pub_diff > $difflimit || $raw_diff > $difflimit || $new_diff > $difflimit || $sum_diff > $difflimit || $down_idff > $difflimit) {
+//            echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4]), ";
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 chip/hr       </i></b>\", "; //+10*50 chip
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 cam/hr        </i></b>\", "; //+ 9*50 cam 
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 fake/hr       </i></b>\", "; //+ 8*50 fake
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 warp/hr       </i></b>\", "; //+ 7*50 warp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 stack/hr      </i></b>\", "; //+ 0*50 stack
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr  </i></b>\", "; //+ 0*50 staticsky
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 diff/hr       </i></b>\", "; //+ 6*50 diff
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr  </i></b>\", "; //+ 0*50 fullforce
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 dist/hr       </i></b>\", "; //+ 5*50 dist
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 pub/hr        </i></b>\", "; //+ 4*50 pub
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 summitExp/hr  </i></b>\", "; //+ 3*50 summitExp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 downloadExp/hr</i></b>\", "; //+ 2*50 downloadExp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 newExp/hr     </i></b>\", "; //+ 1*50 newExp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 rawExp/hr     </i></b>\", "; //+ 0*50 rawExp
+            echo "],";
+//            echo "], $t_i, <br>";
+          } else {
+//            echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo "  $chip_rate, \"<i><b>$hstdatetime (HST)  $chip_rate  chip/hr       </i></b> \", "; //+10*50 chip
+            echo "   $cam_rate, \"<i><b>$hstdatetime (HST)   $cam_rate  cam/hr        </i></b> \", "; //+ 9*50 cam 
+            echo "  $fake_rate, \"<i><b>$hstdatetime (HST)  $fake_rate  fake/hr       </i></b> \", "; //+ 8*50 fake
+            echo "  $warp_rate, \"<i><b>$hstdatetime (HST)  $warp_rate  warp/hr       </i></b> \", "; //+ 7*50 warp
+            echo " $stack_rate, \"<i><b>$hstdatetime (HST) $stack_rate  stack/hr      </i></b> \", "; //+ 0*50 stack
+            echo "  $stat_rate, \"<i><b>$hstdatetime (HST)  $stat_rate  staticsky/hr  </i></b> \", "; //+ 0*50 staticsky
+            echo "  $diff_rate, \"<i><b>$hstdatetime (HST)  $diff_rate  diff/hr       </i></b> \", "; //+ 6*50 diff
+            echo "    $ff_rate, \"<i><b>$hstdatetime (HST)    $ff_rate  fullforce/hr  </i></b> \", "; //+ 0*50 fullforce
+            echo "  $dist_rate, \"<i><b>$hstdatetime (HST)  $dist_rate  dist/hr       </i></b> \", "; //+ 5*50 dist
+            echo "   $pub_rate, \"<i><b>$hstdatetime (HST)   $pub_rate  pub/hr        </i></b> \", "; //+ 4*50 pub
+            echo "   $sum_rate, \"<i><b>$hstdatetime (HST)   $sum_rate  summitExp/hr  </i></b> \", "; //+ 3*50 summitExp
+            echo "  $down_rate, \"<i><b>$hstdatetime (HST)  $down_rate  downloadExp/hr</i></b> \", "; //+ 2*50 downloadExp
+            echo "   $new_rate, \"<i><b>$hstdatetime (HST)   $new_rate  newExp/hr     </i></b> \", "; //+ 1*50 newExp
+            echo "   $raw_rate, \"<i><b>$hstdatetime (HST)   $raw_rate  rawExp/hr     </i></b> \", "; //+ 0*50 rawExp
+            echo "],";
+//            echo "], $t_i, <br>";
+          }
+        } else {
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 chip/hr       </i></b>\", "; //+10*50 chip
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 cam/hr        </i></b>\", "; //+ 9*50 cam 
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 fake/hr       </i></b>\", "; //+ 8*50 fake
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 warp/hr       </i></b>\", "; //+ 7*50 warp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 stack/hr      </i></b>\", "; //+ 0*50 stack
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr  </i></b>\", "; //+ 0*50 staticsky
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 diff/hr       </i></b>\", "; //+ 6*50 diff
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr  </i></b>\", "; //+ 0*50 fullforce
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 dist/hr       </i></b>\", "; //+ 5*50 dist
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 pub/hr        </i></b>\", "; //+ 4*50 pub
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 summitExp/hr  </i></b>\", "; //+ 3*50 summitExp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 downloadExp/hr</i></b>\", "; //+ 2*50 downloadExp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 newExp/hr     </i></b>\", "; //+ 1*50 newExp
+            echo " 0, \"<i><b>$hstdatetime (HST) 0 rawExp/hr     </i></b>\", "; //+ 0*50 rawExp
+            echo "],";
+//            echo "], $t_i, <br>";
+        }
+       }
+      }
+      else {
+        $plottitle = "title: 'Items per hour + N x 50 offset',";
+        $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
+        $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, "; 
+        $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, "; 
+        $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, "; 
+        $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, "; 
+        $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, "; 
+        $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, "; 
+        $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, },"; 
+        echo "  data.addColumn('datetime',        'Time');";
+        echo "  data.addColumn(  'number',        'chip');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'cam');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'fake');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'warp');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',       'stack');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'staticsky');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'diff');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',   'fullforce');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',        'dist');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "  data.addColumn(  'number',         'pub');";
+        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+        echo "   data.addRows([";
+  
+      $datemin  = -$dayshift*1440+gmdate("H")*60+gmdate("i");
+      for ($t_i = 0; $t_i <= $datemin/$bshift; $t_i++) {
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, timestamp";
+        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from chip,        (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun              "; 
+        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
+        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
+        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
+        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
+        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
+        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
+        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
+        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
+        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp limit 1;";
+        $qry = $db->query($sql);
+        $qry->fetchInto($row);
+        list($tstamp, $chipproc0, $camproc0, $fakeproc0, $warpproc0, $stackproc0, $statproc0, $diffproc0, $ffproc0, $distproc0, $pubproc0, $hsttime) = $row;
+ //       $tsp = explode('.', $tstamp);
+
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, timestamp";
+        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from chip,        (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun              "; 
+        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
+        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
+        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
+        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
+        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
+        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
+        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
+        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
+        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp desc limit 1;";
+        $qry = $db->query($sql);
+        $qry->fetchInto($row);
+        list($tstamp, $chipproc1, $camproc1, $fakeproc1, $warpproc1, $stackproc1, $statproc1, $diffproc1, $ffproc1, $distproc1, $pubproc1, $hsttime) = $row;
+        list( $chip_diff,  $chip_rate) = getprocrate( $chipproc1 ,  $chipproc0, $binsize);
+        list(  $cam_diff,   $cam_rate) = getprocrate(  $camproc1 ,   $camproc0, $binsize);
+        list( $fake_diff,  $fake_rate) = getprocrate( $fakeproc1 ,  $fakeproc0, $binsize);
+        list( $warp_diff,  $warp_rate) = getprocrate( $warpproc1 ,  $warpproc0, $binsize);
+        list($stack_diff, $stack_rate) = getprocrate($stackproc1 , $stackproc0, $binsize);
+        list( $stat_diff,  $stat_rate) = getprocrate( $statproc1 ,  $statproc0, $binsize);
+        list( $diff_diff,  $diff_rate) = getprocrate( $diffproc1 ,  $diffproc0, $binsize);
+        list(   $ff_diff,    $ff_rate) = getprocrate(   $ffproc1 ,    $ffproc0, $binsize);
+        list( $dist_diff,  $dist_rate) = getprocrate( $distproc1 ,  $distproc0, $binsize);
+        list(  $pub_diff,   $pub_rate) = getprocrate(  $pubproc1 ,   $pubproc0, $binsize);
+
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp)) - 14*3600 ), \"%H.%i.%s\"), date_format(timestamp, \"%Y-%m-%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp))), \"%H:%i:%s\") from chip where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj'";
+        $qry = $db->query($sql);
+        $qry->fetchinto($row);
+        list($datestamp, $timestamp, $hstdate, $hsttime) = $row;
+        $dsp = explode('.', $datestamp);
+        $tsp = explode('.', $timestamp);
+
+        $utcyy = gmdate("Y", strtotime("$dayshift day"));
+        $utcmm = gmdate("m", strtotime("$dayshift day"));
+        $utcdd = gmdate("d", strtotime("$dayshift day"));
+        $utchh = floor($t_i*$bshift/60);
+        $utcmn = $t_i*$bshift % 60;
+        $hstdatetime = date("Y-m-d H:i", strtotime($utcyy."-".$utcmm."-".$utcdd." ".$utchh.":".$utcmn.":00"." UTC"));
+        if ($row[0] != NULL & $dsp[2] == $utcdd) {
+          if ($chip_diff < 0 || $cam_diff < 0 || $fake_diff < 0 || $warp_diff < 0 || $stack_diff < 0 || $stat_diff < 0 || $diff_diff < 0 || $ff_diff < 0 || $dist_diff < 0 || $pub_diff < 0 || $chip_diff > $difflimit || $cam_diff > $difflimit || $fake_diff > $difflimit || $warp_diff > $difflimit || $stack_diff > $difflimit || $stat_diff > $difflimit || $diff_diff > $difflimit || $ff_diff > $difflimit || $dist_diff > $difflimit || $pub_diff > $difflimit) {
+//            echo "[new Date($dsp[0], $dsp[1]-1, $dsp[2], $tsp[0], $tsp[1]), ";
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 chip/hr     </i></b> \","; //+ 6*50 chip
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 cam/hr      </i></b> \","; //+ 5*50 cam 
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 fake/hr     </i></b> \","; //+ 4*50 fake
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 warp/hr     </i></b> \","; //+ 3*50 warp
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 stack/hr    </i></b> \","; //+ 0*50 stack
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr</i></b> \","; //+ 0*50 staticsky
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 diff/hr     </i></b> \","; //+ 2*50 diff
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr</i></b> \","; //+ 0*50 fullforce
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 dist/hr     </i></b> \","; //+ 1*50 dist
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 pub/hr      </i></b> \","; //+ 0*50 pub
+            echo "], ";
+          } else {
+//            echo "[new Date($dsp[0], $dsp[1]-1, $dsp[2], $tsp[0], $tsp[1]), ";
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo "  $chip_rate, \"<i><b>$hstdatetime (HST)  $chip_rate chip/hr     </i></b> \","; //+ 6*50 chip
+            echo "   $cam_rate, \"<i><b>$hstdatetime (HST)   $cam_rate cam/hr      </i></b> \","; //+ 5*50 cam 
+            echo "  $fake_rate, \"<i><b>$hstdatetime (HST)  $fake_rate fake/hr     </i></b> \","; //+ 4*50 fake
+            echo "  $warp_rate, \"<i><b>$hstdatetime (HST)  $warp_rate warp/hr     </i></b> \","; //+ 3*50 warp
+            echo " $stack_rate, \"<i><b>$hstdatetime (HST) $stack_rate stack/hr    </i></b> \","; //+ 0*50 stack
+            echo "  $stat_rate, \"<i><b>$hstdatetime (HST)  $stat_rate staticsky/hr</i></b> \","; //+ 0*50 staticsky
+            echo "  $diff_rate, \"<i><b>$hstdatetime (HST)  $diff_rate diff/hr     </i></b> \","; //+ 2*50 diff
+            echo "    $ff_rate, \"<i><b>$hstdatetime (HST)    $ff_rate fullforce/hr</i></b> \","; //+ 0*50 fullforce
+            echo "  $dist_rate, \"<i><b>$hstdatetime (HST)  $dist_rate dist/hr     </i></b> \","; //+ 1*50 dist
+            echo "   $pub_rate, \"<i><b>$hstdatetime (HST)   $pub_rate pub/hr      </i></b> \","; //+ 0*50 pub
+            echo "], "; 
+          }  
+        } else {
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 chip/hr     </i></b> \","; //+ 6*50 chip
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 cam/hr      </i></b> \","; //+ 5*50 cam 
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 fake/hr     </i></b> \","; //+ 4*50 fake
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 warp/hr     </i></b> \","; //+ 3*50 warp
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 stack/hr    </i></b> \","; //+ 0*50 stack
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr</i></b> \","; //+ 0*50 staticsky
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 diff/hr     </i></b> \","; //+ 2*50 diff
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr</i></b> \","; //+ 0*50 fullforce
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 dist/hr     </i></b> \","; //+ 1*50 dist
+            echo "  0, \"<i><b>$hstdatetime (HST) 0 pub/hr      </i></b> \","; //+ 0*50 pub
+            echo "], ";
+        }
+      }
+    }
+    }
+    else {
+      $plottitle = "title: 'Items per hour',";
+      echo "  data.addColumn('datetime',          'Time');";
+      echo "  data.addColumn(  'number','$selectedStage');";
+      echo "   data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
+      echo "   data.addRows([";
+      $plotstage = $selectedStage;
+      $plotseries  = "    series: { 0: { color: '#33a532', lineWidth: 3 }, },";
+      $binsize = 30; // 30 mins gap
+      $bshift  = 2; // 2 mins step
+      $datemin  = -$dayshift*1440+gmdate("H")*60+gmdate("i");
+      for ($t_i = 0; $t_i <= $datemin/$bshift; $t_i++) {
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i\") as dated, processed, timestamp from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and label like '$selectedLabel' order by timestamp limit 1;";
+        $qry = $db->query($sql);
+        $qry->fetchinto($row);
+        list($tstamp, $stageproc0) = $row;
+  
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i\") as dated, processed, timestamp from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and label like '$selectedLabel' order by timestamp desc limit 1;";
+        $qry = $db->query($sql);
+        $qry->fetchinto($row);
+        list($tstamp, $stageproc1) = $row;
+
+        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp)) - 14*3600 ), \"%H.%i.%s\"), date_format(timestamp, \"%Y-%m-%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp))), \"%H:%i:%s\") from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and label like '$selectedLabel';";
+        $qry = $db->query($sql);
+        $qry->fetchinto($row);
+        list($datestamp, $timestamp, $hstdate, $hsttime) = $row;
+        $dsp = explode('.', $datestamp);
+        $tsp = explode('.', $timestamp);
+
+
+        list(  $stage_diff,   $stage_rate) = getprocrate(  $stageproc1 , $stageproc0, $binsize);
+  
+        $utcyy = gmdate("Y", strtotime("$dayshift day"));
+        $utcmm = gmdate("m", strtotime("$dayshift day"));
+        $utcdd = gmdate("d", strtotime("$dayshift day"));
+        $utchh = floor($t_i*$bshift/60);
+        $utcmn = $t_i*$bshift % 60;
+        $hstdatetime = date("Y-m-d H:i", strtotime($utcyy."-".$utcmm."-".$utcdd." ".$utchh.":".$utcmn.":00"." UTC"));
+        if ($row[0] != null & $dsp[2] == $utcdd) {
+          if ($stage_diff < 0 || $stage_diff > $difflimit) {
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo " 0, \"<i><b> $hstdatetime (HST) 0 $selectedStage/hr</i></b> \", ";
+            echo "], ";
+          } else {
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo " $stage_rate, \"<i><b> $hstdatetime (HST) $stage_rate $selectedStage/hr</i></b> \", ";
+            echo "], ";
+          }
+        } else {
+            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
+            echo " 0, \"<i><b> $hstdatetime (HST) 0 $selectedStage/hr</i></b> \", ";
+            echo "], ";
+        }
+      }
+   }
+
+   $utcyy = gmdate("Y", strtotime("$dayshift day"));
+   $utcmm = gmdate("m", strtotime("$dayshift day"));
+   $utcdd = gmdate("d", strtotime("$dayshift day"));
+   if ($dayshift != 0) {
+     $utchh = 23;
+     $utcmn = 59;
+   } else {
+     $utchh = gmdate("H", strtotime("$dayshift day"));
+     $utcmn = gmdate("i", strtotime("$dayshift day"));
+   }
+   echo "  ]);";
+
+
+    // linear plot options
+    echo " var options = {
+      title: 'Processed Items: $plotstage stages for $plotlabel labels on $proj',
+      titleTextStyle: {color: 'black', fontSize: 16},
+      width:  640, height: 400, fontSize: 12,
+      legend: { position: 'top', maxLines: 3 }, 
+      chartArea: {left:60, top:70, right:20, bottom:40},
+      tooltip: {isHtml: true},
+      hAxis: {  
+        title: 'Time on $utcyy-$utcmm-$utcdd (UTC)',
+        format: 'HH:mm',
+        gridlines: {count: -1},
+        viewWindow: { 
+          min: new Date($utcyy, $utcmm-1, $utcdd, 0, 0, 0), 
+          max: new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn) 
+        },  
+      },
+      vAxis: {  
+        title: 'Items per hour',
+        gridlines: {count: -1},
+      },
+      $plotseries
+    };";
+
+
+   echo "   var chart = new google.visualization.LineChart(document.getElementById('rate_series_div'));";
+   echo "   chart.draw(data, options);";
+   echo " }";
+   echo "</script>";
+
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    $start= $finish;
+    echo "<center>loading in $total_time seconds<br></center>";
+#    echo $sql;
+}
+
+function getprocrate ($proc1, $proc0, $trange) {
+  if($proc1 > $proc0) {
+    $diffproc = $proc1-$proc0;
+  } else {
+    $diffproc = 0;
+  }
+  $procrate = $diffproc / $trange * 60;
+  return array($diffproc, $procrate);
+}
+
+
 
 ?>
Index: trunk/ippMonitor/raw/site.php
===================================================================
--- trunk/ippMonitor/raw/site.php	(revision 41558)
+++ trunk/ippMonitor/raw/site.php	(revision 41677)
@@ -4,12 +4,16 @@
 // values below are set based on the binary, etc paths.
 
-$WWWHOST    = "ipp113.ifa.hawaii.edu";
+$WWWHOST    = "ipp117.ifa.hawaii.edu";
 
-$PERLLIB    = "/data/ippc18.0/home/tdeboer/ipp/default.lin64/lib";
+$PERLLIB    = "/data/ippc64.1/ippitc/psconfig/ipp-20170121.lin64/lib";
 $BINDIR     = "/data/ippc64.1/ippitc/psconfig/ipp-20170121.lin64/bin";
-$LIBDIR     = "/data/ippc18.0/home/tdeboer/ipp/default.lin64/lib";
+$LIBDIR     = "/data/ippc64.1/ippitc/psconfig/ipp-20170121.lin64/lib";
 $SITE       = "/data/ippc64.1/ippitc/ippconfig/ippmonitor.config";
 
 $DBI     = "DB";
+
+// location of plots produced by czarpoll.pl
+$CZARPLOTDIR     = "./czartool_plots";
+$METRICSPLOTDIR  = "./ippMetrics";
 
 // insert config.dat here. this contains a number of system-specific things like
@@ -18,18 +22,19 @@
 
 // host and user information for the main processing database (contains, e.g., gpc1, gpc2, etc)
-$DBHOST    = "ippdb08";
-$DBUSER    = "ippuser";
-$DBPASS    = "ippuser";
+$DBHOST    = "ippdb05";
+$DBUSER    = "ipp";
+$DBPASS    = "ipp";
 
 // location of nebulous apache interface machine
-$NEB_SERVER = "http://ippc74/nebulous";
+$NEB_SERVER = "http://ippc33/nebulous";
 
 // Czartool configuration variables
 // NOTE: These should match the configuration file used by the czartool perl modules: czartool/czarconfig.xml
 $CZARDBNAME = "czardb";
-$CZARDBHOST = "ippdb08";
+$CZARDBHOST = "ippdb05";
 
 // location of plots produced by czarpoll.pl
-$CZARPLOTDIR = "/export/ipp113.0/ipp/czartool_plots";
+//$CZARPLOTDIR = "/export/ipp113.0/ipp/czartool_plots";
+//$CZARPLOTDIR = "/export/ipp117.0/ipp/czartool_plots";
 
 // Temporary files belonging to DELETION_USER and older than
@@ -40,18 +45,13 @@
 $DELETION_DELAY  = 15;
 
-$HOST_NEBULOUS  = "ippdb09.IfA.Hawaii.Edu";
+$HOST_NEBULOUS  = "nebulous.ipp.ifa.hawaii.edu";
 $USER_NEBULOUS  = "ippMonitor";
 $PASSWORD_NEBULOUS  = "ippMonitor";
-$DBNAME_NEBULOUS  = "ippdb09 nebulous master";
-
-$REPL_HOST_NEBULOUS  = "ippdb01.IfA.Hawaii.Edu";
-$REPL_USER_NEBULOUS  = "ippMonitor";
-$REPL_PASSWORD_NEBULOUS  = "ippMonitor";
-$REPL_DBNAME_NEBULOUS  = "ippdb01 nebulous repl1 (50,000s behind is acceptable / usually stopped on Mon/Tues for backups)";
+$DBNAME_NEBULOUS  = "ippdb11 nebulous master";
 
 $REPL_HOST_NEBULOUS_SECONDARY  = "ippdb06.IfA.Hawaii.Edu";
 $REPL_USER_NEBULOUS_SECONDARY  = "ippMonitor";
 $REPL_PASSWORD_NEBULOUS_SECONDARY  = "ippMonitor";
-$REPL_DBNAME_NEBULOUS_SECONDARY  = "ippdb06 nebulous repl2 (50,000s behind is acceptable / usually stopped on Mon/Tues for backups)";
+$REPL_DBNAME_NEBULOUS_SECONDARY  = "ippdb06 nebulous repl2";
 
 $REPL_HOST_NEBULOUS_THIRD  = "ippdb12.IfA.Hawaii.Edu";
@@ -75,18 +75,23 @@
 $REPL_DBNAME_ISP  = "ippc17 (isp)";
 
-$HOST_GPC1  = "ippdb08.IfA.Hawaii.Edu";
+$HOST_GPC1  = "ippdb05.IfA.Hawaii.Edu";
 $USER_GPC1  = "ippMonitor";
 $PASSWORD_GPC1  = "ippMonitor";
-$DBNAME_GPC1  = "ippdb08 master db(czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
+$DBNAME_GPC1  = "ippdb05 master db(czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
 
-$REPL_HOST_GPC1  = "ippdb05.IfA.Hawaii.Edu";
+$REPL_HOST_GPC1  = "ippdb01.IfA.Hawaii.Edu";
 $REPL_USER_GPC1  = "ippMonitor";
 $REPL_PASSWORD_GPC1  = "ippMonitor";
-$REPL_DBNAME_GPC1  = "ippdb05 repl1 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
+$REPL_DBNAME_GPC1  = "ippdb01 repl1 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
 
-$REPL_HOST_GPC1_SECONDARY  = "ipp116.IfA.Hawaii.Edu";
+$REPL_HOST_GPC1_SECONDARY  = "ippdb09.IfA.Hawaii.Edu";
 $REPL_USER_GPC1_SECONDARY  = "ippMonitor";
 $REPL_PASSWORD_GPC1_SECONDARY  = "ippMonitor";
-$REPL_DBNAME_GPC1_SECONDARY  = "ipp116 repl2 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
+$REPL_DBNAME_GPC1_SECONDARY  = "ippdb09 repl2 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
+
+$REPL_HOST_GPC1_THIRD  = "ipp116.IfA.Hawaii.Edu";
+$REPL_USER_GPC1_THIRD  = "ippMonitor";
+$REPL_PASSWORD_GPC1_THIRD  = "ippMonitor";
+$REPL_DBNAME_GPC1_THIRD  = "ipp116 repl3 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
 
 $REPL_HOST_DATASTORE_SECONDARY  = "ipp117.IfA.Hawaii.Edu";
@@ -102,31 +107,42 @@
 $DBNAME_GATEWAY_SECONDARY  = "ipp117 (gateway backup)";
 
-$HOST_APACHE1  = "ippc70.IfA.Hawaii.Edu";
-$DBNAME_APACHE1  = "ippc70 (apache node)";
+$HOST_APACHE1  = "ippc33.IfA.Hawaii.Edu";
+$DBNAME_APACHE1  = "ippc33 (apache node)";
 
-$HOST_APACHE2  = "ippc71.IfA.Hawaii.Edu";
-$DBNAME_APACHE2  = "ippc71 (apache node)";
+$HOST_APACHE2  = "ippc34.IfA.Hawaii.Edu";
+$DBNAME_APACHE2  = "ippc34 (apache node)";
 
-$HOST_APACHE3  = "ippc72.IfA.Hawaii.Edu";
-$DBNAME_APACHE3  = "ippc72 (apache node)";
+$HOST_APACHE3  = "ippc35.IfA.Hawaii.Edu";
+$DBNAME_APACHE3  = "ippc35 (apache node)";
 
-$HOST_APACHE4  = "ippc73.IfA.Hawaii.Edu";
-$DBNAME_APACHE4  = "ippc73 (apache node)";
+$HOST_APACHE4  = "ippc43.IfA.Hawaii.Edu";
+$DBNAME_APACHE4  = "ippc43 (apache node)";
 
-$HOST_APACHE5  = "ippc74.IfA.Hawaii.Edu";
-$DBNAME_APACHE5  = "ippc74 (apache node)";
+$HOST_APACHE5  = "ippc44.IfA.Hawaii.Edu";
+$DBNAME_APACHE5  = "ippc44 (apache node)";
 
-$HOST_APACHE6  = "ippc75.IfA.Hawaii.Edu";
-$DBNAME_APACHE6  = "ippc75 (apache node)";
+$HOST_APACHE6  = "ippc45.IfA.Hawaii.Edu";
+$DBNAME_APACHE6  = "ippc45 (apache node)";
+
+$HOST_APACHE7  = "ippc36.IfA.Hawaii.Edu";
+$DBNAME_APACHE7 = "ippc36 (backup apache)";
+
+$HOST_APACHE8  = "ippc46.IfA.Hawaii.Edu";
+$DBNAME_APACHE8 = "ippc46 (backup apache)";
 
 $HOST_PROXY  = "ippops1.IfA.Hawaii.Edu";
 $DBNAME_PROXY  = "ippops1 (proxy server)";
 
-$HOST_SVN  = "ippops2.IfA.Hawaii.Edu";
-$DBNAME_SVN  = "ippops2 (svn server)";
+$HOST_SVN  = "ippops4.IfA.Hawaii.Edu";
+$DBNAME_SVN  = "ippops4 (svn server)";
 
 $HOST_CONFLUENCE  = "ippops4.IfA.Hawaii.Edu";
 $DBNAME_CONFLUENCE  = "ippops4 (confluence/JIRA)";
 
+$HOST_NAGIOS  = "ipphome0.IfA.Hawaii.Edu";
+$DBNAME_NAGIOS  = "ipphome0 (nagios/ITC home backup)";
+
+$HOST_HOME  = "ipphome0.IfA.Hawaii.Edu";
+$DBNAME_HOME  = "ipphome0 (ITC homedir)";
 
 ?>
