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