Changeset 42921 for trunk/ippMonitor/raw/czartool_labels.php
- Timestamp:
- Sep 10, 2025, 1:11:48 PM (10 months ago)
- File:
-
- 1 edited
-
trunk/ippMonitor/raw/czartool_labels.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippMonitor/raw/czartool_labels.php
r42902 r42921 1706 1706 # 1707 1707 ########################################################################### 1708 function getHosts ($db) {1708 function getHostsold($db) { 1709 1709 // timer start 1710 1710 $time = microtime(); … … 1716 1716 echo "<script type=\"text/javascript\" src=\"loader.js\"></script>"; 1717 1717 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>"; 1719 1719 echo " <div class=\"overlay\" style=\"position: absolute; width: 100px; top: 35px; right: 20px;\">"; 1720 1720 echo " <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #00ff00\"><center>Free</div>"; … … 1735 1735 echo " 'free', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}],"; 1736 1736 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 "; 1738 1739 if ($debug) {echo "$sql<br>";} 1739 1740 $qry = $db->query($sql); … … 1753 1754 if ($ratio >= 97) { 1754 1755 # space used over limits, up mode (read/write ok). 1755 echo "[ \"$host \", ";1756 echo "[ \"$host:up\", "; 1756 1757 echo " $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ff0000;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", "; 1757 1758 echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],"; … … 1759 1760 else { 1760 1761 # enough space, up mode (read/write ok). 1761 echo "[ \"$host \", ";1762 echo "[ \"$host:up\", "; 1762 1763 echo " $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", "; 1763 1764 echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],"; … … 1767 1768 if ($ratio >= 97) { 1768 1769 # space used over limits, repair mode (read only). 1769 echo "[ \"$host \", ";1770 echo "[ \"$host:repair\", "; 1770 1771 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]\", "; 1771 1772 echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],"; … … 1773 1774 else { 1774 1775 # enough space, but hosts are unstable, repair mode (read only). 1775 echo "[ \"$host \", ";1776 echo "[ \"$host:repair\", "; 1776 1777 echo " $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used<br>$hostnote[0]\", "; 1777 1778 echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],"; … … 1780 1781 else { 1781 1782 # down mode (can't read or write). 1782 echo "[ \"$host \", ";1783 echo "[ \"$host:down\", "; 1783 1784 echo " $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $ratio% used<br>$hostnote[0]\", "; 1784 1785 echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],"; … … 1798 1799 echo " gridlines: {count: 10}"; 1799 1800 echo " },"; 1801 echo " vAxis: { textPosition: 'in', direction: 1 },"; 1800 1802 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},"; 1802 1804 echo " fontSize: 15,"; 1803 1805 echo " isStacked: true,"; … … 1819 1821 ########################################################################### 1820 1822 # 1823 # Gets disk status 1824 # 1825 ########################################################################### 1826 function 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 # 1821 1963 # Gets disk spaces status 1822 1964 # … … 1829 1971 $start = $time; 1830 1972 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); 1832 1975 $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); 1834 1977 $ippbfree = $row[0]; 1835 1978 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); 1837 1980 $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); 1839 1982 $ippfree = $row[0]; 1840 1983 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 1841 1989 $sql = "select format(used/total*100,1), usable from cluster_space order by timestamp desc limit 1;"; 1990 1842 1991 if ($debug) {echo "$sql<br>";} 1843 1992 $qry = $db->query($sql); … … 1851 2000 echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640; height:400\">"; 1852 2001 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 (latestusable)</b></div>";1855 echo " <div style=\"font-size: 16px; color:#33a532; background-color:#ffffff\"><b>ipp + ippb nodes: $ippfree + $ippbfree TB (latestfree)</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>"; 1856 2005 echo " </div>"; 1857 2006 echo "</div>"; … … 1863 2012 echo " var data = new google.visualization.DataTable();"; 1864 2013 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');"; 1867 2016 echo " data.addRows(["; 1868 2017 $interval = 10;
Note:
See TracChangeset
for help on using the changeset viewer.
