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

Last change on this file since 761 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
Line 
1<?php
2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006-2013  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 758 2013-03-27 17:47:17Z ramonb $
23 */
24
25ini_set("memory_limit","500M");
26set_time_limit(0);
27
28$my_dir = getcwd();
29
30include_once "./libtoga.php";
31include_once "./dwoo/dwooAutoload.php";
32
33$r = escapeshellcmd( rawurldecode( $_GET["r"] ));
34$range = $r;
35if( !isset($range) or $range == '') $range= "job";
36
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
48if ( !empty( $_GET ) ) 
49{
50    extract( $_GET );
51}
52
53global $GANGLIA_PATH;
54
55//include_once "./class.TemplatePower.inc.php";
56
57$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
58$clustername = $httpvars->getClusterName();
59$view = $httpvars->getHttpVar( "j_view" );
60
61$filter = array();
62
63if( !isset($view) ) $view = "overview";
64if( !isset($sortorder) ) $sortorder = "desc";
65if( !isset($sortby) ) $sortby = "id";
66
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;
77}
78
79// Fill filter array in order they were picked by user
80if( isset($myfilter_fields) ) 
81{
82
83    foreach( $myfilter_fields as $myfilter ) 
84    {
85
86        switch( $myfilter ) 
87        {
88
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    }
103}
104
105function epochToDatetime( $epoch ) 
106{
107
108        return strftime( "%d-%m-%Y %H:%M:%S", $epoch );
109}
110
111function makeHeader( $page_call, $title, $longtitle ) 
112{
113    global $dwoo, $grid, $context, $initgrid;
114    global $jobrange, $jobstart;
115    global $page, $gridwalk, $clustername;
116    global $parentgrid, $physical, $hostname;
117    global $self, $filter, $cluster_url, $get_metric_string;
118    global $metrics, $reports, $m, $conf;
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;
122    global $conf, $show_hosts;
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
135   
136    if( isset($conf['default_metric']) and !isset($m) )
137        $metricname = $conf['default_metric'];
138    else
139        if( isset( $m ) )
140            $metricname = $m;
141        else
142            $metricname = "load_one";
143
144    $header = "header";
145
146    # Maintain our path through the grid tree.
147    $me = $self . "@" . $grid[$self][AUTHORITY];
148
149    $gridstack = array();
150    $gridstack[] = $me;
151
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    }
168
169    $gridstack_str = join(">", $gridstack);
170    $gridstack_url = rawurlencode($gridstack_str);
171
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    }
178
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]);
182
183    $tpl = new Dwoo_Template_File("templates/header.tpl");
184    $tpl_data = new Dwoo_Data();
185
186    $tpl_data->assign( "date", date("r") );
187    $tpl_data->assign( "longpage_title", $longtitle );
188    $tpl_data->assign( "page_title", $title );
189
190    # The page to go to when "Get Fresh Data" is pressed.
191    $tpl_data->assign("page","./");
192
193    # Templated Logo image
194    $tpl_data->assign("images","./templates/$template_name/images");
195
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";
201
202    if ($jobrange and $jobstart)
203        $get_metric_string .= "&jr=$jobrange&js=$jobstart";
204
205    # Set the Alternate view link.
206    $cluster_url=rawurlencode($clustername);
207    $node_url=rawurlencode($hostname);
208
209    # Make some information available to templates.
210    $tpl_data->assign("cluster_url", $cluster_url);
211    # Build the node_menu
212    $node_menu = "";
213
214    if ($parentgrid) 
215    {
216        $node_menu .= "<B>$parentgrid $meta_designator</B> ";
217        $node_menu .= "<B>&gt;</B>\n";
218    }
219
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";
224
225    if ($physical)
226    {
227        $node_menu .= hiddenvar("p", $physical);
228    }
229
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    }
237
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);
246
247    $mmfh    = array();
248
249    $mmfh    = $metrics[$firsthost];
250
251    $context_metrics    = array();
252
253    foreach( $mmfh as $mm => $bla )
254    {
255        $context_metrics[] = $mm;
256    }
257
258    foreach ($reports as $mr => $mfoo)
259        $context_metrics[] = $mr;
260
261    $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
262
263    if( isset( $hostname ) && ( $view != 'host' ) ) 
264    {
265
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    }
271
272    if( count( $filter ) > 0 && $view != "search" ) 
273    {
274
275        $my_ct = 1;
276        $filter_nr = count( $filter );
277
278        foreach( $filter as $filtername=>$filterval ) 
279        {
280
281            $node_menu .= "<B>&gt;</B>\n";
282
283            $href = "<A HREF=\"./?c=".rawurlencode($clustername);
284            $temp_ct = 0;
285            $n_filter = $filter;
286            $my_filterorder = "";
287            $my_filters = array_keys( $filter );
288
289            foreach( $n_filter as $n_filtername=>$n_filterval ) 
290            {
291
292                if( $temp_ct < $my_ct ) 
293                {
294                    $href .= "&". $n_filtername . "=" . $n_filterval;
295
296                    if( $my_filterorder == "" )
297                        $my_filterorder = $my_filters[$temp_ct];
298                    else
299                        $my_filterorder .= "," . $my_filters[$temp_ct];
300                }
301
302                $temp_ct++;
303            }
304            $href .= "&filterorder=$my_filterorder\">";
305
306            if( $my_ct < $filter_nr )
307                $node_menu .= "<B>$href$filtername: $filterval</A></B> ";
308            else
309                $node_menu .= "<B>$filtername: $filterval</B> ";
310
311            $my_ct++;
312        }
313    }
314
315    $tpl_data->assign("view", $view);
316
317    if( array_key_exists( "id", $filter ) or isset($hostname) )
318    {
319
320        #$range = "job";
321
322        if( $page_call != "host_view" )
323        {
324
325            if (is_array($context_metrics) )
326            {
327                $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
328                    ."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n";
329
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            }
341
342        }
343
344        $tpl_data->assign("metric_menu", $metric_menu );
345
346        if( $view == "search" or $view == "host" or $view == "overview-host" )
347        {
348            $tpl_data->assign("timeperiod", "yes" );
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            }
357            $tpl_data->assign("period_start", $period_start );
358            $tpl_data->assign("period_stop", $period_stop );
359            $tpl_data->assign("hostname", $hostname );
360
361            if( $view == "host" or $view == "overview-host" )
362            {
363                $tpl_data->assign("hostview", "yes");
364                $tpl_data->assign("job_start", $job_start );
365                $tpl_data->assign("job_stop", $job_stop );
366            }
367        }
368
369    }
370
371    if( array_key_exists( "id", $filter ) or isset($hostname) )
372    {
373
374        #$range = "job";
375
376        if( ( $page_call != "host_view" ) && ( $view != "search" ) )
377        {
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);
399        }
400
401    }
402
403    if( $view == "search" or $view == "host" )
404    {
405
406        $node_menu .= "<B>&gt;</B>\n";
407        $node_menu .= "<B>Jobarchive</B> ";
408        $form_name = "archive_search_form";
409        $tpl_data->assign("form_name", $form_name );
410
411    }
412    else
413    {
414        $form_name = "toga_form";
415        $tpl_data->assign("form_name", $form_name );
416    }
417
418    if( $JOB_ARCHIVE && $page_call == 'overview' )
419    {
420        $tpl_data->assign( "search", "yes" );
421        $tpl_data->assign( "cluster_url", rawurlencode($clustername) );
422        $tpl_data->assign( "cluster", $clustername );
423    }
424    $tpl_data->assign( "cluster", $clustername );
425    $tpl_data->assign("node_menu", $node_menu);
426
427    # Make sure that no data is cached..
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
432
433    $dwoo->output($tpl, $tpl_data);
434}
435
436function makeFooter()
437{
438    global $dwoo, $version, $parsetime, $monarchversion;
439
440    $tpl = new Dwoo_Template_File("templates/footer.tpl");
441    $tpl_data = new Dwoo_Data();
442
443    $tpl_data->assign("webfrontendversion",$version["webfrontend"]);
444    $tpl_data->assign("monarchversion", $monarchversion);
445
446    if ($version["gmetad"])
447    {
448        $tpl_data->assign("webbackendcomponent", "gmetad");
449        $tpl_data->assign("webbackendversion",$version["gmetad"]);
450    }
451    else if ($version["gmond"])
452    {
453        $tpl_data->assign("webbackendcomponent", "gmond");
454        $tpl_data->assign("webbackendversion", $version["gmond"]);
455    }
456
457    $tpl_data->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
458
459    $dwoo->output($tpl, $tpl_data);
460}
461
462if( isset( $h ) and $h != '' )
463{
464    $hostname = $h;
465}
466
467//$tpl_data->assign( "footer", template( "templates/footer.tpl" ) );
468
469$longtitle = "Batch Report :: Powered by Job Monarch!";
470$title = "Batch Report";
471//$tpl_data->assign("cluster_url", rawurlencode($clustername) );
472//$tpl_data->assign("cluster", $clustername );
473
474#makeHeader();
475
476switch( $view )
477{
478
479    case "overview":
480
481        include "./overview.php";
482        makeOverview();
483        break;
484
485    case "search":
486
487        include "./search.php";
488        makeSearchPage();
489        break;
490
491    case "host":
492
493        include "./host_view.php";
494        makeHostView();
495        break;
496
497    case "overview-host":
498
499        include "./host_view.php";
500        makeHostView();
501        break;
502
503    default:
504
505        include "./overview.php";
506        makeOverview();
507        break;
508}
509
510makeFooter();
511?>
Note: See TracBrowser for help on using the repository browser.