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