1 | <?php |
---|
2 | global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh; |
---|
3 | global $hosts_up, $m, $start, $end, $filterorder; |
---|
4 | |
---|
5 | //$tpl->assign("_ROOT.summary", "" ); |
---|
6 | |
---|
7 | $data_gatherer = new DataGatherer(); |
---|
8 | |
---|
9 | //$tpl->assign( "self", "./index.php" ); |
---|
10 | $tpl->assign( "clustername", $clustername ); |
---|
11 | |
---|
12 | if( $TARCHD ) |
---|
13 | $tpl->assign( "cluster_url", rawurlencode($clustername) ); |
---|
14 | |
---|
15 | $data_gatherer->parseXML(); |
---|
16 | |
---|
17 | $heartbeat = $data_gatherer->getHeartbeat(); |
---|
18 | $jobs = $data_gatherer->getJobs(); |
---|
19 | $gnodes = $data_gatherer->getNodes(); |
---|
20 | $cpus = $data_gatherer->getCpus(); |
---|
21 | |
---|
22 | $filter_image_url = ""; |
---|
23 | |
---|
24 | foreach( $filter as $filtername => $filtervalue ) { |
---|
25 | $tpl->assign( "f_".$filtername, $filtervalue ); |
---|
26 | $filter_image_url .= "&$filtername=$filtervalue"; |
---|
27 | } |
---|
28 | |
---|
29 | $tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url ); |
---|
30 | $tpl->assign( "f_order", $filterorder ); |
---|
31 | |
---|
32 | if( array_key_exists( "id", $filter ) ) |
---|
33 | $piefilter = 'id'; |
---|
34 | else if( array_key_exists( "user", $filter ) ) |
---|
35 | $piefilter = 'user'; |
---|
36 | else if( array_key_exists( "queue", $filter ) ) |
---|
37 | $piefilter = 'queue'; |
---|
38 | |
---|
39 | $pie = drawPie(); |
---|
40 | $tpl->assign("pie", $pie ); |
---|
41 | |
---|
42 | //if( !array_key_exists( 'id', $filter ) ) { |
---|
43 | |
---|
44 | // $graph_args = "c=$cluster_url&$get_metric_string&st=$cluster[LOCALTIME]"; |
---|
45 | // $tpl->newBlock( "average_graphs" ); |
---|
46 | // $tpl->assign( "graph_args", $graph_args ); |
---|
47 | //} |
---|
48 | |
---|
49 | function timeToEpoch( $time ) { |
---|
50 | |
---|
51 | $time_fields = explode( ':', $time ); |
---|
52 | |
---|
53 | if( count($time_fields) == 3 ) { |
---|
54 | |
---|
55 | $hours = $time_fields[0]; |
---|
56 | $minutes = $time_fields[1]; |
---|
57 | $seconds = $time_fields[2]; |
---|
58 | |
---|
59 | } else if( count($time_fields) == 2 ) { |
---|
60 | |
---|
61 | $hours = 0; |
---|
62 | $minutes = $time_fields[0]; |
---|
63 | $seconds = $time_fields[1]; |
---|
64 | |
---|
65 | } else if( count($time_fields) == 1 ) { |
---|
66 | |
---|
67 | $hours = 0; |
---|
68 | $minutes = 0; |
---|
69 | $seconds = $time_fields[0]; |
---|
70 | } |
---|
71 | |
---|
72 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
73 | |
---|
74 | return $myepoch; |
---|
75 | } |
---|
76 | |
---|
77 | function makeTime( $time ) { |
---|
78 | |
---|
79 | $days = intval( $time / 86400 ); |
---|
80 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
81 | |
---|
82 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
83 | |
---|
84 | $date_str = ''; |
---|
85 | $day_str = ''; |
---|
86 | |
---|
87 | if( $days > 0 ) { |
---|
88 | if( $days > 1 ) |
---|
89 | $day_str .= $days . ' days'; |
---|
90 | else |
---|
91 | $day_str .= $days . ' day'; |
---|
92 | } |
---|
93 | |
---|
94 | $hours = intval( $time / 3600 ); |
---|
95 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
96 | |
---|
97 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
98 | |
---|
99 | if( $hours > 0 ) { |
---|
100 | $date_str .= $hours . ':'; |
---|
101 | $date_unit = 'hours'; |
---|
102 | } |
---|
103 | |
---|
104 | $minutes = intval( $time / 60 ); |
---|
105 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
106 | |
---|
107 | if( $minutes > 0 ) { |
---|
108 | |
---|
109 | if( $minutes >= 10 ) |
---|
110 | $date_str .= $minutes . ':'; |
---|
111 | else |
---|
112 | $date_str .= '0' . $minutes . ':'; |
---|
113 | |
---|
114 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
115 | } else { |
---|
116 | if($hours > 0 ) { |
---|
117 | $date_str .= '00:'; |
---|
118 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
124 | |
---|
125 | if( $seconds > 0 ) { |
---|
126 | |
---|
127 | if( $seconds >= 10 ) |
---|
128 | $date_str .= $seconds . ' ' . $date_unit; |
---|
129 | else |
---|
130 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
131 | |
---|
132 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
133 | |
---|
134 | $date_str .= '00 ' . $date_unit; |
---|
135 | |
---|
136 | if( $days > 0) { |
---|
137 | |
---|
138 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
139 | $date_str = $day_str . ' - ' . $date_str; |
---|
140 | else |
---|
141 | $date_str = $day_str; |
---|
142 | } |
---|
143 | |
---|
144 | return $date_str; |
---|
145 | } |
---|
146 | |
---|
147 | function makeDate( $time ) { |
---|
148 | return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
149 | } |
---|
150 | |
---|
151 | function colorRed( $color ) { |
---|
152 | return substr( $color, 0, 2 ); |
---|
153 | } |
---|
154 | function colorGreen( $color ) { |
---|
155 | return substr( $color, 2, 2 ); |
---|
156 | } |
---|
157 | function colorBlue( $color ) { |
---|
158 | return substr( $color, 4, 2 ); |
---|
159 | } |
---|
160 | |
---|
161 | function colorDiffer( $first, $second ) { |
---|
162 | |
---|
163 | // Make sure these two colors differ atleast 50 R/G/B |
---|
164 | $min_diff = 50; |
---|
165 | |
---|
166 | $c1r = hexDec( colorRed( $first ) ); |
---|
167 | $c1g = hexDec( colorGreen( $first ) ); |
---|
168 | $c1b = hexDec( colorBlue( $first ) ); |
---|
169 | |
---|
170 | $c2r = hexDec( colorRed( $second ) ); |
---|
171 | $c2g = hexDec( colorGreen( $second ) ); |
---|
172 | $c2b = hexDec( colorBlue( $second ) ); |
---|
173 | |
---|
174 | $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; |
---|
175 | $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; |
---|
176 | $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; |
---|
177 | |
---|
178 | if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) |
---|
179 | return TRUE; |
---|
180 | else |
---|
181 | return FALSE; |
---|
182 | } |
---|
183 | |
---|
184 | function randomColor( $known_colors ) { |
---|
185 | |
---|
186 | $start = "004E00"; |
---|
187 | |
---|
188 | $start_red = colorRed( $start ); |
---|
189 | $start_green = colorGreen( $start ); |
---|
190 | $start_blue = colorBlue( $start ); |
---|
191 | |
---|
192 | $end = "FFFFFF"; |
---|
193 | |
---|
194 | $end_red = colorRed( $end ); |
---|
195 | $end_green = colorGreen( $end ); |
---|
196 | $end_blue = colorBlue( $end ); |
---|
197 | |
---|
198 | $change_color = TRUE; |
---|
199 | |
---|
200 | while( $change_color ) { |
---|
201 | |
---|
202 | $change_color = FALSE; |
---|
203 | |
---|
204 | $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) ); |
---|
205 | $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) ); |
---|
206 | $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) ); |
---|
207 | |
---|
208 | $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue ); |
---|
209 | |
---|
210 | foreach( $known_colors as $old ) |
---|
211 | |
---|
212 | if( !colorDiffer( $new, $old ) ) |
---|
213 | |
---|
214 | $change_color = TRUE; |
---|
215 | } |
---|
216 | |
---|
217 | // Whoa! Actually found a good color ;) |
---|
218 | return $new; |
---|
219 | } |
---|
220 | |
---|
221 | function drawJobPie() { |
---|
222 | } |
---|
223 | |
---|
224 | function drawUserPie() { |
---|
225 | |
---|
226 | } |
---|
227 | |
---|
228 | function drawQueuePie() { |
---|
229 | |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | function drawPie() { |
---|
234 | |
---|
235 | global $jobs, $gnodes, $piefilter, $filter; |
---|
236 | |
---|
237 | $nodes = $gnodes; |
---|
238 | |
---|
239 | if( isset($piefilter) ) |
---|
240 | $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage"); |
---|
241 | else |
---|
242 | $pie_args = "title=" . rawurlencode("Cluster queue usage"); |
---|
243 | |
---|
244 | $pie_args .= "&size=250x150"; |
---|
245 | |
---|
246 | $queues = array(); |
---|
247 | $nr_jobs = count( $jobs ); |
---|
248 | $nr_nodes = count( $nodes ); |
---|
249 | |
---|
250 | $emptynodes = 0; |
---|
251 | |
---|
252 | $job_weight = array(); |
---|
253 | |
---|
254 | foreach( $nodes as $node ) { |
---|
255 | |
---|
256 | $myjobs = $node->getJobs(); |
---|
257 | |
---|
258 | if( count( $myjobs ) == 0 ) |
---|
259 | $emptynodes++; |
---|
260 | } |
---|
261 | $used_nodes = $nr_nodes - $emptynodes; |
---|
262 | |
---|
263 | $empty_percentage = ($emptynodes / $nr_nodes) * 100; |
---|
264 | $job_percentage = 100 - $empty_percentage; |
---|
265 | |
---|
266 | $qcolors = array(); |
---|
267 | $color = randomColor( $qcolors ); |
---|
268 | $qcolors[] = $color; |
---|
269 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
270 | |
---|
271 | if( isset( $piefilter ) ) |
---|
272 | $filterpie = array(); |
---|
273 | |
---|
274 | foreach( $nodes as $node ) { |
---|
275 | |
---|
276 | $node_jobs = $node->getJobs(); |
---|
277 | $nr_node_jobs = count( $node_jobs ); |
---|
278 | $myhost = $node->getHostname(); |
---|
279 | |
---|
280 | foreach( $node_jobs as $myjob ) { |
---|
281 | |
---|
282 | // Determine the weight of this job on the node it is running |
---|
283 | // - what percentage of the node is in use by this job |
---|
284 | // |
---|
285 | $job_weight[$myjob] = ( 100 / count( $node_jobs ) ) / 100; |
---|
286 | $qname = $jobs[$myjob][queue]; |
---|
287 | |
---|
288 | if( isset($piefilter) ) { |
---|
289 | $countjob = 1; |
---|
290 | if( $piefilter == 'id' ) { |
---|
291 | if( $myjob != $filter[$piefilter] ) |
---|
292 | $countjob = 0; |
---|
293 | } else if( $piefilter == 'user' ) { |
---|
294 | if( $jobs[$myjob][owner] != $filter[$piefilter] ) |
---|
295 | $countjob = 0; |
---|
296 | } else { |
---|
297 | if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) |
---|
298 | $countjob = 0; |
---|
299 | } |
---|
300 | |
---|
301 | if( $countjob ) { |
---|
302 | |
---|
303 | if( !isset( $filterpie[$filter[$piefilter]] ) ) |
---|
304 | $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; |
---|
305 | else |
---|
306 | $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; |
---|
307 | } else { |
---|
308 | if( !isset( $filterpie["other"] ) ) |
---|
309 | $filterpie["other"] = $job_weight[$myjob]; |
---|
310 | else |
---|
311 | $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; |
---|
312 | |
---|
313 | } |
---|
314 | |
---|
315 | } else { |
---|
316 | |
---|
317 | if( !isset( $queues[$qname] ) ) |
---|
318 | $queues[$qname] = $job_weight[$myjob]; |
---|
319 | else |
---|
320 | $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; |
---|
321 | } |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | //$qcolors = array(); |
---|
326 | if( isset( $piefilter ) ) |
---|
327 | $graphvals = $filterpie; |
---|
328 | else |
---|
329 | $graphvals = $queues; |
---|
330 | |
---|
331 | foreach( $graphvals as $name => $totalweight) { |
---|
332 | |
---|
333 | $percentage = ( $totalweight / $used_nodes ) * $job_percentage; |
---|
334 | |
---|
335 | $color = randomColor( $qcolors ); |
---|
336 | $qcolors[] = $color; |
---|
337 | $pie_args .= "&$name=$percentage,$color"; |
---|
338 | } |
---|
339 | $pie = "../../pie.php?$pie_args"; |
---|
340 | |
---|
341 | return $pie; |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | function sortJobs( $jobs, $sortby, $sortorder ) { |
---|
346 | |
---|
347 | $sorted = array(); |
---|
348 | |
---|
349 | $cmp = create_function( '$a, $b', |
---|
350 | "global \$sortby, \$sortorder;". |
---|
351 | |
---|
352 | "if( \$a == \$b ) return 0;". |
---|
353 | |
---|
354 | "if (\$sortorder==\"desc\")". |
---|
355 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
356 | "else if (\$sortorder==\"asc\")". |
---|
357 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
358 | |
---|
359 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
360 | |
---|
361 | $state = $jobattrs[status]; |
---|
362 | $user = $jobattrs[owner]; |
---|
363 | $queue = $jobattrs[queue]; |
---|
364 | $name = $jobattrs[name]; |
---|
365 | $req_cpu = $jobattrs[requested_time]; |
---|
366 | $req_memory = $jobattrs[requested_memory]; |
---|
367 | |
---|
368 | if( $state == 'R' ) |
---|
369 | $nodes = count( $jobattrs[nodes] ); |
---|
370 | else |
---|
371 | $nodes = $jobattrs[nodes]; |
---|
372 | |
---|
373 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
374 | $cpus = $nodes * $ppn; |
---|
375 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
376 | $runningtime = $report_time - $start_time; |
---|
377 | |
---|
378 | switch( $sortby ) { |
---|
379 | case "id": |
---|
380 | $sorted[$jobid] = $jobid; |
---|
381 | break; |
---|
382 | |
---|
383 | case "state": |
---|
384 | $sorted[$jobid] = $state; |
---|
385 | break; |
---|
386 | |
---|
387 | case "user": |
---|
388 | $sorted[$jobid] = $user; |
---|
389 | break; |
---|
390 | |
---|
391 | case "queue": |
---|
392 | $sorted[$jobid] = $queue; |
---|
393 | break; |
---|
394 | |
---|
395 | case "name": |
---|
396 | $sorted[$jobid] = $name; |
---|
397 | break; |
---|
398 | |
---|
399 | case "req_cpu": |
---|
400 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
401 | break; |
---|
402 | |
---|
403 | case "req_mem": |
---|
404 | $sorted[$jobid] = $req_memory; |
---|
405 | break; |
---|
406 | |
---|
407 | case "nodes": |
---|
408 | $sorted[$jobid] = $nodes; |
---|
409 | break; |
---|
410 | |
---|
411 | case "cpus": |
---|
412 | $sorted[$jobid] = $cpus; |
---|
413 | break; |
---|
414 | |
---|
415 | case "start": |
---|
416 | $sorted[$jobid] = $start_time; |
---|
417 | break; |
---|
418 | |
---|
419 | case "runningtime": |
---|
420 | $sorted[$jobid] = $runningtime; |
---|
421 | break; |
---|
422 | |
---|
423 | default: |
---|
424 | break; |
---|
425 | |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | //uasort( $sorted, $cmp ); |
---|
430 | if( $sortorder == "asc" ) |
---|
431 | arsort( $sorted ); |
---|
432 | else if( $sortorder == "desc" ) |
---|
433 | asort( $sorted ); |
---|
434 | |
---|
435 | return $sorted; |
---|
436 | } |
---|
437 | |
---|
438 | function makeOverview() { |
---|
439 | |
---|
440 | global $jobs, $nodes, $heartbeat, $clustername, $tpl; |
---|
441 | global $sortorder, $sortby, $filter, $sh, $hc, $m; |
---|
442 | global $cluster_url, $get_metric_string, $host_url, $metrics; |
---|
443 | global $start, $end, $reports, $gnodes, $default_showhosts; |
---|
444 | |
---|
445 | $metricname = $m; |
---|
446 | |
---|
447 | $tpl->assign("sortorder", $sortorder ); |
---|
448 | $tpl->assign("sortby", $sortby ); |
---|
449 | |
---|
450 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
451 | |
---|
452 | $even = 1; |
---|
453 | |
---|
454 | $used_jobs = 0; |
---|
455 | $used_cpus = 0; |
---|
456 | $used_nodes = 0; |
---|
457 | |
---|
458 | $all_used_nodes = array(); |
---|
459 | |
---|
460 | $avail_nodes = count( $gnodes ); |
---|
461 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
462 | |
---|
463 | $view_cpus = 0; |
---|
464 | $view_jobs = 0; |
---|
465 | $view_nodes = 0; |
---|
466 | |
---|
467 | $view_used_nodes = array(); |
---|
468 | |
---|
469 | foreach( $sorted_jobs as $jobid => $sortdec ) { |
---|
470 | |
---|
471 | $report_time = $jobs[$jobid][reported]; |
---|
472 | |
---|
473 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
474 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
475 | $cpus = $nodes * $ppn; |
---|
476 | |
---|
477 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
478 | $all_used_nodes[] = $tempnode; |
---|
479 | |
---|
480 | if( $jobs[$jobid][status] == 'R' ) { |
---|
481 | $used_cpus += $cpus; |
---|
482 | $used_jobs++; |
---|
483 | } |
---|
484 | |
---|
485 | if( $report_time == $heartbeat ) { |
---|
486 | |
---|
487 | $display_job = 1; |
---|
488 | |
---|
489 | foreach( $filter as $filtername=>$filtervalue ) { |
---|
490 | |
---|
491 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
492 | $display_job = 0; |
---|
493 | else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue ) |
---|
494 | $display_job = 0; |
---|
495 | else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue ) |
---|
496 | $display_job = 0; |
---|
497 | else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue ) |
---|
498 | $display_job = 0; |
---|
499 | } |
---|
500 | |
---|
501 | if( $display_job ) { |
---|
502 | |
---|
503 | $tpl->newBlock("node"); |
---|
504 | $tpl->assign( "clustername", $clustername ); |
---|
505 | $tpl->assign("id", $jobid ); |
---|
506 | $tpl->assign("state", $jobs[$jobid][status] ); |
---|
507 | $tpl->assign("user", $jobs[$jobid][owner] ); |
---|
508 | $tpl->assign("queue", $jobs[$jobid][queue] ); |
---|
509 | $tpl->assign("name", $jobs[$jobid][name] ); |
---|
510 | $domain = $jobs[$jobid][domain]; |
---|
511 | $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); |
---|
512 | $tpl->assign("req_memory", $jobs[$jobid][requested_memory] ); |
---|
513 | |
---|
514 | if( $jobs[$jobid][status] == 'R' ) |
---|
515 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
516 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
517 | $nodes = $jobs[$jobid][nodes]; |
---|
518 | |
---|
519 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
520 | $cpus = $nodes * $ppn; |
---|
521 | $tpl->assign("nodes", $nodes ); |
---|
522 | $tpl->assign("cpus", $cpus ); |
---|
523 | $start_time = (int) $jobs[$jobid][start_timestamp]; |
---|
524 | $job_start = $start_time; |
---|
525 | |
---|
526 | $view_cpus += $cpus; |
---|
527 | $view_jobs++; |
---|
528 | |
---|
529 | if( $jobs[$jobid][status] == 'R' ) |
---|
530 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
531 | $view_used_nodes[] = $tempnode; |
---|
532 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
533 | $view_nodes += $jobs[$jobid][nodes]; |
---|
534 | |
---|
535 | if( $even ) { |
---|
536 | |
---|
537 | $tpl->assign("nodeclass", "even"); |
---|
538 | $even = 0; |
---|
539 | } else { |
---|
540 | |
---|
541 | $tpl->assign("nodeclass", "odd"); |
---|
542 | $even = 1; |
---|
543 | } |
---|
544 | |
---|
545 | if( $start_time ) { |
---|
546 | |
---|
547 | $runningtime = makeTime( $report_time - $start_time ); |
---|
548 | $job_runningtime = $report_time - $start_time; |
---|
549 | $tpl->assign("started", makeDate( $start_time ) ); |
---|
550 | $tpl->assign("runningtime", $runningtime ); |
---|
551 | } |
---|
552 | } |
---|
553 | } |
---|
554 | } |
---|
555 | array_unique( $all_used_nodes ); |
---|
556 | array_unique( $view_used_nodes ); |
---|
557 | $used_nodes = count( $all_used_nodes ); |
---|
558 | $view_nodes += count( $view_used_nodes ); |
---|
559 | |
---|
560 | //$tpl->assignGlobal("cpus_nr", $overview_cpus ); |
---|
561 | //$tpl->assignGlobal("jobs_nr", $overview_jobs ); |
---|
562 | |
---|
563 | $tpl->assignGlobal("avail_nodes", $avail_nodes ); |
---|
564 | $tpl->assignGlobal("avail_cpus", $avail_cpus ); |
---|
565 | |
---|
566 | $tpl->assignGlobal("used_nodes", $used_nodes ); |
---|
567 | $tpl->assignGlobal("used_jobs", $used_jobs ); |
---|
568 | $tpl->assignGlobal("used_cpus", $used_cpus ); |
---|
569 | |
---|
570 | $tpl->assignGlobal("view_nodes", $view_nodes ); |
---|
571 | $tpl->assignGlobal("view_jobs", $view_jobs ); |
---|
572 | $tpl->assignGlobal("view_cpus", $view_cpus ); |
---|
573 | |
---|
574 | $tpl->assignGlobal("report_time", makeDate( $heartbeat)); |
---|
575 | |
---|
576 | //$tpl->assignGlobal("f_cpus_nr", $f_cpus ); |
---|
577 | //$tpl->assignGlobal("f_jobs_nr", $f_jobs ); |
---|
578 | |
---|
579 | if( array_key_exists( "id", $filter ) and $start_time ) { |
---|
580 | $tpl->newBlock( "showhosts" ); |
---|
581 | |
---|
582 | # Present a width list |
---|
583 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
584 | |
---|
585 | $hostcols = ($hc) ? $hc : 4; |
---|
586 | |
---|
587 | foreach(range(1,25) as $cols) { |
---|
588 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
589 | if ($cols == $hostcols) |
---|
590 | $cols_menu .= "SELECTED"; |
---|
591 | $cols_menu .= ">$cols\n"; |
---|
592 | } |
---|
593 | $cols_menu .= "</SELECT>\n"; |
---|
594 | |
---|
595 | //$tpl->assign("cluster", $clustername); |
---|
596 | $tpl->assign("metric","$metricname $units"); |
---|
597 | $tpl->assign("id", $filter[id]); |
---|
598 | # Host columns menu defined in header.php |
---|
599 | $tpl->assign("cols_menu", $cols_menu); |
---|
600 | |
---|
601 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
602 | //if( !$showhosts) $showhosts = $default_showhosts; |
---|
603 | $tpl->assign("checked$showhosts", "checked"); |
---|
604 | |
---|
605 | if( $showhosts ) { |
---|
606 | //----- |
---|
607 | |
---|
608 | if( !isset($start) ) $start="jobstart"; |
---|
609 | if( !isset($stop) ) $stop="now"; |
---|
610 | //$tpl->assign("start", $start); |
---|
611 | //$tpl->assign("stop", $stop); |
---|
612 | |
---|
613 | $sorted_hosts = array(); |
---|
614 | $hosts_up = $jobs[$filter[id]][nodes]; |
---|
615 | |
---|
616 | $r = intval($job_runningtime * 1.25); |
---|
617 | |
---|
618 | $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; |
---|
619 | $jobstart = $report_time - $job_runningtime; |
---|
620 | |
---|
621 | if ($reports[$metricname]) |
---|
622 | $metricval = "g"; |
---|
623 | else |
---|
624 | $metricval = "m"; |
---|
625 | |
---|
626 | foreach ($hosts_up as $host ) { |
---|
627 | $host = $host. '.'.$domain; |
---|
628 | $cpus = $metrics[$host]["cpu_num"][VAL]; |
---|
629 | if (!$cpus) $cpus=1; |
---|
630 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
631 | $load = ((float) $load_one)/$cpus; |
---|
632 | $host_load[$host] = $load; |
---|
633 | $percent_hosts[load_color($load)] += 1; |
---|
634 | if ($metricname=="load_one") |
---|
635 | $sorted_hosts[$host] = $load; |
---|
636 | else |
---|
637 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
638 | } |
---|
639 | switch ($sort) { |
---|
640 | case "descending": |
---|
641 | arsort($sorted_hosts); |
---|
642 | break; |
---|
643 | case "by hostname": |
---|
644 | ksort($sorted_hosts); |
---|
645 | break; |
---|
646 | default: |
---|
647 | case "ascending": |
---|
648 | asort($sorted_hosts); |
---|
649 | break; |
---|
650 | } |
---|
651 | |
---|
652 | //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); |
---|
653 | |
---|
654 | # First pass to find the max value in all graphs for this |
---|
655 | # metric. The $start,$end variables comes from get_context.php, |
---|
656 | # included in index.php. |
---|
657 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
658 | |
---|
659 | # Second pass to output the graphs or metrics. |
---|
660 | $i = 1; |
---|
661 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
662 | $tpl->newBlock ("sorted_list"); |
---|
663 | //$host = $host. '.'.$domain; |
---|
664 | $host_url = rawurlencode($host); |
---|
665 | $cluster_url = rawurlencode($clustername); |
---|
666 | |
---|
667 | $textval = ""; |
---|
668 | //printf("host = %s, value = %s", $host, $value); |
---|
669 | //echo "$host: $value, "; |
---|
670 | $val = $metrics[$host][$metricname]; |
---|
671 | $class = "metric"; |
---|
672 | $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
673 | |
---|
674 | if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { |
---|
675 | $textval = date("r", $val[VAL]); |
---|
676 | } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
677 | $textval = "$val[VAL] $val[UNITS]"; |
---|
678 | } else { |
---|
679 | $load_color = load_color($host_load[$host]); |
---|
680 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
681 | $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&x=$max&n=$min&r=job&jr=$jobrange&js=$jobstart"; |
---|
682 | } |
---|
683 | if ($textval) { |
---|
684 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
685 | } else { |
---|
686 | $cell="<td><a href=$host_link>". "<img src=\"../../graph.php?$graphargs\" ". "alt=\"$host\" height=112 width=225 border=0></a></td>"; |
---|
687 | } |
---|
688 | |
---|
689 | $tpl->assign("metric_image", $cell); |
---|
690 | if (! ($i++ % $hostcols) ) |
---|
691 | $tpl->assign ("br", "</tr><tr>"); |
---|
692 | } |
---|
693 | } |
---|
694 | //--- |
---|
695 | } |
---|
696 | } |
---|
697 | ?> |
---|