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

Last change on this file since 417 was 416, checked in by bastiaans, 17 years ago

web/addons/job_monarch/overview.php:

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