source: trunk/web2/addons/job_monarch/index.php @ 576

Last change on this file since 576 was 555, checked in by ramonb, 16 years ago

job_monarch/js/jobgrid.js:

job_monarch/templates/header.tpl:

  • removed some positioning stuff

job_monarch/index.php,
job_monarch/image.php:

  • more memory limits
File size: 12.2 KB
Line 
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 527 2008-06-27 13:37:31Z ramonb $
23 */
24
25ini_set("memory_limit","200M");
26set_time_limit(0);
27
28
29$my_dir = getcwd();
30
31global $r, $range;
32
33include_once "./libtoga.php";
34
35if ( !empty( $_GET ) ) {
36        extract( $_GET );
37}
38
39//printf( "r2%s\n", $range );
40
41global $GANGLIA_PATH;
42chdir( $GANGLIA_PATH );
43
44include_once "./class.TemplatePower.inc.php";
45chdir( $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
53if( !isset($view) ) $view = "overview";
54if( !isset($sortorder) ) $sortorder = "asc";
55if( !isset($sortby) ) $sortby = "id";
56
57if( 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
67if( 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
94function epochToDatetime( $epoch ) {
95
96        return strftime( "%d-%m-%Y %H:%M:%S", $epoch );
97}
98
99function 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, $metricname;
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>&gt;</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>&gt;</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>&gt;</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 ) && ( $view != 'host' ) ) {
242
243                $node_menu .= "<B>&gt;</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>&gt;</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( $page_call != "host_view" )
302                {
303
304                        if (is_array($context_metrics) ) {
305                                $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
306                                        ."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n";
307
308                                sort($context_metrics);
309                                foreach( $context_metrics as $k ) {
310                                        $url = rawurlencode($k);
311                                        $metric_menu .= "<OPTION VALUE=\"$url\" ";
312                                        if ($k == $metricname )
313                                                $metric_menu .= "SELECTED";
314                                        $metric_menu .= ">$k\n";
315                                }
316                                $metric_menu .= "</SELECT>\n";
317                        }
318
319                }
320
321                $tpl->assign("metric_menu", $metric_menu );
322
323                if( $view == "search" or $view == "host" ) {
324                        $tpl->newBlock("timeperiod");
325                        if( is_numeric( $period_start ) ) {
326                                $period_start = epochToDatetime( $period_start );
327                        }
328                        if( is_numeric( $period_stop ) ) {
329                                $period_stop = epochToDatetime( $period_stop );
330                        }
331                        $tpl->assign("period_start", $period_start );
332                        $tpl->assign("period_stop", $period_stop );
333                        $tpl->assign("hostname", $hostname );
334
335                        if( $view == "host" ) {
336                                $tpl->newBlock("hostview");
337                                $tpl->assign("job_start", $job_start );
338                                $tpl->assign("job_stop", $job_stop );
339                        }
340                }
341
342        }
343
344        //$ex_fn = $tpl->getVarValue( "_ROOT", "form_name" );
345
346        if( $view != "search" )
347        {
348                $context_ranges[]="hour";
349                $context_ranges[]="day";
350                $context_ranges[]="week";
351                $context_ranges[]="month";
352                $context_ranges[]="year";
353                $context_ranges[]="job";
354
355                $range_menu = "<B>Last</B>&nbsp;&nbsp;" ."<SELECT NAME=\"r\" OnChange=\"toga_form.submit();\">\n";
356                foreach ($context_ranges as $v) {
357                        $url=rawurlencode($v);
358                        $range_menu .= "<OPTION VALUE=\"$url\" ";
359                        if ($v == $range)
360                                $range_menu .= "SELECTED";
361                        $range_menu .= ">$v\n";
362                }
363                $range_menu .= "</SELECT>\n";
364
365                $tpl->assign("range_menu", $range_menu);
366
367        }
368
369        if( $view == "search" or $view == "host" ) {
370
371                $node_menu .= "<B>&gt;</B>\n";
372                $node_menu .= "<B>Jobarchive</B> ";
373                $form_name = "archive_search_form";
374                $tpl->assignGlobal("form_name", $form_name );
375
376        } else {
377                $form_name = "toga_form";
378                $tpl->assignGlobal("form_name", $form_name );
379        }
380
381        if( $JOB_ARCHIVE && $page_call == 'overview' ) {
382                $tpl->newBlock( "search" );
383                $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
384                $tpl->assignGlobal( "cluster", $clustername );
385        }
386        $tpl->gotoBlock( "_ROOT" );
387        $tpl->assignGlobal( "cluster", $clustername );
388        $tpl->assign("node_menu", $node_menu);
389
390        # Make sure that no data is cached..
391        header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
392        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
393        header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
394        header ("Pragma: no-cache");                          # HTTP/1.0
395}
396
397function makeFooter() {
398        global $tpl, $version, $parsetime, $monarchversion;
399
400        $tpl->gotoBlock( "_ROOT" );
401        $tpl->assign("webfrontend-version",$version["webfrontend"]);
402        $tpl->assign("monarch-version", $monarchversion);
403
404        if ($version["gmetad"]) {
405                $tpl->assign("webbackend-component", "gmetad");
406                $tpl->assign("webbackend-version",$version["gmetad"]);
407        } else if ($version["gmond"]) {
408                $tpl->assign("webbackend-component", "gmond");
409                $tpl->assign("webbackend-version", $version["gmond"]);
410        }
411
412        $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
413}
414
415function includeSearchpage() {
416        global $tpl;
417
418        $tpl->assignInclude( "main", "templates/search.tpl" );
419
420}
421
422function includeOverview() {
423        global $tpl;
424
425        $tpl->assignInclude( "main", "templates/overview.tpl" );
426}
427
428function includeHostPage() {
429
430        global $tpl;
431
432        $tpl->assignInclude( "main", "templates/host_view.tpl" );
433}
434
435$tpl = new TemplatePower( "templates/index.tpl" );
436
437$tpl->assignInclude( "header", "templates/header.tpl" );
438
439if( isset( $h ) and $h != '' ) {
440        $hostname = $h;
441        //$view = "host";
442}
443
444switch( $view ) {
445
446        case "overview":
447
448                includeOverview();
449                break;
450
451        case "search":
452
453                includeSearchPage();
454                break;
455
456        case "host":
457
458                includeHostPage();
459                break;
460
461        default:
462
463                includeOverview();
464                break;
465}
466
467$tpl->assignInclude( "footer", "templates/footer.tpl" );
468$tpl->prepare();
469
470$longtitle = "Batch Report :: Powered by Job Monarch!";
471$title = "Batch Report";
472//makeHeader( 'index' );
473$tpl->assign("cluster_url", rawurlencode($clustername) );
474$tpl->assign("cluster", $clustername );
475
476switch( $view ) {
477
478        case "overview":
479
480                include "./overview.php";
481                makeOverview();
482                break;
483
484        case "search":
485
486                include "./search.php";
487                makeSearchPage();
488                break;
489
490        case "host":
491
492                include "./host_view.php";
493                makeHostView();
494                break;
495
496        default:
497
498                makeOverview();
499                break;
500}
501
502makeFooter();
503$tpl->printToScreen();
504?>
Note: See TracBrowser for help on using the repository browser.