source: trunk/web/addons/job_monarch/index.php @ 411

Last change on this file since 411 was 411, checked in by bastiaans, 17 years ago

web/addons/job_monarch/host_view.php:

  • make header properly according to new setup

web/addons/job_monarch/search.php,
web/addons/job_monarch/index.php:

  • use correct metricname parsing
  • Property svn:keywords set to Id
File size: 12.1 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 411 2007-07-06 13:50:48Z bastiaans $
23 */
24
25ini_set("memory_limit","80M");
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 ) ) {
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 (is_array($context_metrics) ) {
302                        $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
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        if( $view != "search" )
343        {
344                $context_ranges[]="hour";
345                $context_ranges[]="day";
346                $context_ranges[]="week";
347                $context_ranges[]="month";
348                $context_ranges[]="year";
349                $context_ranges[]="job";
350
351                $range_menu = "<B>Last</B>&nbsp;&nbsp;" ."<SELECT NAME=\"r\" OnChange=\"toga_form.submit();\">\n";
352                foreach ($context_ranges as $v) {
353                        $url=rawurlencode($v);
354                        $range_menu .= "<OPTION VALUE=\"$url\" ";
355                        if ($v == $range)
356                                $range_menu .= "SELECTED";
357                        $range_menu .= ">$v\n";
358                }
359                $range_menu .= "</SELECT>\n";
360
361                $tpl->assign("range_menu", $range_menu);
362
363        }
364
365        if( $view == "search" or $view == "host" ) {
366
367                $node_menu .= "<B>&gt;</B>\n";
368                $node_menu .= "<B>Jobarchive</B> ";
369                $form_name = "archive_search_form";
370                $tpl->assignGlobal("form_name", $form_name );
371
372        } else {
373                $form_name = "toga_form";
374                $tpl->assignGlobal("form_name", $form_name );
375        }
376
377        if( $JOB_ARCHIVE && $page_call == 'overview' ) {
378                $tpl->newBlock( "search" );
379                $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
380                $tpl->assignGlobal( "cluster", $clustername );
381        }
382        $tpl->gotoBlock( "_ROOT" );
383        $tpl->assignGlobal( "cluster", $clustername );
384        $tpl->assign("node_menu", $node_menu);
385
386        # Make sure that no data is cached..
387        header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
388        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
389        header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
390        header ("Pragma: no-cache");                          # HTTP/1.0
391}
392
393function makeFooter() {
394        global $tpl, $version, $parsetime, $monarchversion;
395
396        $tpl->gotoBlock( "_ROOT" );
397        $tpl->assign("webfrontend-version",$version["webfrontend"]);
398        $tpl->assign("monarch-version", $monarchversion);
399
400        if ($version["gmetad"]) {
401                $tpl->assign("webbackend-component", "gmetad");
402                $tpl->assign("webbackend-version",$version["gmetad"]);
403        } else if ($version["gmond"]) {
404                $tpl->assign("webbackend-component", "gmond");
405                $tpl->assign("webbackend-version", $version["gmond"]);
406        }
407
408        $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
409}
410
411function includeSearchpage() {
412        global $tpl;
413
414        $tpl->assignInclude( "main", "templates/search.tpl" );
415
416}
417
418function includeOverview() {
419        global $tpl;
420
421        $tpl->assignInclude( "main", "templates/overview.tpl" );
422}
423
424function includeHostPage() {
425
426        global $tpl;
427
428        $tpl->assignInclude( "main", "templates/host_view.tpl" );
429}
430
431$tpl = new TemplatePower( "templates/index.tpl" );
432
433$tpl->assignInclude( "header", "templates/header.tpl" );
434
435if( isset( $h ) and $h != '' ) {
436        $hostname = $h;
437        //$view = "host";
438}
439
440switch( $view ) {
441
442        case "overview":
443
444                includeOverview();
445                break;
446
447        case "search":
448
449                includeSearchPage();
450                break;
451
452        case "host":
453
454                includeHostPage();
455                break;
456
457        default:
458
459                includeOverview();
460                break;
461}
462
463$tpl->assignInclude( "footer", "templates/footer.tpl" );
464$tpl->prepare();
465
466$longtitle = "Batch Report :: Powered by Job Monarch!";
467$title = "Batch Report";
468//makeHeader( 'index' );
469$tpl->assign("cluster_url", rawurlencode($clustername) );
470$tpl->assign("cluster", $clustername );
471
472switch( $view ) {
473
474        case "overview":
475
476                include "./overview.php";
477                makeOverview();
478                break;
479
480        case "search":
481
482                include "./search.php";
483                makeSearchPage();
484                break;
485
486        case "host":
487
488                include "./host_view.php";
489                makeHostView();
490                break;
491
492        default:
493
494                makeOverview();
495                break;
496}
497
498makeFooter();
499$tpl->printToScreen();
500?>
Note: See TracBrowser for help on using the repository browser.