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

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

web/addons/job_monarch/search.php:

  • set host view for host detail

web/addons/job_monarch/index.php:

  • enable host view again

web/addons/job_monarch/host_view.php:

  • get available metrics from archive

web/addons/job_monarch/templates/host_view.tpl:

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