IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 19, 2026, 5:23:27 PM (7 weeks ago)
Author:
cclin33
Message:

update function.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippMonitor/raw/storage.php

    r42923 r42972  
    1212$projectdb = dbconnect($ID['proj']);
    1313
     14
    1415if ($ID['menu']) {$myMenu = $ID['menu'];}
    1516else {$myMenu = "ipp.czar.dat";}
    1617
    17 menu($myMenu, 'Czartool on '.$lastUpdateTime, 'ipp.css', $ID['link'], $ID['proj']);
     18menu($myMenu, 'Czartool on ', 'ipp.css', $ID['link'], $ID['proj']);
    1819
    1920$pass = $ID['pass'];
     
    2526echo "  <td style=width:1200px>";
    2627echo "  <h1 align=\"middle\">Storage status</h1>";
     28
     29require_once 'functions.php'; 
     30
    2731# storage timeseries
    2832echo getSpaces($czardb);
     
    3539menu_end();
    3640
    37 
    38 /////////////////////////////////////////////////////////////////////////////
    39 //                                                                         //
    40 //                               Functions                                 //
    41 //                                                                         //
    42 /////////////////////////////////////////////////////////////////////////////
    43 
    44 ###########################################################################
    45 #
    46 # Gets disk status
    47 #
    48 ###########################################################################
    49 function getHosts($db) {
    50     $start = microtime(true);
    51 
    52 
    53     // Set environment variables
    54     putenv("PATH=/usr/local/bin:/usr/bin:/bin:/data/ippc65.0/ipp/src/psconfig//ipp-20210708-gentoo.lin64/bin");
    55     putenv("PERL5LIB=/data/ippc65.0/ipp/src/psconfig//ipp-20210708-gentoo.lin64/lib");
    56 
    57     $hostnoteall = array();
    58     exec("neb-host |cut -b 17-30,86-", $hostnoteall);
    59 
    60     $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;";
    61     $qry = $db->query($sql);
    62 
    63     if ($qry === false) {
    64         echo "<b>Error with SQL query</b><br>";
    65         return;
    66     }
    67 
    68     $sqlMax = "SELECT MAX(total) AS max_total FROM hosts WHERE xattr <> 3";
    69     $qryMax = $db->query($sqlMax);
    70     $maxUsed = 0;
    71    
    72     if ($qryMax && $qryMax->fetchInto($rowMax)) {
    73         $maxUsed = $rowMax[0];  // max_total value
    74     }
    75 
    76     $dataRows = array();
    77     while ($qry->fetchInto($row)) {
    78         // Access by index
    79         $host      = $row[0]; // ipp071.0
    80         $total     = $row[1]; // 80.0352 TB
    81         $available = $row[2]; // 10.8096 TB
    82         $used      = $row[3]; // 69.2256 TB
    83         $writable  = $row[4]; // 0
    84         $readable  = $row[5]; // 1
    85         $ratio     = $row[6]; // 86.4939 %
    86 
    87         // Match notes
    88         $hostnotes = preg_grep("/$host/", $hostnoteall);
    89         $hostnote = reset($hostnotes);
    90 
    91         // Defaults
    92         $styles    = "stroke-width: .5; stroke-color: black;";
    93         $status    = "down";
    94         $usedColor = "lightgrey";
    95         $freeColor = "lightgrey";
    96 
    97         // Status logic
    98         if ($writable == 1 && $readable == 1) {
    99             $status    = "up";
    100             $usedColor = ($ratio >= 97) ? "pink" : "yellow"; // red if ≥97%
    101             $freeColor = "#a6ec99"; // green free
    102         } elseif ($writable == 0 && $readable == 1) {
    103             $status    = "repair";
    104             $usedColor = ($ratio >= 97) ? "pink" : "yellow";
    105             $freeColor = "lightgrey"; // grey free
    106         } elseif ($available < 1) {
    107             $used      = $maxUsed;
    108             $available = 0;
    109             $status    = "offline";
    110             $usedColor = "white";
    111             $freeColor = "white";
    112         }
    113    
    114         if ($status == "down") {
    115             $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used ".
    116                            "<span style='color:red; font-weight:bold;'> <br>" . $hostnote .  "</span>";
    117             $tooltipFree = "<span style='color:red; font-weight:bold;'>" .
    118                            $host . ": " . $available . " TB free" .
    119                            "</span>";
    120         } elseif ($status == "offline") {
    121             $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used ".
    122                            "<span style='color:red; font-weight:bold;'> <br>" . $hostnote .  "</span>";
    123             $tooltipFree = "<span style='color:red; font-weight:bold;'>" .
    124                            $host . ": " . $total . " TB free" .
    125                            "</span>";
    126         } else {
    127             $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used<br>" . $hostnote ;
    128             $tooltipFree = $host . ": " . $available . " TB free";
    129         }
    130 
    131 
    132         // Build data row (manual string concatenation for old PHP)
    133         $dataRows[] =
    134             "[ \"" . $host . ":" . $status . "\", " .
    135             $used . ", \"" . $styles . " color: " . $usedColor . ";\", \"" . $tooltipUsed . "\", " .
    136             $available . ", \"" . $styles . " color: " . $freeColor . ";\", \"" . $tooltipFree . "\" ]";
    137 
    138     }
    139     echo "<script type=\"text/javascript\">
    140             google.charts.load('current', {packages: ['corechart', 'bar']});
    141             google.charts.setOnLoadCallback(drawBarColors);
    142 
    143             function drawBarColors() {
    144                 var data = google.visualization.arrayToDataTable([
    145                     ['Host', 'Used', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}},
    146                      'Free', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}],
    147                     " . implode(",\n", $dataRows) . "
    148                 ]);
    149                
    150                 var options = {
    151                     title: 'Nebulous Disk Use across IPP Clusters',
    152                     titleTextStyle: {color: 'black', fontSize: 15},
    153                     width: '100%',
    154                     height: '100%',
    155                     tooltip: {isHtml: true},
    156                     legend: { position: 'none', alignment: 'end', maxLines: 3 },
    157                     hAxis: { title: 'Space (TB)', gridlines: {count: 20} },
    158                     vAxis: { textStyle: {fontSize: 14}, format: 'string',  textPosition: 'in', direction: 1},
    159                     bar: { groupWidth: '95%' },
    160                     chartArea: {left:40, top:50, right:20, bottom:40},
    161                     fontSize: 15,
    162                     allowHtml: true,
    163                     isStacked: true
    164                 };
    165 
    166                 var chart = new google.visualization.BarChart(document.getElementById('disk_div'));
    167                 chart.draw(data, options);
    168             }
    169           </script>";
    170 
    171 echo "<script type='text/javascript' src='loader.js'></script>
    172 <br>
    173 <div class='chartWithOverlay' style='position: relative; width: 100%'>
    174 
    175     <div id='disk_div' style='width:100%; height:5000px'></div>
    176 
    177     <div class='overlay' style='position: absolute; width:160px; top:50px; right:30px; font-family:Arial, sans-serif;'>
    178 
    179       <div style='font-size:15px; border:1px solid #888; background-color:lightgreen; color:black; text-align:center; margin-bottom:1px;'>Free</div>
    180       <div style='font-size:15px; border:1px solid #888; background-color:yellow    ; color:black; text-align:center; margin-bottom:1px;'>Used</div>
    181       <div style='font-size:15px; border:1px solid #888; background-color:pink      ; color:black; text-align:center; margin-bottom:1px;'>97% Usage</div>
    182       <div style='font-size:15px; border:1px solid #888; background-color:lightgrey ; color:black; text-align:center; margin-bottom:1px;'>Down/Repair</div>
    183       <div style='font-size:15px; border:1px solid #888; background-color:white     ; color:black; text-align:center; margin-bottom:1px;'>Offline</div>
    184       <div style='font-size:15px; border:1px solid #888; background-color:#42a5f5   ; color:white; text-align:center; margin-bottom:1px;'>
    185         <a href='https://atrcganglia.ifa.hawaii.edu/' target='_blank' style='text-decoration:none; color:white; font-weight:bold;'>ATRC ganglia</a>
    186       </div>
    187 
    188     </div>
    189 
    190 </div>";
    191 
    192     $total_time = round(microtime(true) - $start, 3);
    193     echo "<center>loading in $total_time seconds<br></center>";
    194 }
    195 
    196 
    197 ###########################################################################
    198 #
    199 # Gets disk spaces status
    200 #
    201 ###########################################################################
    202 function getSpaces($db) {
    203     // timer start
    204     $time = microtime();
    205     $time = explode(' ', $time);
    206     $time = $time[1] + $time[0];
    207     $start = $time;
    208 
    209     $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ippb%' and xattr <> 3")->fetchInto($row);
    210     $ippbusable = $row[0];
    211     $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ippb%' and writable = 1 and xattr <> 3")->fetchInto($row);
    212     $ippbfree = $row[0];
    213 
    214     $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host not like 'ippb%' and xattr <> 3")->fetchInto($row);
    215     $ippusable = $row[0];
    216     $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host not like 'ippb%' and writable = 1 and xattr <> 3")->fetchInto($row);
    217     $ippfree = $row[0];
    218 
    219     $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ipp%_bck.0' and xattr <> 3")->fetchInto($row);
    220     $bckusable = $row[0];
    221     $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);
    222     $bckfree = $row[0];
    223 
    224 
    225     $sql = "select format(used/total*100,1), usable from cluster_space order by timestamp desc limit 1;";
    226 
    227     if ($debug) {echo "$sql<br>";}
    228     $qry = $db->query($sql);
    229     if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
    230     $qry->fetchInto($row);
    231     $allocated = $row[0];
    232     $usable    = $row[1];
    233 
    234     #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
    235     echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
    236     echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 100%; height:400\">";
    237     echo "  <div id=\"space_div\" style=\"width:100%; \"></div>";
    238     echo "  <div class=\"overlay\" style=\"position: absolute; width: 500px; bottom: 60px; left: 80px;\">";
    239     echo "    <div style=\"font-size: 16px; color:#0000ff; \"><b>ipp*_bck: $bckusable TB (usable)</b></div>";
    240     echo "    <div style=\"font-size: 16px; color:#33a532; \"><b>ipp*_bck: $bckfree   TB (free)</b></div>";
    241     echo "  </div>";
    242     echo "</div>";
    243 
    244     echo "<script type=\"text/javascript\">";
    245     echo "google.charts.load('current', {packages: ['corechart']});";
    246     echo "google.charts.setOnLoadCallback(drawChart);";
    247     echo "function drawChart() {";
    248     echo "  var data = new google.visualization.DataTable();";
    249     echo "        data.addColumn('datetime', 'Day');";
    250     echo "        data.addColumn('number', 'Usable (ipp:$ippusable, ippb:$ippbusable) TB');";
    251     echo "        data.addColumn('number', 'Free (ipp:$ippfree, ippb:$ippbfree) TB');";
    252     echo "   data.addRows([";
    253     $interval = 10;
    254     $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;";
    255     if ($debug) {echo "$sql<br>";}
    256     $qry = $db->query($sql);
    257     if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
    258     while ($qry->fetchInto($row)) {
    259         $tsp = explode('.', $row[0]);
    260         $mon = $tsp[1]-1;
    261         $timestamp = $row[0];
    262         $usable    = $row[1];
    263         $available = $row[2];
    264 #       new Date(Year, Month, Day, Hours, Minutes, Seconds, Milliseconds)
    265        echo "[new Date($tsp[0], $mon, $tsp[2], $tsp[3], $tsp[4]), $usable, $available],";
    266     }
    267    echo "  ]);";
    268    echo "   var options = {";
    269    echo "      chart: {"; 
    270    echo "               position: 'center', " ;
    271    echo "              },";
    272    echo "     title: 'Total Available Cluster Space in the Past $interval Days ($allocated% of total allocated)',";
    273    echo "     titleTextStyle: {color: 'black', fontSize: 15},";
    274    echo "     width: '100%',";
    275    echo "     height: 400,";
    276    echo "     legend: { position: 'top',";
    277    echo "               alignment: 'center',";
    278    echo "              },";
    279    echo "     lineWidth: 2, ";
    280    echo "     series: {";
    281    echo "         0: { color: '#0000ff', lineWidth: 3 },      ";
    282    echo "         1: { color: '#33a532', lineWidth: 3 },      ";
    283    echo "              },";
    284    echo "     hAxis: {  ";
    285    echo "             title: 'Date/Time (HST)',";
    286    echo "             format: 'MMM dd',";
    287    echo "            gridlines: {count: -1},";
    288    echo "     },";
    289    echo "     vAxis: {  ";
    290    echo "                  title: 'Available (TB)',";
    291    echo "     viewWindow: {   min: 500    },  ";
    292    echo "     },";
    293    echo "     chartArea: {left:80, top:50, right:20, bottom:50},";
    294    echo "     fontSize: 12,";
    295    echo "   };";
    296    echo "   var chart = new google.visualization.LineChart(document.getElementById('space_div'));";
    297    echo "   chart.draw(data, options);";
    298    echo " }";
    299    echo "</script>";
    300     $time = microtime();
    301     $time = explode(' ', $time);
    302     $time = $time[1] + $time[0];
    303     $finish = $time;
    304     $total_time = round(($finish - $start), 3);
    305     $start= $finish;
    306     echo "<center>loading in $total_time seconds<br></center>";
    307 }
    308 
    309 
    31041?>
    31142
Note: See TracChangeset for help on using the changeset viewer.