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