Added client work scripts
[clearscm.git] / clients / GD / FSMon / graphFS.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        graphFS.php
5 // Revision:    0.1
6 // Description: Produce a graph showing file system sizes
7 //              date range.
8 // Author:      Andrew@ClearSCM.com
9 // Created:     Mon Apr 28 15:20:06 MST 2008
10 // Modified:    
11 // Language:    PHP
12 //
13 // (c) Copyright 2008, ClearSCM Inc., all rights reserved.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16 $script = basename ($_SERVER["PHP_SELF"]);
17 //$inc  = $_SERVER["DOCUMENT_ROOT"];
18 $inc = "/var/www/html/Fsmon";
19
20 include_once "$inc/FsmonDB.php";
21 include_once "$inc/Fsutils.php";
22
23 include_once "$inc/pChart/pData.class";
24 include_once "$inc/pChart/pChart.class";
25
26 $system = $_REQUEST["system"];
27 $mount  = $_REQUEST["mount"];
28
29 $debug;
30
31 function mydebug ($msg) {
32   $debug = fopen ("/tmp/debug.log", "a");
33
34   fwrite ($debug, "$msg\n");
35 } // mydebug
36
37 function setScaling () {
38   if ($_REQUEST["scale"] == "byte") {
39     return BYTE;
40   } elseif ($_REQUEST["scale"] == "kbyte") {
41     return KBYTE;
42   } elseif ($_REQUEST["scale"] == "meg") {
43     return MEG;
44   } else {
45     return GIG;
46   } // if
47 } // if
48
49 function setPeriod () {
50   if ($_REQUEST["period"] == "hourly") {
51     return $_REQUEST["period"];
52   } elseif ($_REQUEST["period"] == "weekly") {
53     return $_REQUEST["period"];
54   } elseif ($_REQUEST["period"] == "monthly") {
55     return $_REQUEST["period"];
56   } else {
57     return "daily";
58   } // if
59 } // if
60
61 openDB ();
62
63 $scaling = setScaling ();
64 $period  = setPeriod ();
65
66 $data   = getFSInfo ($system, $mount, $period);
67
68 $fonts  = "$inc/Fonts";
69
70 // Dataset definition   
71 $DataSet = new pData;
72
73 $system = "Unknown";
74 $mount  = "Unknown";
75
76 foreach ($data as $result) {
77   $system       = $result["sysname"];
78   $mount        = $result["mount"];
79
80   // Set X Axis label properly
81   if ($period == "hourly") {
82     $hours      = substr ($result["timestamp"], 11, 2);
83     $minutes    = substr ($result["timestamp"], 14, 2);
84     $ampm       = "Am";
85
86     if ($hours > 12) {
87       $hours    = $hours - 12;
88       $ampm     = "Pm";
89     } elseif ($hours < 10) {
90       $hours    = substr ($hours, 1, 1);
91     } // if
92
93     $Xlabel     = "$hours:$minutes $ampm";
94   } elseif ($period == "daily") {
95     $day        = substr ($result["timestamp"], 8, 2);
96  
97     if ($day < 10) {
98       $day      = substr ($day, 1, 1);
99     } // if
100     
101     $month      = substr ($result["timestamp"], 5, 2);
102  
103     if ($month < 10) {
104       $month    = substr ($month, 1, 1);
105     } // if
106     
107     $year       = substr ($result["timestamp"], 0, 4);
108     $Xlabel     = "$month/$day/$year";
109   } elseif ($period == "weekly") {
110     $Xlabel     = "Weekly not implemented";
111   } elseif ($period == "monthly") {
112     $month      = substr ($result["timestamp"], 5, 2);
113  
114     if ($month < 10) {
115       $month    = substr ($month, 1, 1);
116     } // if
117     
118     $year       = substr ($result["timestamp"], 0, 4);
119     $Xlabel     = "$month/$year";
120   } else {
121     $Xlabel     = $result["timestamp"];
122   } // if
123
124   $DataSet->AddPoint ($result["used"] / $scaling, "Used", $Xlabel);
125   $DataSet->AddPoint ($result["free"] / $scaling, "Free", $Xlabel);
126 } // foreach
127
128 $DataSet->AddAllSeries();
129 $DataSet->SetAbsciseLabelSerie();
130
131 $DataSet->SetXAxisName ("Time");
132
133 // Initialise the graph
134 $Test = new pChart (700, 280);
135
136 $Test->setColorPalette (1, 0, 255, 0);
137 $Test->setColorPalette (0, 255, 0, 0);
138
139 $Test->drawGraphAreaGradient (100, 150, 175, 100, TARGET_BACKGROUND);
140 $Test->setFontProperties ("$fonts/tahoma.ttf", 8);
141
142 if ($scaling == BYTE) {
143   $Test->setGraphArea (110, 30, 680, 200);
144   $DataSet->SetYAxisName ("Bytes");
145 } elseif ($scaling == KBYTE) {
146   $Test->setGraphArea (90, 30, 680, 200);
147   $DataSet->SetYAxisName ("Kbytes");
148 } elseif ($scaling == MEG) {
149   $Test->setGraphArea (70, 30, 680, 200);
150   $DataSet->SetYAxisName ("Meg");
151 } else {
152   $Test->setGraphArea (55, 30, 680, 200);
153   $DataSet->SetYAxisName ("Gig");
154 } // if  
155
156 $Test->drawRoundedRectangle (5, 5, 695, 275, 5, 230, 230, 230);
157 $Test->drawGraphAreaGradient (162, 183, 202, 50);
158 $Test->drawScale ($DataSet->GetData (), $DataSet->GetDataDescription (), SCALE_ADDALLSTART0, 200, 200, 200, true, 70, 2, true);
159 $Test->drawGrid (4, true, 230, 230, 230, 50);
160
161 // Draw the 0 line
162 $Test->setFontProperties ("$fonts/tahoma.ttf", 6);
163 $Test->drawTreshold (0, 143, 55, 72, true, true);
164
165 // Draw the bar graph
166 $Test->drawStackedBarGraph ($DataSet->GetData (), $DataSet->GetDataDescription (), 75);
167
168 // Finish the graph
169 $Test->setFontProperties ("$fonts/tahoma.ttf",8);
170 $Test->drawLegend (610, 35, $DataSet->GetDataDescription (), 130, 180, 205);
171 $Test->setFontProperties ("$fonts/tahoma.ttf", 10);
172 $Test->drawTitle (50, 22, "$system:$mount ($period)", 255, 255, 255, 675);
173 $Test->Stroke ();
174 ?>