1 | <?php |
---|
2 | /* |
---|
3 | * |
---|
4 | * This file is part of Jobmonarch |
---|
5 | * |
---|
6 | * Copyright (C) 2006 Ramon Bastiaans |
---|
7 | * |
---|
8 | * Jobmonarch is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * Jobmonarch is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | * |
---|
22 | * SVN $Id: index.php 266 2006-06-26 11:38:27Z bastiaans $ |
---|
23 | */ |
---|
24 | |
---|
25 | if ( !empty( $_GET ) ) { |
---|
26 | extract( $_GET ); |
---|
27 | } |
---|
28 | |
---|
29 | $my_dir = getcwd(); |
---|
30 | |
---|
31 | include_once "./libtoga.php"; |
---|
32 | |
---|
33 | global $GANGLIA_PATH; |
---|
34 | chdir( $GANGLIA_PATH ); |
---|
35 | |
---|
36 | include_once "./class.TemplatePower.inc.php"; |
---|
37 | chdir( $my_dir ); |
---|
38 | |
---|
39 | $httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET ); |
---|
40 | $clustername = $httpvars->getClusterName(); |
---|
41 | $view = $httpvars->getHttpVar( "view" ); |
---|
42 | |
---|
43 | $filter = array(); |
---|
44 | |
---|
45 | if( !isset($view) ) $view = "overview"; |
---|
46 | if( !isset($sortorder) ) $sortorder = "asc"; |
---|
47 | if( !isset($sortby) ) $sortby = "id"; |
---|
48 | |
---|
49 | if( isset( $filterorder ) && ($filterorder!='') ) { |
---|
50 | $myfilter_fields = explode( ",", $filterorder ); |
---|
51 | } else { |
---|
52 | if( isset($queue) && ($queue!='')) $filter[queue]=$queue; |
---|
53 | if( isset($state) && ($state!='')) $filter[state]=$state; |
---|
54 | if( isset($user) && ($user!='')) $filter[user]=$user; |
---|
55 | if( isset($id) && ($id!='')) $filter[id]=$id; |
---|
56 | } |
---|
57 | |
---|
58 | // Fill filter array in order they were picked by user |
---|
59 | foreach( $myfilter_fields as $myfilter ) { |
---|
60 | |
---|
61 | switch( $myfilter ) { |
---|
62 | |
---|
63 | case "queue": |
---|
64 | $filter[queue]=$queue; |
---|
65 | break; |
---|
66 | case "state": |
---|
67 | $filter[state]=$state; |
---|
68 | break; |
---|
69 | case "user": |
---|
70 | $filter[user]=$user; |
---|
71 | break; |
---|
72 | case "id": |
---|
73 | $filter[id]=$id; |
---|
74 | break; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | //if( isset($queue) && ($queue!='')) $filter[queue]=$queue; |
---|
79 | //if( isset($state) && ($state!='')) $filter[state]=$state; |
---|
80 | //if( isset($user) && ($user!='')) $filter[user]=$user; |
---|
81 | //if( isset($id) && ($id!='')) $filter[id]=$id; |
---|
82 | |
---|
83 | function epochToDatetime( $epoch ) { |
---|
84 | |
---|
85 | return strftime( "%d-%m-%Y %H:%M:%S", $epoch ); |
---|
86 | } |
---|
87 | |
---|
88 | function makeHeader( $page_call ) { |
---|
89 | |
---|
90 | global $tpl, $grid, $context, $initgrid; |
---|
91 | global $jobrange, $jobstart, $title; |
---|
92 | global $page, $gridwalk, $clustername; |
---|
93 | global $parentgrid, $physical, $hostname; |
---|
94 | global $self, $filter, $cluster_url, $get_metric_string; |
---|
95 | global $metrics, $reports, $m, $default_metric; |
---|
96 | global $default_refresh, $filterorder, $view; |
---|
97 | global $JOB_ARCHIVE, $period_start, $period_stop, $h, $id; |
---|
98 | global $job_start, $job_stop; |
---|
99 | |
---|
100 | if( isset($default_metric) and !isset($m) ) |
---|
101 | $metricname = $default_metric; |
---|
102 | else |
---|
103 | if( isset( $m ) ) |
---|
104 | $metricname = $m; |
---|
105 | else |
---|
106 | $metricname = "load_one"; |
---|
107 | |
---|
108 | $header = "header"; |
---|
109 | |
---|
110 | # Maintain our path through the grid tree. |
---|
111 | $me = $self . "@" . $grid[$self][AUTHORITY]; |
---|
112 | |
---|
113 | $gridstack = array(); |
---|
114 | $gridstack[] = $me; |
---|
115 | |
---|
116 | if ($gridwalk=="fwd") { |
---|
117 | # push our info on gridstack, format is "name@url>name2@url". |
---|
118 | if (end($gridstack) != $me) { |
---|
119 | $gridstack[] = $me; |
---|
120 | } |
---|
121 | } else if ($gridwalk=="back") { |
---|
122 | # pop a single grid off stack. |
---|
123 | if (end($gridstack) != $me) { |
---|
124 | array_pop($gridstack); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | $gridstack_str = join(">", $gridstack); |
---|
129 | $gridstack_url = rawurlencode($gridstack_str); |
---|
130 | |
---|
131 | if ($initgrid or $gridwalk) { |
---|
132 | # Use cookie so we dont have to pass gridstack around within this site. |
---|
133 | # Cookie values are automatically urlencoded. Expires in a day. |
---|
134 | setcookie("gs", $gridstack_str, time() + 86400); |
---|
135 | } |
---|
136 | |
---|
137 | # Invariant: back pointer is second-to-last element of gridstack. Grid stack never |
---|
138 | # has duplicate entries. |
---|
139 | list($parentgrid, $parentlink) = explode("@", $gridstack[count($gridstack)-2]); |
---|
140 | |
---|
141 | # Setup a redirect to a remote server if you choose a grid from pulldown menu. Tell |
---|
142 | # destination server that we're walking foward in the grid tree. |
---|
143 | if (strstr($clustername, "http://")) { |
---|
144 | $tpl->assign("refresh", "0"); |
---|
145 | $tpl->assign("redirect", ";URL=$clustername?gw=fwd&gs=$gridstack_url"); |
---|
146 | echo "<h2>Redirecting, please wait...</h2>"; |
---|
147 | $tpl->printToScreen(); |
---|
148 | exit; |
---|
149 | } |
---|
150 | |
---|
151 | if( $view != "search" ) |
---|
152 | $tpl->assign( "refresh", $default_refresh ); |
---|
153 | |
---|
154 | $tpl->assign( "date", date("r") ); |
---|
155 | $tpl->assign( "page_title", $title ); |
---|
156 | |
---|
157 | # The page to go to when "Get Fresh Data" is pressed. |
---|
158 | $tpl->assign("page","./"); |
---|
159 | |
---|
160 | # Templated Logo image |
---|
161 | $tpl->assign("images","./templates/$template_name/images"); |
---|
162 | |
---|
163 | # |
---|
164 | # Used when making graphs via graph.php. Included in most URLs |
---|
165 | # |
---|
166 | $sort_url=rawurlencode($sort); |
---|
167 | $get_metric_string = "m=$metric&r=$range&s=$sort_url&hc=$hostcols"; |
---|
168 | |
---|
169 | if ($jobrange and $jobstart) |
---|
170 | $get_metric_string .= "&jr=$jobrange&js=$jobstart"; |
---|
171 | |
---|
172 | # Set the Alternate view link. |
---|
173 | $cluster_url=rawurlencode($clustername); |
---|
174 | $node_url=rawurlencode($hostname); |
---|
175 | |
---|
176 | # Make some information available to templates. |
---|
177 | $tpl->assign("cluster_url", $cluster_url); |
---|
178 | # Build the node_menu |
---|
179 | $node_menu = ""; |
---|
180 | |
---|
181 | if ($parentgrid) { |
---|
182 | $node_menu .= "<B>$parentgrid $meta_designator</B> "; |
---|
183 | $node_menu .= "<B>></B>\n"; |
---|
184 | } |
---|
185 | |
---|
186 | # Show grid. |
---|
187 | $mygrid = ($self == "unspecified") ? "" : $self; |
---|
188 | $node_menu .= "<B><A HREF=\"../..\">$mygrid $meta_designator</A></B> "; |
---|
189 | $node_menu .= "<B>></B>\n"; |
---|
190 | |
---|
191 | if ($physical) |
---|
192 | $node_menu .= hiddenvar("p", $physical); |
---|
193 | |
---|
194 | if ( $clustername ) { |
---|
195 | $url = rawurlencode($clustername); |
---|
196 | $node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> "; |
---|
197 | $node_menu .= "<B>></B>\n"; |
---|
198 | $node_menu .= hiddenvar("c", $clustername); |
---|
199 | } |
---|
200 | |
---|
201 | if (!count($metrics)) { |
---|
202 | echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n"; echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n"; |
---|
203 | exit; |
---|
204 | } |
---|
205 | $firsthost = key($metrics); |
---|
206 | foreach ($metrics[$firsthost] as $m => $foo) |
---|
207 | $context_metrics[] = $m; |
---|
208 | |
---|
209 | foreach ($reports as $r => $foo) |
---|
210 | $context_metrics[] = $r; |
---|
211 | |
---|
212 | $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> "; |
---|
213 | |
---|
214 | if( count( $filter ) > 0 && $view != "search" ) { |
---|
215 | |
---|
216 | $my_ct = 1; |
---|
217 | $filter_nr = count( $filter ); |
---|
218 | |
---|
219 | foreach( $filter as $filtername=>$filterval ) { |
---|
220 | |
---|
221 | $node_menu .= "<B>></B>\n"; |
---|
222 | |
---|
223 | $href = "<A HREF=\"./?c=".rawurlencode($clustername); |
---|
224 | $temp_ct = 0; |
---|
225 | $n_filter = $filter; |
---|
226 | $my_filterorder = ""; |
---|
227 | $my_filters = array_keys( $filter ); |
---|
228 | |
---|
229 | foreach( $n_filter as $n_filtername=>$n_filterval ) { |
---|
230 | |
---|
231 | if( $temp_ct < $my_ct ) { |
---|
232 | $href .= "&". $n_filtername . "=" . $n_filterval; |
---|
233 | |
---|
234 | if( $my_filterorder == "" ) |
---|
235 | $my_filterorder = $my_filters[$temp_ct]; |
---|
236 | else |
---|
237 | $my_filterorder .= "," . $my_filters[$temp_ct]; |
---|
238 | } |
---|
239 | |
---|
240 | $temp_ct++; |
---|
241 | } |
---|
242 | $href .= "&filterorder=$my_filterorder\">"; |
---|
243 | |
---|
244 | if( $my_ct < $filter_nr ) |
---|
245 | $node_menu .= "<B>$href$filtername: $filterval</A></B> "; |
---|
246 | else |
---|
247 | $node_menu .= "<B>$filtername: $filterval</B> "; |
---|
248 | |
---|
249 | $my_ct++; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | $m = $metricname; |
---|
254 | |
---|
255 | |
---|
256 | $tpl->gotoBlock( "_ROOT" ); |
---|
257 | $tpl->assignGlobal("view", $view); |
---|
258 | |
---|
259 | if( array_key_exists( "id", $filter ) or isset($hostname) ) { |
---|
260 | |
---|
261 | //print_r( $context_metrics ); |
---|
262 | |
---|
263 | if( !isset( $hostname ) ) { |
---|
264 | |
---|
265 | if (is_array($context_metrics) ) { |
---|
266 | $metric_menu = "<B>Metric</B> " |
---|
267 | ."<SELECT NAME=\"m\" OnChange=\"".$form_name.".submit();\">\n"; |
---|
268 | |
---|
269 | sort($context_metrics); |
---|
270 | foreach( $context_metrics as $k ) { |
---|
271 | $url = rawurlencode($k); |
---|
272 | $metric_menu .= "<OPTION VALUE=\"$url\" "; |
---|
273 | if ($k == $metricname ) |
---|
274 | $metric_menu .= "SELECTED"; |
---|
275 | $metric_menu .= ">$k\n"; |
---|
276 | } |
---|
277 | $metric_menu .= "</SELECT>\n"; |
---|
278 | |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | $tpl->assign("metric_menu", $metric_menu ); |
---|
283 | |
---|
284 | if( $view == "search" or $view == "host" ) { |
---|
285 | $tpl->newBlock("timeperiod"); |
---|
286 | if( is_numeric( $period_start ) ) { |
---|
287 | $period_start = epochToDatetime( $period_start ); |
---|
288 | } |
---|
289 | if( is_numeric( $period_stop ) ) { |
---|
290 | $period_stop = epochToDatetime( $period_stop ); |
---|
291 | } |
---|
292 | $tpl->assign("period_start", $period_start ); |
---|
293 | $tpl->assign("period_stop", $period_stop ); |
---|
294 | $tpl->assign("hostname", $hostname ); |
---|
295 | |
---|
296 | if( $view == "host" ) { |
---|
297 | $tpl->newBlock("hostview"); |
---|
298 | $tpl->assign("job_start", $job_start ); |
---|
299 | $tpl->assign("job_stop", $job_stop ); |
---|
300 | } |
---|
301 | } |
---|
302 | |
---|
303 | } |
---|
304 | |
---|
305 | //$ex_fn = $tpl->getVarValue( "_ROOT", "form_name" ); |
---|
306 | |
---|
307 | if( $view == "search" or $view == "host" ) { |
---|
308 | |
---|
309 | $node_menu .= "<B>></B>\n"; |
---|
310 | $node_menu .= "<B>Jobarchive</B> "; |
---|
311 | $form_name = "archive_search_form"; |
---|
312 | $tpl->assignGlobal("form_name", $form_name ); |
---|
313 | |
---|
314 | } else { |
---|
315 | $form_name = "toga_form"; |
---|
316 | $tpl->assignGlobal("form_name", $form_name ); |
---|
317 | } |
---|
318 | |
---|
319 | if( $JOB_ARCHIVE && $page_call == 'index' ) { |
---|
320 | $tpl->newBlock( "search" ); |
---|
321 | $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) ); |
---|
322 | $tpl->assignGlobal( "cluster", $clustername ); |
---|
323 | } |
---|
324 | $tpl->gotoBlock( "_ROOT" ); |
---|
325 | $tpl->assignGlobal( "cluster", $clustername ); |
---|
326 | $tpl->assign("node_menu", $node_menu); |
---|
327 | |
---|
328 | # Make sure that no data is cached.. |
---|
329 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Date in the past |
---|
330 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified |
---|
331 | header ("Cache-Control: no-cache, must-revalidate"); # HTTP/1.1 |
---|
332 | header ("Pragma: no-cache"); # HTTP/1.0 |
---|
333 | } |
---|
334 | |
---|
335 | function makeFooter() { |
---|
336 | global $tpl, $version, $parsetime, $monarchversion; |
---|
337 | |
---|
338 | $tpl->gotoBlock( "_ROOT" ); |
---|
339 | $tpl->assign("webfrontend-version",$version["webfrontend"]); |
---|
340 | $tpl->assign("monarch-version", $monarchversion); |
---|
341 | |
---|
342 | if ($version["gmetad"]) { |
---|
343 | $tpl->assign("webbackend-component", "gmetad"); |
---|
344 | $tpl->assign("webbackend-version",$version["gmetad"]); |
---|
345 | } else if ($version["gmond"]) { |
---|
346 | $tpl->assign("webbackend-component", "gmond"); |
---|
347 | $tpl->assign("webbackend-version", $version["gmond"]); |
---|
348 | } |
---|
349 | |
---|
350 | $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s"); |
---|
351 | } |
---|
352 | |
---|
353 | function includeSearchpage() { |
---|
354 | global $tpl; |
---|
355 | |
---|
356 | $tpl->assignInclude( "main", "templates/search.tpl" ); |
---|
357 | |
---|
358 | } |
---|
359 | |
---|
360 | function includeOverview() { |
---|
361 | global $tpl; |
---|
362 | |
---|
363 | $tpl->assignInclude( "main", "templates/overview.tpl" ); |
---|
364 | } |
---|
365 | |
---|
366 | function includeHostPage() { |
---|
367 | |
---|
368 | global $tpl; |
---|
369 | |
---|
370 | $tpl->assignInclude( "main", "templates/host_view.tpl" ); |
---|
371 | } |
---|
372 | |
---|
373 | $tpl = new TemplatePower( "templates/index.tpl" ); |
---|
374 | |
---|
375 | $tpl->assignInclude( "header", "templates/header.tpl" ); |
---|
376 | |
---|
377 | if( isset( $h ) and $h != '' ) { |
---|
378 | $hostname = $h; |
---|
379 | //$view = "host"; |
---|
380 | } |
---|
381 | |
---|
382 | switch( $view ) { |
---|
383 | |
---|
384 | case "overview": |
---|
385 | |
---|
386 | includeOverview(); |
---|
387 | break; |
---|
388 | |
---|
389 | case "search": |
---|
390 | |
---|
391 | includeSearchPage(); |
---|
392 | break; |
---|
393 | |
---|
394 | //case "host": |
---|
395 | |
---|
396 | // includeHostPage(); |
---|
397 | // break; |
---|
398 | |
---|
399 | default: |
---|
400 | |
---|
401 | includeOverview(); |
---|
402 | break; |
---|
403 | } |
---|
404 | |
---|
405 | $tpl->assignInclude( "footer", "templates/footer.tpl" ); |
---|
406 | $tpl->prepare(); |
---|
407 | |
---|
408 | $title = "Torque Report"; |
---|
409 | makeHeader( 'index' ); |
---|
410 | $tpl->assign("cluster_url", rawurlencode($clustername) ); |
---|
411 | $tpl->assign("cluster", $clustername ); |
---|
412 | |
---|
413 | switch( $view ) { |
---|
414 | |
---|
415 | case "overview": |
---|
416 | |
---|
417 | include "./overview.php"; |
---|
418 | makeOverview(); |
---|
419 | break; |
---|
420 | |
---|
421 | case "search": |
---|
422 | |
---|
423 | include "./search.php"; |
---|
424 | makeSearchPage(); |
---|
425 | break; |
---|
426 | |
---|
427 | //case "host": |
---|
428 | |
---|
429 | // include "./host_view.php"; |
---|
430 | // makeHostView(); |
---|
431 | // break; |
---|
432 | |
---|
433 | default: |
---|
434 | |
---|
435 | makeOverview(); |
---|
436 | break; |
---|
437 | } |
---|
438 | |
---|
439 | makeFooter(); |
---|
440 | $tpl->printToScreen(); |
---|
441 | ?> |
---|