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