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