IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 10, 2025, 1:11:48 PM (10 months ago)
Author:
cclin33
Message:

update storage views

File:
1 edited

Legend:

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

    r42902 r42921  
    17061706#
    17071707###########################################################################
    1708 function getHosts($db) {
     1708function getHostsold($db) {
    17091709    // timer start
    17101710    $time = microtime();
     
    17161716    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
    17171717    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640px\">";
    1718     echo "  <div id=\"disk_div\" style=\"width:640px; height:4000px\"></div>";
     1718    echo "  <div id=\"disk_div\" style=\"width:640px; height:5000px\"></div>";
    17191719    echo "  <div class=\"overlay\" style=\"position: absolute; width: 100px; top: 35px; right: 20px;\">";
    17201720    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #00ff00\"><center>Free</div>";
     
    17351735    echo "     'free', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}],";
    17361736
    1737     $sql = "SELECT host, format(total,1), format(available,2), format(used,2), writable, readable, format(used/total*100,2) FROM hosts where host like 'ipp1%' or host like 'ippb%' order by host";
     1737    //$sql = "SELECT host, format(total,1), format(available,2), format(used,2), writable, readable, format(used/total*100,2) FROM hosts";
     1738    $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 ";
    17381739    if ($debug) {echo "$sql<br>";}
    17391740    $qry = $db->query($sql);
     
    17531754          if ($ratio >= 97) {
    17541755            # space used over limits, up mode (read/write ok).
    1755             echo "[ \"$host\", ";
     1756            echo "[ \"$host:up\", ";
    17561757            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ff0000;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", ";
    17571758            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],";
     
    17591760          else {
    17601761            # enough space, up mode (read/write ok).
    1761             echo "[ \"$host\", ";
     1762            echo "[ \"$host:up\", ";
    17621763            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", ";
    17631764            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],";
     
    17671768          if ($ratio >= 97) {
    17681769            # space used over limits, repair mode (read only).
    1769             echo "[ \"$host\", ";
     1770            echo "[ \"$host:repair\", ";
    17701771            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]\", ";
    17711772            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
     
    17731774          else {
    17741775            # enough space, but hosts are unstable, repair mode (read only).
    1775             echo "[ \"$host\", ";
     1776            echo "[ \"$host:repair\", ";
    17761777            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used<br>$hostnote[0]\", ";
    17771778            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
     
    17801781       else {
    17811782            # down mode (can't read or write).
    1782             echo "[ \"$host\", ";
     1783            echo "[ \"$host:down\", ";
    17831784            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $ratio% used<br>$hostnote[0]\", ";
    17841785            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
     
    17981799   echo "               gridlines: {count: 10}";
    17991800   echo "     },";
     1801   echo "     vAxis: { textPosition: 'in', direction: 1 },";
    18001802   echo "     bar: { groupWidth: '95%' },";
    1801    echo "     chartArea: {left:100, top:30, right:20, bottom:40},";
     1803   echo "     chartArea: {left:20, top:30, right:20, bottom:40},";
    18021804   echo "     fontSize: 15,";
    18031805   echo "     isStacked: true,";
     
    18191821###########################################################################
    18201822#
     1823# Gets disk status
     1824#
     1825###########################################################################
     1826function getHosts($db) {
     1827    $start = microtime(true);
     1828
     1829    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
     1830    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 100%\">";
     1831    echo "  <div id=\"disk_div\" style=\"width:100%; height:5000px\"></div>";
     1832    echo "  <div class=\"overlay\" style=\"position: absolute; width: 100px; top: 50px; right: 20px;\">";
     1833    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: lightgreen\"><center>Free</div>";
     1834    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: yellow\"><center>Used</div>";
     1835    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: pink\"><center>> 97% limit</div>";
     1836    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: lightgrey\"><center>Down | Repair</div>";
     1837    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: white\"><center>Offline</div>";
     1838    echo "  </div>";
     1839    echo "</div>";
     1840
     1841    // Set environment variables
     1842    putenv("PATH=/usr/local/bin:/usr/bin:/bin:/data/ippc65.0/ipp/src/psconfig//ipp-20210708-gentoo.lin64/bin");
     1843    putenv("PERL5LIB=/data/ippc65.0/ipp/src/psconfig//ipp-20210708-gentoo.lin64/lib");
     1844
     1845    $hostnoteall = array();
     1846    exec("neb-host |cut -b 17-30,86-", $hostnoteall);
     1847
     1848    $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 ";
     1849    $qry = $db->query($sql);
     1850
     1851    if ($qry === false) {
     1852        echo "<b>Error with SQL query</b><br>";
     1853        return;
     1854    }
     1855
     1856    $dataRows = array();
     1857    $maxUsed = 0;   // initialize before the while loop
     1858
     1859    while ($qry->fetchInto($row)) {
     1860        // Access by index
     1861        $host      = $row[0]; // ipp071.0
     1862        $total     = $row[1]; // 80.0352 TB
     1863        $available = $row[2]; // 10.8096 TB
     1864        $used      = $row[3]; // 69.2256 TB
     1865        $writable  = $row[4]; // 0
     1866        $readable  = $row[5]; // 1
     1867        $ratio     = $row[6]; // 86.4939 %
     1868
     1869        // update maxUsed
     1870        if ($total > $maxUsed) {
     1871            $maxUsed = $total/2;
     1872        }
     1873
     1874        // Match notes
     1875        $hostnotes = preg_grep("/$host/", $hostnoteall);
     1876        $hostnote = reset($hostnotes);
     1877
     1878        // Defaults
     1879        $styles    = "stroke-width: .5; stroke-color: black;";
     1880        $status    = "down";
     1881        $usedColor = "lightgrey";
     1882        $freeColor = "lightgrey";
     1883
     1884        // Status logic
     1885        if ($writable == 1 && $readable == 1) {
     1886            $status    = "up";
     1887            $usedColor = ($ratio >= 97) ? "pink" : "yellow"; // red if ≥97%
     1888            $freeColor = "#a6ec99"; // green free
     1889        } elseif ($writable == 0 && $readable == 1) {
     1890            $status    = "repair";
     1891            $usedColor = ($ratio >= 97) ? "pink" : "yellow";
     1892            $freeColor = "lightgrey"; // grey free
     1893        } elseif ($available < 1) {
     1894            $used      = $maxUsed;
     1895            $available = $maxUsed;
     1896            $status    = "offline";
     1897            $usedColor = "white";
     1898            $freeColor = "white";
     1899        }
     1900
     1901        if ($status == "down") {
     1902            $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used ".
     1903                           "<span style='color:red; font-weight:bold;'> <br>" . $hostnote .  "</span>";
     1904            $tooltipFree = "<span style='color:red; font-weight:bold;'>" .
     1905                           $host . ": " . $available . " TB free" .
     1906                           "</span>";
     1907        } elseif ($status == "offline") {
     1908            $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used ".
     1909                           "<span style='color:red; font-weight:bold;'> <br>" . $hostnote .  "</span>";
     1910            $tooltipFree = "<span style='color:red; font-weight:bold;'>" .
     1911                           $host . ": " . $total . " TB free" .
     1912                           "</span>";
     1913        } else {
     1914            $tooltipUsed = $host . ": " . round($ratio, 1) . "% of " . $total . " TB used<br>" . $hostnote;
     1915            $tooltipFree = $host . ": " . $available . " TB free";
     1916        }
     1917
     1918        // Build data row (manual string concatenation for old PHP)
     1919        $dataRows[] =
     1920            "[ \"" . $host . ":" . $status . "\", " .
     1921            $used . ", \"" . $styles . " color: " . $usedColor . ";\", \"" . $tooltipUsed . "\", " .
     1922            $available . ", \"" . $styles . " color: " . $freeColor . ";\", \"" . $tooltipFree . "\" ]";
     1923
     1924    }
     1925    echo "<script type=\"text/javascript\">
     1926            google.charts.load('current', {packages: ['corechart', 'bar']});
     1927            google.charts.setOnLoadCallback(drawBarColors);
     1928
     1929            function drawBarColors() {
     1930                var data = google.visualization.arrayToDataTable([
     1931                    ['Host', 'Used', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}},
     1932                     'Free', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}],
     1933                    " . implode(",\n", $dataRows) . "
     1934                ]);
     1935
     1936                var options = {
     1937                    title: 'Nebulous Disk Use across IPP Clusters',
     1938                    titleTextStyle: {color: 'black', fontSize: 15},
     1939                    width: '100%',
     1940                    height: '100%',
     1941                    tooltip: {isHtml: true},
     1942                    legend: { position: 'none', alignment: 'end', maxLines: 3 },
     1943                    hAxis: { title: 'Space (TB)', gridlines: {count: 20} },
     1944                    vAxis: { textStyle: {fontSize: 14}, format: 'string',  textPosition: 'in', direction: 1},
     1945                    bar: { groupWidth: '95%' },
     1946                    chartArea: {left:40, top:50, right:20, bottom:40},
     1947                    fontSize: 15,
     1948                    allowHtml: true,
     1949                    isStacked: true
     1950                };
     1951
     1952                var chart = new google.visualization.BarChart(document.getElementById('disk_div'));
     1953                chart.draw(data, options);
     1954            }
     1955          </script>";
     1956
     1957    $total_time = round(microtime(true) - $start, 3);
     1958    echo "<center>loading in $total_time seconds<br></center>";
     1959}
     1960
     1961###########################################################################
     1962#
    18211963# Gets disk spaces status
    18221964#
     
    18291971    $start = $time;
    18301972
    1831     $db->query("SELECT sum(format(available, 2)) FROM hosts where host like 'ippb%'")->fetchInto($row);
     1973
     1974    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ippb%' and xattr <> 3")->fetchInto($row);
    18321975    $ippbusable = $row[0];
    1833     $db->query("SELECT sum(format(available, 2)) FROM hosts where host like 'ippb%' and writable = 1")->fetchInto($row);
     1976    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ippb%' and writable = 1 and xattr <> 3")->fetchInto($row);
    18341977    $ippbfree = $row[0];
    18351978
    1836     $db->query("SELECT sum(format(available, 2)) FROM hosts where host not like 'ippb%'")->fetchInto($row);
     1979    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host not like 'ippb%' and xattr <> 3")->fetchInto($row);
    18371980    $ippusable = $row[0];
    1838     $db->query("SELECT sum(format(available, 2)) FROM hosts where host not like 'ippb%' and writable = 1")->fetchInto($row);
     1981    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host not like 'ippb%' and writable = 1 and xattr <> 3")->fetchInto($row);
    18391982    $ippfree = $row[0];
    18401983
     1984    $db->query("SELECT FORMAT(IFNULL(SUM(available), 0), 1) FROM hosts where host like 'ipp%_bck.0' and xattr <> 3")->fetchInto($row);
     1985    $bckusable = $row[0];
     1986    $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);
     1987    $bckfree = $row[0];
     1988
    18411989    $sql = "select format(used/total*100,1), usable from cluster_space order by timestamp desc limit 1;";
     1990
    18421991    if ($debug) {echo "$sql<br>";}
    18431992    $qry = $db->query($sql);
     
    18512000    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640; height:400\">";
    18522001    echo "  <div id=\"space_div\" style=\"width:640; \"></div>";
    1853     echo "  <div class=\"overlay\" style=\"position: absolute; width: 400px; bottom: 60px; left: 85px;\">";
    1854     echo "    <div style=\"font-size: 16px; color:#0000ff; background-color:#ffffff\"><b>ipp + ippb nodes: $ippusable + $ippbusable TB (latest usable)</b></div>";
    1855     echo "    <div style=\"font-size: 16px; color:#33a532; background-color:#ffffff\"><b>ipp + ippb nodes: $ippfree + $ippbfree TB (latest free)</b></div>";
     2002    echo "  <div class=\"overlay\" style=\"position: absolute; width: 500px; bottom: 60px; left: 85px;\">";
     2003    echo "    <div style=\"font-size: 16px; color:#0000ff; \"><b>ipp*_bck: $bckusable TB (usable)</b></div>";
     2004    echo "    <div style=\"font-size: 16px; color:#33a532; \"><b>ipp*_bck: $bckfree   TB (free)</b></div>";
    18562005    echo "  </div>";
    18572006    echo "</div>";
     
    18632012    echo "  var data = new google.visualization.DataTable();";
    18642013    echo "        data.addColumn('datetime', 'Day');";
    1865     echo "        data.addColumn('number', 'Usable');";
    1866     echo "        data.addColumn('number', 'Free');";
     2014    echo "        data.addColumn('number', 'Usable (ipp:$ippusable, ippb:$ippbusable) TB');";
     2015    echo "        data.addColumn('number', 'Free (ipp:$ippfree, ippb:$ippbfree) TB');";
    18672016    echo "   data.addRows([";
    18682017    $interval = 10;
Note: See TracChangeset for help on using the changeset viewer.