Added client work scripts
[clearscm.git] / clients / GD / FSMon / fsmon.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        fsmon.php
5 // Description: Produce a graph of filesystem usage
6 // Author:      Andrew@ClearSCM.com
7 // Created:     Mon Apr 28 15:20:06 MST 2008
8 // Modified:    
9 // Language:    PHP
10 //
11 // (c) Copyright 2008, ClearSCM Inc., all rights reserved.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 $script = basename ($_SERVER["PHP_SELF"]);
15
16 include_once "FsmonDB.php";
17 include_once "Fsutils.php";
18
19 $version = VERSION;
20
21 $system = $_REQUEST["system"];
22 $mount  = $_REQUEST["mount"];
23 $period = $_REQUEST["period"];
24 $scale  = $_REQUEST["scale"];
25
26 function createHeader () {
27   global $version, $system, $mount;
28
29   $sysLabel     = (empty ($system)) ? "All Systems"     : $system;
30   $mountLabel   = (empty ($mount))  ? "All Filesystems" : $mount;
31
32   $header = <<<END
33 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
34    "http://www.w3.org/TR/html4/strict.dtd">
35 <html>
36 <head>
37   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
38   <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
39   <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
40   <title>FSMon v($version) $sysLabel - $mountLabel</title>
41 </head>
42 <body>
43 END;
44
45   $header .= banner ();
46   $header .= <<<END
47 <h1 align="center">Filesystem Monitor</h1>
48 END;
49
50   return $header;
51 } // createHeader
52
53 function createPage ($system, $mount = "", $period = "daily", $scale = "gig") {
54   $data = getFSInfo ($system, $mount, $period);
55
56   $page .= <<<END
57 <table align=center>
58   <thead>
59     <tr>
60       <th class="left">System</th>
61       <th>Mount Point</th>
62       <th>Timestamp</th>
63       <th>Size</th>
64       <th>Used</th>
65       <th>Free</th>
66       <th class="right">Reserve</th>
67     </tr>
68   </thead>
69   <tbody>
70 END;
71
72   foreach ($data as $line) {
73     $page .= <<<END
74       <tr class="white">
75         <td>$line[sysname]</td>
76         <td>$line[mount]</td>
77         <td>$line[timestamp]</td>
78         <td align="right">$line[size]</td>
79         <td align="right">$line[used]</td>
80         <td align="right">$line[free]</td>
81         <td align="right">$line[reserve]</td>
82       </tr>
83 END;
84   } // foreach
85     
86   $page .=<<<END
87   </tbody>
88 </table>
89 END;
90
91   return $page;
92 } // createPage
93
94 function displayReport ($system = "", $mount = "", $period = "daily", $scale = "gig") {
95   print createPage ($system, $mount, $period, $scale);
96 } // displayReport
97
98 function displayMount ($system = "", $mount = "", $period = "daily", $scale = "gig") {
99   global $script;
100
101   print <<<END
102 <table cellspacing="0" align="center">
103   <tr>
104     <form action="$script">
105     <td align="center">System:&nbsp;
106       <select name="system" class="inputfield">
107 END;
108
109  foreach (getSystem () as $item) {
110    print "<option";
111
112    if ($item["name"] == $system) {
113      print " selected=\"selected\"";
114    } // if
115
116    print ">$item[name]</option>";
117  } // foreach
118
119   print <<<END
120       </select>
121     &nbsp;Mount:&nbsp;
122       <select name="mount" class="inputfield">
123 END;
124
125   foreach (getMounts ($system) as $item) {
126     print "<option";
127
128     if ($item == $mount) {
129       print " selected=\"selected\"";
130     } // if
131
132     print ">$item</option>";
133   } // foreach
134
135   print <<<END
136       </select>
137     &nbsp;Period:&nbsp;
138       <select name="period" class="inputfield">
139 END;
140
141   foreach (getPeriods () as $item) {
142    print "<option";
143
144    if ($item == $period) {
145      print " selected=\"selected\"";
146    } // if
147
148    print ">$item</option>";
149  } // foreach
150
151   print <<<END
152       </select>
153     &nbsp;Scale:&nbsp;
154       <select name="scale" class="inputfield">
155 END;
156
157   foreach (getScales () as $item) {
158     print "<option";
159
160     if ($item == $scale) {
161       print " selected=\"selected\"";
162     } // if
163
164     print ">$item</option>";
165   } // foreach
166
167   print <<<END
168       </select>
169       &nbsp;<input type="submit" value="Graph" /></form>
170     </td>
171   </tr>
172   <tr>
173     <td align="center">
174       <img src="graphFS.php?system=$system&mount=$mount&period=$period&scale=$scale">
175     </td>
176   </tr>
177 </table>
178 END;
179 //  displayReport ($system, $mount, $period, $scale);
180 } // displayMount
181
182 function displayFilesystems ($system = "", $mount = "", $period = "daily", $scale = "gig") {
183   if (empty ($mount)) {
184     foreach (getMounts ($system) as $mount) {
185       displayMount ($system, $mount, $period, $scale);
186       print "<p></p>";
187     } // foreach
188   } else {
189     displayMount ($system, $mount, $period, $scale);
190   } // if
191 } // displayFilesystems
192
193 function displayGraph ($system = "", $mount = "", $period = "daily", $scale = "gig") {
194   print createHeader ();
195
196   if (empty ($system)) {
197     foreach (getSystem () as $system) {
198       displayFilesystems ($system["name"], $mount, $period, $scale);
199     } // foreach
200   } else {
201     displayFilesystems ($system, $mount, $period, $scale);
202   } // if
203 } // displayGraph
204
205 openDB ();
206
207 if (empty ($system)) {
208   print createHeader ();
209   print "<ul>";
210
211   foreach (getSystem () as $system) {
212     print "<li><a href=$script?system=$system[name]>$system[name]</a></li>";
213
214 //    print "<ul>";
215
216 //    $mounts = getMounts ($system["name"]);
217
218 //    foreach ($mounts as $mount) {
219 //      print "<li><a href=$script?system=$system[name]&mount=$mount>$mount</a></li>";
220 //    } // foreach
221
222 //    print "</ul>";
223   } // foreach
224
225   print "</ul>";
226 } else {
227   displayGraph ($system, $mount, $period, $scale);
228 } // if
229
230 print copyright ();
231 ?>
232 </body>
233 </html>