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

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

graph.php,
overview.php:

  • display range in title
  • removed RRDs column count: now done via css

templates/overview.tpl:

  • removed RRDs column count: now done via css

index.php:

  • dont show range selector if no show hosts
  • Property svn:keywords set to Id
File size: 13.8 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 758 2013-03-27 17:47:17Z 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;
[758]122    global $conf, $show_hosts;
[753]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    $tpl_data = new Dwoo_Data();
[117]185
[753]186    $tpl_data->assign( "date", date("r") );
187    $tpl_data->assign( "longpage_title", $longtitle );
188    $tpl_data->assign( "page_title", $title );
[117]189
[715]190    # The page to go to when "Get Fresh Data" is pressed.
[753]191    $tpl_data->assign("page","./");
[117]192
[715]193    # Templated Logo image
[753]194    $tpl_data->assign("images","./templates/$template_name/images");
[117]195
[715]196    #
197    # Used when making graphs via graph.php. Included in most URLs
198    #
199    $sort_url=rawurlencode($sort);
200    $get_metric_string = "m=$metric&r=$range&s=$sort_url&hc=$hostcols";
[117]201
[715]202    if ($jobrange and $jobstart)
203        $get_metric_string .= "&jr=$jobrange&js=$jobstart";
[117]204
[715]205    # Set the Alternate view link.
206    $cluster_url=rawurlencode($clustername);
207    $node_url=rawurlencode($hostname);
[117]208
[715]209    # Make some information available to templates.
[753]210    $tpl_data->assign("cluster_url", $cluster_url);
[715]211    # Build the node_menu
212    $node_menu = "";
[117]213
[715]214    if ($parentgrid) 
215    {
216        $node_menu .= "<B>$parentgrid $meta_designator</B> ";
217        $node_menu .= "<B>&gt;</B>\n";
218    }
[117]219
[715]220    # Show grid.
221    $mygrid =  ($self == "unspecified") ? "" : $self;
222    $node_menu .= "<B><A HREF=\"../..\">$mygrid $meta_designator</A></B> ";
223    $node_menu .= "<B>&gt;</B>\n";
[117]224
[715]225    if ($physical)
226    {
227        $node_menu .= hiddenvar("p", $physical);
228    }
[117]229
[715]230    if ( $clustername ) 
231    {
232        $url = rawurlencode($clustername);
233        $node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> ";
234        $node_menu .= "<B>&gt;</B>\n";
235        $node_menu .= hiddenvar("c", $clustername);
236    }
[117]237
[715]238    if (!count($metrics)) 
239    {
240        echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n";
241        echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n";
242        exit;
243    }
244    reset($metrics);
245    $firsthost = key($metrics);
[145]246
[715]247    $mmfh    = array();
[126]248
[715]249    $mmfh    = $metrics[$firsthost];
[406]250
[715]251    $context_metrics    = array();
[406]252
[715]253    foreach( $mmfh as $mm => $bla )
254    {
255        $context_metrics[] = $mm;
256    }
[406]257
[715]258    foreach ($reports as $mr => $mfoo)
259        $context_metrics[] = $mr;
[406]260
[715]261    $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
[122]262
[715]263    if( isset( $hostname ) && ( $view != 'host' ) ) 
264    {
[267]265
[715]266        $node_menu .= "<B>&gt;</B>\n";
267        $href = "<A HREF=\"./?c=".rawurlencode($clustername)."&h=".$hostname."\">";
268        $node_menu .= "<B>$href";
269        $node_menu .= "host: $hostname</A></B> ";
270    }
[267]271
[715]272    if( count( $filter ) > 0 && $view != "search" ) 
273    {
[119]274
[715]275        $my_ct = 1;
276        $filter_nr = count( $filter );
[119]277
[715]278        foreach( $filter as $filtername=>$filterval ) 
279        {
[138]280
[715]281            $node_menu .= "<B>&gt;</B>\n";
[153]282
[715]283            $href = "<A HREF=\"./?c=".rawurlencode($clustername);
284            $temp_ct = 0;
285            $n_filter = $filter;
286            $my_filterorder = "";
287            $my_filters = array_keys( $filter );
[153]288
[715]289            foreach( $n_filter as $n_filtername=>$n_filterval ) 
290            {
[153]291
[715]292                if( $temp_ct < $my_ct ) 
293                {
294                    $href .= "&". $n_filtername . "=" . $n_filterval;
[153]295
[715]296                    if( $my_filterorder == "" )
297                        $my_filterorder = $my_filters[$temp_ct];
298                    else
299                        $my_filterorder .= "," . $my_filters[$temp_ct];
300                }
[158]301
[715]302                $temp_ct++;
303            }
304            $href .= "&filterorder=$my_filterorder\">";
[138]305
[715]306            if( $my_ct < $filter_nr )
307                $node_menu .= "<B>$href$filtername: $filterval</A></B> ";
308            else
309                $node_menu .= "<B>$filtername: $filterval</B> ";
[153]310
[715]311            $my_ct++;
312        }
313    }
[119]314
[753]315    $tpl_data->assign("view", $view);
[143]316
[715]317    if( array_key_exists( "id", $filter ) or isset($hostname) )
318    {
[117]319
[738]320        #$range = "job";
[409]321
[715]322        if( $page_call != "host_view" )
323        {
[126]324
[715]325            if (is_array($context_metrics) )
326            {
327                $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
328                    ."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n";
[413]329
[715]330                sort($context_metrics);
331                foreach( $context_metrics as $k ) 
332                {
333                    $url = rawurlencode($k);
334                    $metric_menu .= "<OPTION VALUE=\"$url\" ";
335                    if ($k == $metricname )
336                        $metric_menu .= "SELECTED";
337                    $metric_menu .= ">$k\n";
338                }
339                $metric_menu .= "</SELECT>\n";
340            }
[189]341
[715]342        }
[149]343
[753]344        $tpl_data->assign("metric_menu", $metric_menu );
[189]345
[734]346        if( $view == "search" or $view == "host" or $view == "overview-host" )
[715]347        {
[753]348            $tpl_data->assign("timeperiod", "yes" );
[715]349            if( is_numeric( $period_start ) )
350            {
351                $period_start = epochToDatetime( $period_start );
352            }
353            if( is_numeric( $period_stop ) )
354            {
355                $period_stop = epochToDatetime( $period_stop );
356            }
[753]357            $tpl_data->assign("period_start", $period_start );
358            $tpl_data->assign("period_stop", $period_stop );
359            $tpl_data->assign("hostname", $hostname );
[189]360
[734]361            if( $view == "host" or $view == "overview-host" )
[715]362            {
[753]363                $tpl_data->assign("hostview", "yes");
364                $tpl_data->assign("job_start", $job_start );
365                $tpl_data->assign("job_stop", $job_stop );
[715]366            }
367        }
[189]368
[715]369    }
[126]370
[758]371    if( array_key_exists( "id", $filter ) or isset($hostname) )
[715]372    {
[409]373
[758]374        #$range = "job";
375
376        if( ( $page_call != "host_view" ) && ( $view != "search" ) )
[715]377        {
[758]378            $context_ranges[]="hour";
379            $context_ranges[]="day";
380            $context_ranges[]="week";
381            $context_ranges[]="month";
382            $context_ranges[]="year";
383            $context_ranges[]="job";
384
385            $range_menu = "<B>Last</B>&nbsp;&nbsp;" ."<SELECT NAME=\"r\" OnChange=\"toga_form.submit();\">\n";
386            foreach ($context_ranges as $v) 
387            {
388                $url=rawurlencode($v);
389                $range_menu .= "<OPTION VALUE=\"$url\" ";
390                if ($v == $range)
391                {
392                    $range_menu .= "SELECTED";
393                }
394                $range_menu .= ">$v\n";
395            }
396            $range_menu .= "</SELECT>\n";
397
398            $tpl_data->assign("range_menu", $range_menu);
[715]399        }
[410]400
[715]401    }
[409]402
[736]403    if( $view == "search" or $view == "host" )
[715]404    {
[189]405
[715]406        $node_menu .= "<B>&gt;</B>\n";
407        $node_menu .= "<B>Jobarchive</B> ";
408        $form_name = "archive_search_form";
[753]409        $tpl_data->assign("form_name", $form_name );
[189]410
[715]411    }
412    else
413    {
414        $form_name = "toga_form";
[753]415        $tpl_data->assign("form_name", $form_name );
[715]416    }
[189]417
[715]418    if( $JOB_ARCHIVE && $page_call == 'overview' )
419    {
[753]420        $tpl_data->assign( "search", "yes" );
421        $tpl_data->assign( "cluster_url", rawurlencode($clustername) );
422        $tpl_data->assign( "cluster", $clustername );
[715]423    }
[753]424    $tpl_data->assign( "cluster", $clustername );
425    $tpl_data->assign("node_menu", $node_menu);
[140]426
[715]427    # Make sure that no data is cached..
[754]428    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
429    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
430    header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
431    header ("Pragma: no-cache");                          # HTTP/1.0
[753]432
433    $dwoo->output($tpl, $tpl_data);
[117]434}
435
[715]436function makeFooter()
437{
[753]438    global $dwoo, $version, $parsetime, $monarchversion;
[117]439
[753]440    $tpl = new Dwoo_Template_File("templates/footer.tpl");
441    $tpl_data = new Dwoo_Data();
[117]442
[753]443    $tpl_data->assign("webfrontendversion",$version["webfrontend"]);
444    $tpl_data->assign("monarchversion", $monarchversion);
445
[715]446    if ($version["gmetad"])
447    {
[753]448        $tpl_data->assign("webbackendcomponent", "gmetad");
449        $tpl_data->assign("webbackendversion",$version["gmetad"]);
[715]450    }
451    else if ($version["gmond"])
452    {
[753]453        $tpl_data->assign("webbackendcomponent", "gmond");
454        $tpl_data->assign("webbackendversion", $version["gmond"]);
[715]455    }
[117]456
[753]457    $tpl_data->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
[117]458
[753]459    $dwoo->output($tpl, $tpl_data);
[117]460}
461
[715]462if( isset( $h ) and $h != '' )
463{
464    $hostname = $h;
[149]465}
466
[753]467//$tpl_data->assign( "footer", template( "templates/footer.tpl" ) );
[117]468
[334]469$longtitle = "Batch Report :: Powered by Job Monarch!";
[323]470$title = "Batch Report";
[753]471//$tpl_data->assign("cluster_url", rawurlencode($clustername) );
472//$tpl_data->assign("cluster", $clustername );
[117]473
[753]474#makeHeader();
475
[715]476switch( $view )
477{
[117]478
[715]479    case "overview":
[117]480
[715]481        include "./overview.php";
482        makeOverview();
483        break;
[117]484
[715]485    case "search":
[117]486
[715]487        include "./search.php";
488        makeSearchPage();
489        break;
[117]490
[715]491    case "host":
[149]492
[715]493        include "./host_view.php";
494        makeHostView();
495        break;
[149]496
[734]497    case "overview-host":
498
499        include "./host_view.php";
500        makeHostView();
501        break;
502
[715]503    default:
[117]504
[753]505        include "./overview.php";
[715]506        makeOverview();
507        break;
[117]508}
509
510makeFooter();
[113]511?>
Note: See TracBrowser for help on using the repository browser.