2 ////////////////////////////////////////////////////////////////////////////////
5 // Description: PHP Module to access the fsmon database
6 // Author: Andrew@ClearSCm.com
7 // Created: Mon Apr 28 15:20:06 MST 2008
11 // (c) Copyright 2008, ClearSCM Inc., all rights reserved.
13 ////////////////////////////////////////////////////////////////////////////////
14 include_once ("Fsutils.php");
26 $na = "<font color=#999999>N/A</font>";
28 function dbError ($msg, $statement) {
29 $errno = mysql_errno ();
30 $errmsg = mysql_error ();
33 <h2><font color="red">ERROR:</font> $msg</h2>
34 <b>Error #$errno:</b><br>
35 <blockquote>$errmsg</blockquote>
36 <b>SQL Statement:</b><br>
37 <blockquote>$statement</blockquote>
44 global $dbserver, $userid, $password, $dbname;
46 $db = mysql_connect ($dbserver, $userid, $password)
47 or dbError (__FUNCTION__ . ": Unable to connect to database server $dbserver", "Connect");
49 mysql_select_db ($dbname)
50 or dbError (__FUNCTION__ . ": Unable to select the $dbname database", "$dbname");
53 function getFSInfo ($system = "", $mount = "", $period = "daily") {
54 $sysCondition = (isset ($system)) ? "where sysname = \"$system\"" : "";
55 $mountCondition = (isset ($mount)) ? " and mount = \"$mount\"" : "";
57 if (!($period == "hourly" or
59 $period == "weekly" or
60 $period == "monthly")) {
61 error ("Invalid period - $period - specified", 1);
81 $result = mysql_query ($statement)
82 or DBError ("Unable to execute query: ", $statement);
89 while ($row = mysql_fetch_array ($result)) {
90 $line["sysname"] = $row["sysname"];
91 $line["mount"] = $row["mount"];
92 $line["timestamp"] = $row["timestamp"];
94 // Snapshot's finest granularity is 1 hour intervals. If hourly
95 // therefore just capture the data an move on.
96 if ($period == "hourly") {
97 $line["size"] = $row["size"];
98 $line["used"] = $row["used"];
99 $line["free"] = $row["free"];
100 $line["reserve"] = $row["reserve"];
101 } elseif ($period == "daily") {
102 $thisPeriod = substr ($row["timestamp"], 0, 10);
104 if ($lastPeriod == "") {
105 $lastPeriod = $thisPeriod;
106 } elseif ($lastPeriod == $thisPeriod) {
110 $lastPeriod = $thisPeriod;
112 if ($row["used"] > $maxUsed) {
113 $maxUsed = $row["used"];
114 $line["size"] = $row["size"];
115 $line["used"] = $row["used"];
116 $line["free"] = $row["free"];
117 $line["reserve"] = $row["reserve"];
121 } elseif ($period == "weekly") {
122 error ("Weekly not handled yet", 1);
123 } elseif ($period == "monthly") {
124 $thisPeriod = substr ($row["timestamp"], 0, 7);
125 if ($lastPeriod == "") {
126 $lastPeriod = $thisPeriod;
127 } elseif ($lastPeriod == $thisPeriod) {
131 if ($row["used"] > $maxUsed) {
132 $maxUsed = $row["used"];
133 $line["size"] = $row["size"];
134 $line["used"] = $row["used"];
135 $line["free"] = $row["free"];
136 $line["reserve"] = $row["reserve"];
142 array_push ($data, $line);
148 function getSystem ($system = "") {
149 $statement = "select * from system";
151 if (isset ($system) and $system != "") {
152 $statement .= " where name = \"$system\"";
155 $result = mysql_query ($statement)
156 or DBError ("Unable to execute query: ", $statement);
160 while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
161 array_push ($data, $row);
167 function getMounts ($system) {
168 $statement = "select mount from filesystems where sysname = \"$system\" order by mount";
170 $result = mysql_query ($statement)
171 or DBError ("Unable to execute query: ", $statement);
175 while ($row = mysql_fetch_array ($result)) {
176 array_push ($data, $row["mount"]);