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

Last change on this file since 231 was 231, checked in by bastiaans, 18 years ago

*.php:

  • added svn keywords propset
  • Property svn:keywords set to Id
File size: 10.7 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 231 2006-03-10 16:36:38Z bastiaans $
23 */
24
25if ( !empty( $_GET ) ) {
26        extract( $_GET );
27}
28
29$my_dir = getcwd();
30
31include_once "./libtoga.php";
32
33global $GANGLIA_PATH;
34chdir( $GANGLIA_PATH );
35
36include_once "./class.TemplatePower.inc.php";
37chdir( $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
45if( !isset($view) ) $view = "overview";
46if( !isset($sortorder) ) $sortorder = "asc";
47if( !isset($sortby) ) $sortby = "id";
48
49if( 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
59foreach( $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
83function epochToDatetime( $epoch ) {
84
85        return strftime( "%d-%m-%Y %H:%M:%S", $epoch );
86}
87
88function makeHeader() {
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>&gt;</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>&gt;</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>&gt;</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>&gt;</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>&nbsp;&nbsp;"
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        if( $view == "search" or $view == "host" ) {
306
307                $node_menu .= "<B>&gt;</B>\n";
308                $node_menu .= "<B>Jobarchive</B> ";
309                $form_name = "archive_search_form";
310                $tpl->assignGlobal("form_name", $form_name );
311
312        } else {
313                $form_name = "toga_form";
314                $tpl->assignGlobal("form_name", $form_name );
315        }
316
317        if( $JOB_ARCHIVE ) {
318                $tpl->newBlock( "search" );
319                $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
320                $tpl->assignGlobal( "cluster", $clustername );
321        }
322        $tpl->gotoBlock( "_ROOT" );
323        $tpl->assignGlobal( "cluster", $clustername );
324        $tpl->assign("node_menu", $node_menu);
325
326        # Make sure that no data is cached..
327        header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
328        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
329        header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
330        header ("Pragma: no-cache");                          # HTTP/1.0
331}
332
333function makeFooter() {
334        global $tpl, $version, $parsetime, $monarchversion;
335
336        $tpl->gotoBlock( "_ROOT" );
337        $tpl->assign("webfrontend-version",$version["webfrontend"]);
338        $tpl->assign("monarch-version", $monarchversion);
339
340        if ($version["gmetad"]) {
341                $tpl->assign("webbackend-component", "gmetad");
342                $tpl->assign("webbackend-version",$version["gmetad"]);
343        } else if ($version["gmond"]) {
344                $tpl->assign("webbackend-component", "gmond");
345                $tpl->assign("webbackend-version", $version["gmond"]);
346        }
347
348        $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
349}
350
351function includeSearchpage() {
352        global $tpl;
353
354        $tpl->assignInclude( "main", "templates/search.tpl" );
355
356}
357
358function includeOverview() {
359        global $tpl;
360
361        $tpl->assignInclude( "main", "templates/overview.tpl" );
362}
363
364function includeHostPage() {
365
366        global $tpl;
367
368        $tpl->assignInclude( "main", "templates/host_view.tpl" );
369}
370
371$tpl = new TemplatePower( "templates/index.tpl" );
372
373$tpl->assignInclude( "header", "templates/header.tpl" );
374
375if( isset( $h ) and $h != '' ) {
376        $hostname = $h;
377        $view = "host";
378}
379
380switch( $view ) {
381
382        case "overview":
383
384                includeOverview();
385                break;
386
387        case "search":
388
389                includeSearchPage();
390                break;
391
392        case "host":
393
394                includeHostPage();
395                break;
396
397        default:
398
399                includeOverview();
400                break;
401}
402
403$tpl->assignInclude( "footer", "templates/footer.tpl" );
404$tpl->prepare();
405
406$title = "Torque Report";
407makeHeader();
408$tpl->assign("cluster_url", rawurlencode($clustername) );
409$tpl->assign("cluster", $clustername );
410
411switch( $view ) {
412
413        case "overview":
414
415                include "./overview.php";
416                makeOverview();
417                break;
418
419        case "search":
420
421                include "./search.php";
422                makeSearchPage();
423                break;
424
425        case "host":
426
427                include "./host_view.php";
428                makeHostView();
429                break;
430
431        default:
432
433                makeOverview();
434                break;
435}
436
437makeFooter();
438$tpl->printToScreen();
439?>
Note: See TracBrowser for help on using the repository browser.