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