source: trunk/web/addons/job_monarch/overview.php @ 302

Last change on this file since 302 was 302, checked in by bastiaans, 16 years ago

web/addons/job_monarch/overview.php:

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