1 | <?php |
---|
2 | |
---|
3 | if ( !empty( $_GET ) ) { |
---|
4 | extract( $_GET ); |
---|
5 | } |
---|
6 | |
---|
7 | $my_dir = getcwd(); |
---|
8 | |
---|
9 | include_once "./libtoga.php"; |
---|
10 | |
---|
11 | global $GANGLIA_PATH; |
---|
12 | chdir( $GANGLIA_PATH ); |
---|
13 | |
---|
14 | include_once "./class.TemplatePower.inc.php"; |
---|
15 | chdir( $my_dir ); |
---|
16 | |
---|
17 | $httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET ); |
---|
18 | $clustername = $httpvars->getClusterName(); |
---|
19 | $view = $httpvars->getHttpVar( "view" ); |
---|
20 | |
---|
21 | $filter = array(); |
---|
22 | |
---|
23 | if( !isset($view) ) $view = "overview"; |
---|
24 | if( !isset($sortorder) ) $sortorder = "asc"; |
---|
25 | if( !isset($sortby) ) $sortby = "id"; |
---|
26 | if( isset($queue) && ($queue!='')) $filter[queue]=$queue; |
---|
27 | if( isset($state) && ($state!='')) $filter[state]=$state; |
---|
28 | if( isset($user) && ($user!='')) $filter[user]=$user; |
---|
29 | if( isset($id) && ($id!='')) $filter[id]=$id; |
---|
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; |
---|
37 | global $self, $filter, $cluster_url, $get_metric_string; |
---|
38 | global $metrics, $reports, $m, $default_metric; |
---|
39 | global $default_refresh, $filterorder, $view; |
---|
40 | global $TARCHD; |
---|
41 | |
---|
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 | |
---|
50 | $header = "header"; |
---|
51 | |
---|
52 | # Maintain our path through the grid tree. |
---|
53 | $me = $self . "@" . $grid[$self][AUTHORITY]; |
---|
54 | |
---|
55 | $gridstack = array(); |
---|
56 | $gridstack[] = $me; |
---|
57 | |
---|
58 | if ($gridwalk=="fwd") { |
---|
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. |
---|
98 | $tpl->assign("page","./"); |
---|
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; |
---|
128 | $node_menu .= "<B>$mygrid $meta_designator</B> "; |
---|
129 | $node_menu .= "<B>></B>\n"; |
---|
130 | |
---|
131 | if ($physical) |
---|
132 | $node_menu .= hiddenvar("p", $physical); |
---|
133 | |
---|
134 | if ( $clustername ) { |
---|
135 | $url = rawurlencode($clustername); |
---|
136 | $node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> "; |
---|
137 | $node_menu .= "<B>></B>\n"; |
---|
138 | $node_menu .= hiddenvar("c", $clustername); |
---|
139 | } |
---|
140 | |
---|
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; |
---|
148 | |
---|
149 | foreach ($reports as $r => $foo) |
---|
150 | $context_metrics[] = $r; |
---|
151 | |
---|
152 | $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> "; |
---|
153 | |
---|
154 | if( count( $filter ) > 0 && $view != "search" ) { |
---|
155 | |
---|
156 | $filter_fields = explode( ",", $filterorder ); |
---|
157 | $onclick_href = array(); |
---|
158 | |
---|
159 | if( count( $filter_fields ) > 1 ) { |
---|
160 | //for( $i = (count( $filter_fields )-2); $i >= 0; $i-- ) { |
---|
161 | |
---|
162 | // for( $l = intval($i+1); $l <=(count($filter_fields)-1); $l++ ) { |
---|
163 | //$onclick_href[$filter_fields[$i]] = $onclick_href[$filter_fields[$i]] . "removeFilter( '" . $filter_fields[$l] . "' );"; |
---|
164 | // if( !isset( $onclick_href[$filter_fields[$i]] ) ) |
---|
165 | // $onclick_href[$filter_fields[$i]] = "removeFilters( '".$filter_fields[$l]; |
---|
166 | // else |
---|
167 | // $onclick_href[$filter_fields[$i]] = $onclick_href[$filter_fields[$i]] . " ". $filter_fields[$l]; |
---|
168 | |
---|
169 | // } |
---|
170 | // $onclick_href[$filter_fields[$i]] = $onclick_href[$filter_fields[$i]] . "' )"; |
---|
171 | //} |
---|
172 | foreach( $filter_fields as $filtername ) { |
---|
173 | |
---|
174 | $node_menu .= "<B>></B>\n"; |
---|
175 | if( isset( $onclick_href[$filtername] ) ) |
---|
176 | $node_menu .= "<B><A HREF =\"#\" onClick=\"".$onclick_href[$filtername]."\">$filtername: $filter[$filtername]</A></B> "; |
---|
177 | else |
---|
178 | $node_menu .= "<B>$filtername: $filter[$filtername]</B> "; |
---|
179 | } |
---|
180 | } else { |
---|
181 | |
---|
182 | foreach( $filter as $filtername=>$filterval ) { |
---|
183 | $node_menu .= "<B>></B>\n"; |
---|
184 | $node_menu .= "<B>$filtername: $filterval</B> "; |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | if( $view == "search" ) { |
---|
191 | $node_menu .= "<B>></B>\n"; |
---|
192 | $node_menu .= "<B>Jobarchive</B> "; |
---|
193 | $tpl->assign("view", "search" ); |
---|
194 | $form_name = "archive_search_form"; |
---|
195 | $tpl->assign("form_name", $form_name ); |
---|
196 | } else { |
---|
197 | $form_name = "toga_form"; |
---|
198 | $tpl->assign("form_name", $form_name ); |
---|
199 | $tpl->assign("view", "overview" ); |
---|
200 | } |
---|
201 | |
---|
202 | $tpl->assign("node_menu", $node_menu); |
---|
203 | |
---|
204 | if( array_key_exists( "id", $filter ) ) { |
---|
205 | |
---|
206 | if (is_array($context_metrics) ) { |
---|
207 | $metric_menu = "<B>Metric</B> " |
---|
208 | ."<SELECT NAME=\"m\" OnChange=\"".$form_name.".submit();\">\n"; |
---|
209 | |
---|
210 | sort($context_metrics); |
---|
211 | foreach( $context_metrics as $k ) { |
---|
212 | $url = rawurlencode($k); |
---|
213 | $metric_menu .= "<OPTION VALUE=\"$url\" "; |
---|
214 | if ($k == $metricname ) |
---|
215 | $metric_menu .= "SELECTED"; |
---|
216 | $metric_menu .= ">$k\n"; |
---|
217 | } |
---|
218 | $metric_menu .= "</SELECT>\n"; |
---|
219 | |
---|
220 | $tpl->assign("metric_menu", $metric_menu ); |
---|
221 | } |
---|
222 | } |
---|
223 | $m = $metricname; |
---|
224 | |
---|
225 | if( $TARCHD ) { |
---|
226 | $tpl->newBlock( "search" ); |
---|
227 | $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) ); |
---|
228 | $tpl->assignGlobal( "cluster", $clustername ); |
---|
229 | $tpl->gotoBlock( "_ROOT" ); |
---|
230 | } |
---|
231 | |
---|
232 | # Make sure that no data is cached.. |
---|
233 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Date in the past |
---|
234 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified |
---|
235 | header ("Cache-Control: no-cache, must-revalidate"); # HTTP/1.1 |
---|
236 | header ("Pragma: no-cache"); # HTTP/1.0 |
---|
237 | } |
---|
238 | |
---|
239 | function makeFooter() { |
---|
240 | global $tpl, $version, $parsetime; |
---|
241 | |
---|
242 | $tpl->assign("webfrontend-version",$version["webfrontend"]); |
---|
243 | $tpl->assign("togaweb-version", "0.1"); |
---|
244 | $tpl->assign("togaarch-version", "0.1"); |
---|
245 | $tpl->assign("togaplug-version", "0.1"); |
---|
246 | |
---|
247 | if ($version["gmetad"]) { |
---|
248 | $tpl->assign("webbackend-component", "gmetad"); |
---|
249 | $tpl->assign("webbackend-version",$version["gmetad"]); |
---|
250 | } else if ($version["gmond"]) { |
---|
251 | $tpl->assign("webbackend-component", "gmond"); |
---|
252 | $tpl->assign("webbackend-version", $version["gmond"]); |
---|
253 | } |
---|
254 | |
---|
255 | $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s"); |
---|
256 | } |
---|
257 | |
---|
258 | function includeSearchpage() { |
---|
259 | global $tpl; |
---|
260 | |
---|
261 | $tpl->assignInclude( "main", "templates/search.tpl" ); |
---|
262 | |
---|
263 | } |
---|
264 | |
---|
265 | function includeOverview() { |
---|
266 | global $tpl; |
---|
267 | |
---|
268 | $tpl->assignInclude( "main", "templates/overview.tpl" ); |
---|
269 | } |
---|
270 | |
---|
271 | $tpl = new TemplatePower( "templates/index.tpl" ); |
---|
272 | |
---|
273 | $tpl->assignInclude( "header", "templates/header.tpl" ); |
---|
274 | |
---|
275 | switch( $view ) { |
---|
276 | |
---|
277 | case "overview": |
---|
278 | |
---|
279 | includeOverview(); |
---|
280 | break; |
---|
281 | |
---|
282 | case "search": |
---|
283 | |
---|
284 | includeSearchPage(); |
---|
285 | break; |
---|
286 | |
---|
287 | default: |
---|
288 | |
---|
289 | includeOverview(); |
---|
290 | break; |
---|
291 | } |
---|
292 | |
---|
293 | $tpl->assignInclude( "footer", "templates/footer.tpl" ); |
---|
294 | $tpl->prepare(); |
---|
295 | |
---|
296 | $title = "Torque Report"; |
---|
297 | makeHeader(); |
---|
298 | $tpl->assign("cluster_url", rawurlencode($clustername) ); |
---|
299 | $tpl->assign("cluster", $clustername ); |
---|
300 | |
---|
301 | switch( $view ) { |
---|
302 | |
---|
303 | case "overview": |
---|
304 | |
---|
305 | include "./overview.php"; |
---|
306 | makeOverview(); |
---|
307 | break; |
---|
308 | |
---|
309 | case "search": |
---|
310 | |
---|
311 | include "./search.php"; |
---|
312 | makeSearchPage(); |
---|
313 | break; |
---|
314 | |
---|
315 | default: |
---|
316 | |
---|
317 | makeOverview(); |
---|
318 | break; |
---|
319 | } |
---|
320 | |
---|
321 | makeFooter(); |
---|
322 | $tpl->printToScreen(); |
---|
323 | ?> |
---|