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