source: branches/0.4/web/addons/job_monarch/index.php @ 753

Last change on this file since 753 was 753, checked in by ramonb, 11 years ago

index.php, overview.php:

header.php:

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