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