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