Index: trunk/ippMonitor/raw/storage.php
===================================================================
--- trunk/ippMonitor/raw/storage.php	(revision 42923)
+++ trunk/ippMonitor/raw/storage.php	(revision 42972)
@@ -12,8 +12,9 @@
 $projectdb = dbconnect($ID['proj']);
 
+
 if ($ID['menu']) {$myMenu = $ID['menu'];}
 else {$myMenu = "ipp.czar.dat";}
 
-menu($myMenu, 'Czartool on '.$lastUpdateTime, 'ipp.css', $ID['link'], $ID['proj']);
+menu($myMenu, 'Czartool on ', 'ipp.css', $ID['link'], $ID['proj']);
 
 $pass = $ID['pass'];
@@ -25,4 +26,7 @@
 echo "  <td style=width:1200px>";
 echo "  <h1 align=\"middle\">Storage status</h1>";
+
+require_once 'functions.php';  
+
 # storage timeseries
 echo getSpaces($czardb);
@@ -35,277 +39,4 @@
 menu_end();
 
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-//                               Functions                                 //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-###########################################################################
-#
-# Gets disk status
-#
-###########################################################################
-function getHosts($db) {
-    $start = microtime(true);
-
-
-    // Set environment variables
-    putenv("PATH=/usr/local/bin:/usr/bin:/bin:/data/ippc65.0/ipp/src/psconfig//ipp-20210708-gentoo.lin64/bin");
-    putenv("PERL5LIB=/data/ippc65.0/ipp/src/psconfig//ipp-20210708-gentoo.lin64/lib");
-
-    $hostnoteall = array();
-    exec("neb-host |cut -b 17-30,86-", $hostnoteall);
-
-    $sql = "SELECT host, format(total, 2), format(available, 2), format(used, 2), writable, readable, format(used/total*100,3) as ratio FROM hosts where xattr <> 3 ORDER BY CASE WHEN ROUND(used/total*100,3) = 100 THEN 0 ELSE 1 END, xattr, host;";
-    $qry = $db->query($sql);
-
-    if ($qry === false) {
-        echo "<b>Error with SQL query</b><br>";
-        return;
-    }
-
-    $sqlMax = "SELECT MAX(total) AS max_total FROM hosts WHERE xattr <> 3";
-    $qryMax = $db->query($sqlMax);
-    $maxUsed = 0;
-    
-    if ($qryMax && $qryMax->fetchInto($rowMax)) {
-        $maxUsed = $rowMax[0];  // max_total value
-    }
-
-    $dataRows = array();
-    while ($qry->fetchInto($row)) {
-        // Access by index
-        $host      = $row[0]; // ipp071.0
-        $total     = $row[1]; // 80.0352 TB
-        $available = $row[2]; // 10.8096 TB
-        $used      = $row[3]; // 69.2256 TB
-        $writable  = $row[4]; // 0
-        $readable  = $row[5]; // 1
-        $ratio     = $row[6]; // 86.4939 %
-
-        // Match notes
-        $hostnotes = preg_grep("/$host/", $hostnoteall);
-        $hostnote = reset($hostnotes);
-
-        // Defaults
-        $styles    = "stroke-width: .5; stroke-color: black;";
-        $status    = "down";
-        $usedColor = "lightgrey";
-        $freeColor = "lightgrey";
-
-        // Status logic
-        if ($writable == 1 && $readable == 1) {
-            $status    = "up";
-            $usedColor = ($ratio >= 97) ? "pink" : "yellow"; // red if â¥97%
-            $freeColor = "#a6ec99"; // green free
-        } elseif ($writable == 0 && $readable == 1) {
-            $status    = "repair";
-            $usedColor = ($ratio >= 97) ? "pink" : "yellow";
-            $freeColor = "lightgrey"; // grey free
-        } elseif ($available < 1) {
-            $used      = $maxUsed;
-            $available = 0;
-            $status    = "offline";
-            $usedColor = "white";
-            $freeColor = "white";
-        }
-    
-        if ($status == "down") {
-            $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used ". 
-                           "<span style='color:red; font-weight:bold;'> <br>" . $hostnote .  "</span>";
-            $tooltipFree = "<span style='color:red; font-weight:bold;'>" .
-                           $host . ": " . $available . " TB free" .
-                           "</span>";
-        } elseif ($status == "offline") {
-            $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used ". 
-                           "<span style='color:red; font-weight:bold;'> <br>" . $hostnote .  "</span>";
-            $tooltipFree = "<span style='color:red; font-weight:bold;'>" .
-                           $host . ": " . $total . " TB free" .
-                           "</span>";
-        } else {
-            $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used<br>" . $hostnote ;
-            $tooltipFree = $host . ": " . $available . " TB free";
-        }
-
-
-        // Build data row (manual string concatenation for old PHP)
-        $dataRows[] =
-            "[ \"" . $host . ":" . $status . "\", " .
-            $used . ", \"" . $styles . " color: " . $usedColor . ";\", \"" . $tooltipUsed . "\", " .
-            $available . ", \"" . $styles . " color: " . $freeColor . ";\", \"" . $tooltipFree . "\" ]";
-
-    }
-    echo "<script type=\"text/javascript\">
-            google.charts.load('current', {packages: ['corechart', 'bar']});
-            google.charts.setOnLoadCallback(drawBarColors);
-
-            function drawBarColors() {
-                var data = google.visualization.arrayToDataTable([
-                    ['Host', 'Used', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}, 
-                     'Free', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}],
-                    " . implode(",\n", $dataRows) . "
-                ]);
-                
-                var options = {
-                    title: 'Nebulous Disk Use across IPP Clusters',
-                    titleTextStyle: {color: 'black', fontSize: 15},
-                    width: '100%',
-                    height: '100%',
-                    tooltip: {isHtml: true},
-                    legend: { position: 'none', alignment: 'end', maxLines: 3 },
-                    hAxis: { title: 'Space (TB)', gridlines: {count: 20} },
-                    vAxis: { textStyle: {fontSize: 14}, format: 'string',  textPosition: 'in', direction: 1},
-                    bar: { groupWidth: '95%' },
-                    chartArea: {left:40, top:50, right:20, bottom:40},
-                    fontSize: 15,
-                    allowHtml: true,
-                    isStacked: true
-                };
-
-                var chart = new google.visualization.BarChart(document.getElementById('disk_div'));
-                chart.draw(data, options);
-            }
-          </script>";
-
-echo "<script type='text/javascript' src='loader.js'></script>
-<br>
-<div class='chartWithOverlay' style='position: relative; width: 100%'>
-
-    <div id='disk_div' style='width:100%; height:5000px'></div>
-
-    <div class='overlay' style='position: absolute; width:160px; top:50px; right:30px; font-family:Arial, sans-serif;'>
-
-      <div style='font-size:15px; border:1px solid #888; background-color:lightgreen; color:black; text-align:center; margin-bottom:1px;'>Free</div>
-      <div style='font-size:15px; border:1px solid #888; background-color:yellow    ; color:black; text-align:center; margin-bottom:1px;'>Used</div>
-      <div style='font-size:15px; border:1px solid #888; background-color:pink      ; color:black; text-align:center; margin-bottom:1px;'>97% Usage</div>
-      <div style='font-size:15px; border:1px solid #888; background-color:lightgrey ; color:black; text-align:center; margin-bottom:1px;'>Down/Repair</div>
-      <div style='font-size:15px; border:1px solid #888; background-color:white     ; color:black; text-align:center; margin-bottom:1px;'>Offline</div>
-      <div style='font-size:15px; border:1px solid #888; background-color:#42a5f5   ; color:white; text-align:center; margin-bottom:1px;'>
-        <a href='https://atrcganglia.ifa.hawaii.edu/' target='_blank' style='text-decoration:none; color:white; font-weight:bold;'>ATRC ganglia</a>
-      </div>
-
-    </div>
-
-</div>";
-
-    $total_time = round(microtime(true) - $start, 3);
-    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 FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ippb%' and xattr <> 3")->fetchInto($row);
-    $ippbusable = $row[0];
-    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ippb%' and writable = 1 and xattr <> 3")->fetchInto($row);
-    $ippbfree = $row[0];
-
-    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host not like 'ippb%' and xattr <> 3")->fetchInto($row);
-    $ippusable = $row[0];
-    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host not like 'ippb%' and writable = 1 and xattr <> 3")->fetchInto($row);
-    $ippfree = $row[0];
-
-    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ipp%_bck.0' and xattr <> 3")->fetchInto($row);
-    $bckusable = $row[0];
-    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ipp%_bck.0' and writable = 1 and xattr <> 3")->fetchInto($row);
-    $bckfree = $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: 100%; height:400\">"; 
-    echo "  <div id=\"space_div\" style=\"width:100%; \"></div>";
-    echo "  <div class=\"overlay\" style=\"position: absolute; width: 500px; bottom: 60px; left: 80px;\">";
-    echo "    <div style=\"font-size: 16px; color:#0000ff; \"><b>ipp*_bck: $bckusable TB (usable)</b></div>";
-    echo "    <div style=\"font-size: 16px; color:#33a532; \"><b>ipp*_bck: $bckfree   TB (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 (ipp:$ippusable, ippb:$ippbusable) TB');";
-    echo "        data.addColumn('number', 'Free (ipp:$ippfree, ippb:$ippbfree) TB');";
-    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>";
-}
-
-
 ?>
 
