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

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

overview.php:

  • remove domain name adding, this is now handled properly by libtoga
  • Property svn:keywords set to Id
File size: 23.3 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 462 2008-02-07 08:12:07Z 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, $filterorder;
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        $empty_cpus             = ( $empty_cpus >= 0 ) ? $empy_cpus : 0;
270        $used_cpus              = $nr_cpus - $empty_cpus;
271
272        $empty_percentage       = ($empty_cpus / $nr_cpus) * 100;
273
274        $qcolors                = array();
275        $color                  = randomColor( $qcolors );
276        $qcolors[]              = $color;
277        $pie_args               .= "&free=$empty_percentage,$color";
278
279        if( isset( $piefilter ) )
280        {
281                $filterpie = array();
282        }
283
284        foreach( $nodes as $node )
285        {
286                $node_jobs      = $node->getJobs();
287                $nr_node_jobs   = count( $node_jobs );
288                $myhost         = $node->getHostname();
289                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
290
291                foreach( $node_jobs as $myjob )
292                {
293                        $job_cpu                = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
294
295                        // Determine the weight of this job
296                        // - what percentage of the cpus is in use by this job
297                        //
298                        $job_weight[$myjob]     = ( $job_cpu / $nr_cpus );
299
300
301                        if( isset( $piefilter ) ) {
302
303                                $countjob = 1;
304
305                                if( $piefilter == 'id' )
306                                {
307                                        if( $myjob != $filter[$piefilter] )
308                                        {
309                                                $countjob = 0;
310                                        }
311                                }
312                                else if( $piefilter == 'user' )
313                                {
314                                        if( $jobs[$myjob][owner] != $filter[$piefilter] )
315                                        {
316                                                $countjob = 0;
317                                        }
318                                }
319                                else
320                                {
321                                        if( $jobs[$myjob][$piefilter] != $filter[$piefilter] )
322                                        {
323                                                $countjob = 0;
324                                        }
325                                }
326
327                                if( $countjob )
328                                {
329
330                                        if( !isset( $filterpie[$filter[$piefilter]] ) )
331                                        {
332                                                $filterpie[$filter[$piefilter]] = $job_weight[$myjob];
333                                        }
334                                        else
335                                        {
336
337                                                $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob];
338                                        }
339                                }
340                                else
341                                {
342                                        if( !isset( $filterpie["other"] ) )
343                                        {
344                                                $filterpie["other"] = $job_weight[$myjob];
345                                        }
346                                        else
347                                        {
348                                                $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob];
349                                        }
350
351                                }
352                               
353                        }
354                        else
355                        {
356
357                                $qname          = $jobs[$myjob][queue];
358
359                                if( !isset( $queues[$qname] ) )
360                                {
361                                        $queues[$qname] = $job_weight[$myjob];
362                                }
363                                else
364                                {
365                                        $queues[$qname] = $queues[$qname] + $job_weight[$myjob];
366                                }
367                        }
368                }
369        }
370
371        if( isset( $piefilter ) )
372        {
373                $graphvals = $filterpie;
374        }
375        else
376        {
377                $graphvals = $queues;
378        }
379
380        foreach( $graphvals as $name => $totalweight) 
381        {
382                $percentage     = ( $totalweight * 100 );
383               
384                $color          = randomColor( $qcolors );
385                $qcolors[]      = $color;
386                $pie_args       .= "&$name=$percentage,$color";
387        }
388        $pie = "../../pie.php?$pie_args";
389
390        return $pie;
391}
392
393
394function sortJobs( $jobs, $sortby, $sortorder ) 
395{
396        $sorted = array();
397
398        $cmp    = create_function( '$a, $b', 
399                "global \$sortby, \$sortorder;".
400
401                "if( \$a == \$b ) return 0;".
402
403                "if (\$sortorder==\"desc\")".
404                        "return ( \$a < \$b ) ? 1 : -1;".
405                "else if (\$sortorder==\"asc\")".
406                        "return ( \$a > \$b ) ? 1 : -1;" );
407
408        if( isset( $jobs ) && count( $jobs ) > 0 ) 
409        {
410                foreach( $jobs as $jobid => $jobattrs ) 
411                {
412                                $state          = $jobattrs[status];
413                                $user           = $jobattrs[owner];
414                                $queue          = $jobattrs[queue];
415                                $name           = $jobattrs[name];
416                                $req_cpu        = $jobattrs[requested_time];
417                                $req_memory     = $jobattrs[requested_memory];
418
419                                if( $state == 'R' )
420                                {
421                                        $nodes = count( $jobattrs[nodes] );
422                                }
423                                else
424                                {
425                                        $nodes = $jobattrs[nodes];
426                                }
427
428                                $ppn            = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
429                                $cpus           = $nodes * $ppn;
430                                $queued_time    = (int) $jobattrs[queued_timestamp];
431                                $start_time     = (int) $jobattrs[start_timestamp];
432                                $runningtime    = $report_time - $start_time;
433
434                                switch( $sortby ) 
435                                {
436                                        case "id":
437                                                $sorted[$jobid] = $jobid;
438                                                break;
439
440                                        case "state":
441                                                $sorted[$jobid] = $state;
442                                                break;
443
444                                        case "user":
445                                                $sorted[$jobid] = $user;
446                                                break;
447
448                                        case "queue":
449                                                $sorted[$jobid] = $queue;
450                                                break;
451
452                                        case "name":
453                                                $sorted[$jobid] = $name;
454                                                break;
455
456                                        case "req_cpu":
457                                                $sorted[$jobid] = timeToEpoch( $req_cpu );
458                                                break;
459
460                                        case "req_mem":
461                                                $sorted[$jobid] = $req_memory;
462                                                break;
463
464                                        case "nodes":
465                                                $sorted[$jobid] = $nodes;
466                                                break;
467
468                                        case "cpus":
469                                                $sorted[$jobid] = $cpus;
470                                                break;
471
472                                        case "queued":
473                                                $sorted[$jobid] = $queued_time;
474                                                break;
475
476                                        case "start":
477                                                $sorted[$jobid] = $start_time;
478                                                break;
479
480                                        case "runningtime":
481                                                $sorted[$jobid] = $runningtime;
482                                                break;
483
484                                        default:
485                                                break;
486                                }
487                }
488        }
489
490        if( $sortorder == "asc" )
491        {
492                arsort( $sorted );
493        }
494        else if( $sortorder == "desc" )
495        {
496                asort( $sorted );
497        }
498
499        return $sorted;
500}
501
502function makeOverview() 
503{
504        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
505        global $sortorder, $sortby, $filter, $sh, $hc, $m, $range;
506        global $cluster_url, $get_metric_string, $host_url, $metrics;
507        global $start, $end, $reports, $gnodes, $default_showhosts;
508        global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname;
509        global $cluster;
510
511        $metricname             = $m;
512
513        $tpl->assign("sortorder", $sortorder );
514        $tpl->assign("sortby", $sortby );
515
516        $sorted_jobs            = sortJobs( $jobs, $sortby, $sortorder );
517
518        $even                   = 1;
519
520        $used_jobs              = 0;
521        $used_cpus              = 0;
522        $used_nodes             = 0;
523
524        $queued_jobs            = 0;
525        $queued_nodes           = 0;
526        $queued_cpus            = 0;
527
528        $total_nodes            = 0;
529        $total_cpus             = 0;
530        $total_jobs             = 0;
531
532        $all_used_nodes         = array();
533        $total_used_nodes       = array();
534
535        $running_name_nodes     = array();
536
537        $running_nodes          = 0;
538        $running_jobs           = 0;
539        $running_cpus           = 0;
540
541        $avail_nodes            = count( $gnodes );
542        $avail_cpus             = cluster_sum("cpu_num", $metrics);
543
544        $view_cpus              = 0;
545        $view_jobs              = 0;
546        $view_nodes             = 0;
547
548        $all_nodes              = 0;
549        $all_jobs               = 0;
550        $all_cpus               = 0;
551
552        $view_name_nodes        = array();
553
554        if( $COLUMN_REQUESTED_MEMORY ) 
555        {
556                $tpl->newBlock( "column_header_req_mem" );
557        }
558
559        if( $COLUMN_NODES ) 
560        {
561                $tpl->newBlock( "column_header_nodes" );
562        }
563
564        if( $COLUMN_QUEUED ) 
565        {
566                $tpl->newBlock( "column_header_queued" );
567        }
568
569        $last_displayed_job     = null;
570
571        $rjqj_host              = null;
572
573        foreach( $metrics as $bhost => $bmetric )
574        {
575                foreach( $bmetric as $mname => $mval )
576                {
577                        if( ( $mname == 'MONARCH-RJ' ) || ($mname == 'MONARCH-QJ') )
578                        {
579                                $rjqj_host      = $bhost;
580                        }
581                }
582        }
583
584        if( $rjqj_host != null )
585        {
586
587                $rjqj_str =  "<IMG SRC=\"./graph.php?z=small&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">";
588
589                $tpl->gotoBlock( "_ROOT" );
590
591                $tpl->assign( "rjqj_graph", $rjqj_str );
592        }
593
594        foreach( $sorted_jobs as $jobid => $sortdec ) 
595        {
596                $report_time    = $jobs[$jobid][reported];
597
598                if( $jobs[$jobid][status] == 'R' )
599                {
600                        $nodes = count( $jobs[$jobid][nodes] );
601                }
602                else if( $jobs[$jobid][status] == 'Q' )
603                {
604                        $nodes = $jobs[$jobid][nodes];
605                }
606
607                $ppn            = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
608                $cpus           = $nodes * $ppn;
609
610                if( $report_time == $heartbeat ) 
611                {
612                        $display_job    = 1;
613
614                        if( $jobs[$jobid][status] == 'R' ) 
615                        {
616                                foreach( $jobs[$jobid][nodes] as $tempnode ) 
617                                {
618                                        $all_used_nodes[] = $tempnode;
619                                }
620                        }
621
622                        $used_cpus += $cpus;
623
624                        if( $jobs[$jobid][status] == 'R' ) 
625                        {
626                                $running_cpus   += $cpus;
627
628                                $running_jobs++;
629
630                                $found_node_job = 0;
631
632                                foreach( $jobs[$jobid][nodes] as $tempnode ) 
633                                {
634                                        $running_name_nodes[] = $tempnode;
635
636                                        if( isset( $hostname ) && $hostname != '' ) 
637                                        {
638                                                //$filter[host] = $hostname;
639
640                                                $domain_len     = 0 - strlen( $jobs[$jobid][domain] );
641                                                $hostnode       = $tempnode;
642
643                                                //if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] )
644                                                //{
645                                                //      $hostnode = $hostnode. '.'. $jobs[$jobid][domain];
646                                                //}
647
648                                                if( $hostname == $hostnode ) 
649                                                {
650                                                        $found_node_job = 1;
651                                                        $display_job = 1;
652                                                } 
653                                                else if( !$found_node_job ) 
654                                                {
655                                                        $display_job = 0;
656                                                }
657                                        }
658                                }
659                        }
660
661                        if( $jobs[$jobid][status] == 'Q' ) 
662                        {
663                                if( isset( $hostname ) && $hostname != '' )
664                                {
665                                        $display_job = 0;
666                                }
667
668                                $queued_cpus    += $cpus;
669                                $queued_nodes   += $nodes;
670
671                                $queued_jobs++;
672                        }
673
674                        foreach( $filter as $filtername=>$filtervalue ) 
675                        {
676                                if( $filtername == 'id' && $jobid != $filtervalue )
677                                {
678                                        $display_job = 0;
679                                }
680                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
681                                {
682                                        $display_job = 0;
683                                }
684                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
685                                {
686                                        $display_job = 0;
687                                }
688                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
689                                {
690                                        $display_job = 0;
691                                }
692                        }
693
694                        if( $display_job ) 
695                        {
696                                $tpl->newBlock( "node" );
697                                $tpl->assign( "clustername", $clustername );
698                                $tpl->assign( "id", $jobid );
699
700                                $last_displayed_job     = $jobid;
701
702                                $tpl->assign( "state", $jobs[$jobid][status] );
703
704                                $fullstate              = '';
705
706                                if( $jobs[$jobid][status] == 'R' ) 
707                                {
708                                        $fullstate      = "Running";
709                                } 
710                                else if( $jobs[$jobid][status] == 'Q' ) 
711                                {
712                                        $fullstate      = "Queued";
713                                }
714
715                                $tpl->assign( "fullstate", $fullstate );
716                               
717                                $tpl->assign( "user", $jobs[$jobid][owner] );
718                                $tpl->assign( "queue", $jobs[$jobid][queue] );
719
720                                $fulljobname            = $jobs[$jobid][name];
721                                $shortjobname           = '';
722
723                                $tpl->assign( "fulljobname", $fulljobname );
724
725                                $fulljobname_fields     = explode( ' ', $fulljobname );
726
727                                $capjobname             = 0;
728
729                                if( strlen( $fulljobname_fields[0] ) > 10 )
730                                {
731                                        $capjobname     = 1;
732                                }
733
734                                if( $capjobname ) 
735                                {
736                                        $tpl->newBlock( "jobname_hint_start" );
737                                        $tpl->gotoBlock( "node" );
738
739                                        $shortjobname   = substr( $fulljobname, 0, 10 ) . '..';
740                                } 
741                                else 
742                                {
743                                        $shortjobname   = $fulljobname;
744                                }
745                               
746                                $tpl->assign( "name", $shortjobname );
747
748                                if( $capjobname ) 
749                                {
750                                        $tpl->newBlock( "jobname_hint_end" );
751                                        $tpl->gotoBlock( "node" );
752                                }
753
754                                $domain                 = $jobs[$jobid][domain];
755
756                                $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
757
758                                if( $COLUMN_REQUESTED_MEMORY ) 
759                                {
760                                        $tpl->newBlock( "column_req_mem" );
761                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
762                                        $tpl->gotoBlock( "node" );
763                                }
764
765
766                                if( $COLUMN_QUEUED ) 
767                                {
768                                        $tpl->newBlock( "column_queued" );
769                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
770                                        $tpl->gotoBlock( "node" );
771                                }
772                                if( $COLUMN_NODES ) 
773                                {
774                                        $tpl->newBlock( "column_nodes" );
775                                        $tpl->gotoBlock( "node" );
776                                }
777
778                                $ppn                    = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
779                                $cpus                   = $nodes * $ppn;
780
781                                $tpl->assign( "nodes", $nodes );
782                                $tpl->assign( "cpus", $cpus );
783
784                                $start_time             = (int) $jobs[$jobid][start_timestamp];
785                                $job_start              = $start_time;
786
787                                $view_cpus              += $cpus;
788
789                                $view_jobs++;
790
791                                if( $jobs[$jobid][status] == 'R' ) 
792                                {
793                                        foreach( $jobs[$jobid][nodes] as $tempnode )
794                                        {
795                                                $view_name_nodes[]      = $tempnode;
796                                        }
797
798                                        if( $COLUMN_NODES ) 
799                                        {
800                                                $tpl->gotoBlock( "column_nodes" );
801
802                                                $mynodehosts            = array();
803
804                                                foreach( $jobs[$jobid][nodes] as $mynode ) 
805                                                {
806                                                        //$myhost_href  = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain];
807                                                        $myhost_href    = "./?c=".$clustername."&h=".$mynode;
808                                                        $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$mynode."</A>";
809                                                }
810
811                                                $nodes_hostnames        = implode( " ", $mynodehosts );
812
813                                                $tpl->assign( "nodes_hostnames", $nodes_hostnames );
814                                                $tpl->gotoBlock( "node" );
815                                        }
816                                } 
817                                else if( $jobs[$jobid][status] == 'Q' ) 
818                                {
819                                        $view_nodes     += (int) $jobs[$jobid][nodes];
820                                }
821
822                                if( $even ) 
823                                {
824                                        $tpl->assign( "nodeclass", "even" );
825
826                                        $even           = 0;
827                                } 
828                                else 
829                                {
830                                        $tpl->assign( "nodeclass", "odd" );
831
832                                        $even           = 1;
833                                }
834
835                                if( $start_time ) 
836                                {
837                                        $runningtime            = makeTime( $report_time - $start_time );
838                                        //$job_runningtime      = $report_time - $start_time;
839                                        $job_runningtime        = $heartbeat - $start_time;
840
841                                        $tpl->assign( "started", makeDate( $start_time ) );
842                                        $tpl->assign( "runningtime", $runningtime );
843                                }
844                        }
845                }
846        }
847
848        $all_used_nodes         = array_unique( $all_used_nodes );
849        $view_name_nodes        = array_unique( $view_name_nodes );
850        $running_name_nodes     = array_unique( $running_name_nodes );
851
852        $used_nodes             = count( $all_used_nodes );
853        $view_nodes             += count( $view_name_nodes );
854        $running_nodes          += count( $running_name_nodes );
855
856        $total_nodes            = $queued_nodes + $running_nodes;
857        $total_cpus             = $queued_cpus + $running_cpus;
858        $total_jobs             = $queued_jobs + $running_jobs;
859
860        $free_nodes             = $avail_nodes - $running_nodes;
861        $free_nodes             = ( $free_nodes >= 0 ) ? $free_nodes : 0;
862        $free_cpus              = $avail_cpus - $running_cpus;
863        $free_cpus              = ( $free_cpus >= 0 ) ? $free_cpus : 0;
864
865        $tpl->assignGlobal( "avail_nodes", $avail_nodes );
866        $tpl->assignGlobal( "avail_cpus", $avail_cpus );
867
868        $tpl->assignGlobal( "queued_nodes", $queued_nodes );
869        $tpl->assignGlobal( "queued_jobs", $queued_jobs );
870        $tpl->assignGlobal( "queued_cpus", $queued_cpus );
871
872        $tpl->assignGlobal( "total_nodes", $total_nodes );
873        $tpl->assignGlobal( "total_jobs", $total_jobs );
874        $tpl->assignGlobal( "total_cpus", $total_cpus );
875
876        $tpl->assignGlobal( "running_nodes", $running_nodes );
877        $tpl->assignGlobal( "running_jobs", $running_jobs );
878        $tpl->assignGlobal( "running_cpus", $running_cpus );
879
880        $tpl->assignGlobal( "used_nodes", $used_nodes );
881        $tpl->assignGlobal( "used_jobs", $used_jobs );
882        $tpl->assignGlobal( "used_cpus", $used_cpus );
883
884        $tpl->assignGlobal( "free_nodes", $free_nodes );
885        $tpl->assignGlobal( "free_cpus", $free_cpus );
886
887        $tpl->assignGlobal( "view_nodes", $view_nodes );
888        $tpl->assignGlobal( "view_jobs", $view_jobs );
889        $tpl->assignGlobal( "view_cpus", $view_cpus );
890
891        $tpl->assignGlobal( "report_time", makeDate( $heartbeat) );
892
893        if( intval($view_jobs) == 1 and $start_time )
894        {
895                if( $last_displayed_job != null )
896                {
897                        $filter[id] = $last_displayed_job;
898                }
899        }
900
901        //print_r( $metrics );
902
903        global $longtitle, $title;
904
905        $longtitle = "Batch Report :: Powered by Job Monarch!";
906        $title = "Batch Report";
907
908        makeHeader( 'overview', $title, $longtitle );
909
910        setupFilterSettings();
911
912        if( intval($view_jobs) == 1 and $start_time ) 
913        {
914                $tpl->newBlock( "showhosts" );
915
916                # Present a width list
917                $cols_menu      = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
918
919                $hostcols       = ($hc) ? $hc : 4;
920
921                foreach( range( 1, 25 ) as $cols ) 
922                {
923                        $cols_menu      .= "<OPTION VALUE=$cols ";
924
925                        if ($cols == $hostcols)
926                        {
927                                $cols_menu      .= "SELECTED";
928                        }
929                        $cols_menu      .= ">$cols\n";
930                }
931                $cols_menu      .= "</SELECT>\n";
932
933                $tpl->assign( "metric","$metricname $units" );
934                $tpl->assign( "id", $filter[id] );
935
936                # Host columns menu defined in header.php
937                $tpl->assign( "cols_menu", $cols_menu );
938
939                $showhosts      = isset($sh) ? $sh : $default_showhosts;
940
941                $tpl->assign( "checked$showhosts", "checked" );
942
943                if( $showhosts ) 
944                {
945                        if( !isset( $start ) ) 
946                        {
947                                $start  ="jobstart";
948                        }
949                        if( !isset( $stop ) ) 
950                        {
951                                $stop   ="now";
952                        }
953
954                        $sorted_hosts   = array();
955                        $hosts_up       = $jobs[$filter[id]][nodes];
956
957                        //printf( "r %s\n", $job_runningtime );
958
959                        $r              = intval($job_runningtime * 1.2);
960
961                        //$jobrange     = ($job_runningtime < 3600) ? -3600 : -$r ;
962                        $jobrange       = -$r ;
963                        //$jobstart     = $report_time - $job_runningtime;
964                        $jobstart       = $start_time;
965
966                        //printf( "jr %s\n", $jobrange );
967                        //printf( "js %s\n", $jobstart);
968
969                        if ( $reports[$metricname] )
970                        {
971                                $metricval      = "g";
972                        }
973                        else
974                        {
975                                $metricval      = "m";
976                        }
977                               
978                        foreach ( $hosts_up as $host ) 
979                        {
980                                //$domain_len           = 0 - strlen( $domain );
981
982                                //if( substr( $host, $domain_len ) != $domain )
983                                //{
984                                //      $host           = $host . '.' . $domain;
985                                //}
986
987                                $cpus                   = $metrics[$host]["cpu_num"]["VAL"];
988
989                                if ( !$cpus )
990                                {
991                                        $cpus           = 1;
992                                }
993
994                                $load_one               = $metrics[$host]["load_one"][VAL];
995                                $load                   = ((float) $load_one) / $cpus;
996                                $host_load[$host]       = $load;
997
998                                $percent_hosts[load_color($load)] ++;
999
1000                                if ($metricname=="load_one")
1001                                {
1002                                        $sorted_hosts[$host]    = $load;
1003                                }
1004                                else
1005                                {
1006                                        $sorted_hosts[$host]    = $metrics[$host][$metricname][VAL];
1007                                }
1008                        }
1009                        switch ( $sort ) 
1010                        {
1011                                case "descending":
1012                                        arsort( $sorted_hosts );
1013                                        break;
1014
1015                                case "by hostname":
1016                                        ksort( $sorted_hosts );
1017                                        break;
1018
1019                                case "ascending":
1020                                        asort( $sorted_hosts );
1021                                        break;
1022
1023                                default:
1024                                        break;
1025                        }
1026
1027                        // First pass to find the max value in all graphs for this
1028                        // metric. The $start,$end variables comes from get_context.php,
1029                        // included in index.php.
1030                        //
1031                        list($min, $max) = find_limits($sorted_hosts, $metricname);
1032
1033                        // Second pass to output the graphs or metrics.
1034                        $i = 1;
1035
1036                        foreach ( $sorted_hosts as $host=>$value  ) 
1037                        {
1038                                $tpl->newBlock( "sorted_list" );
1039
1040                                $host_url       = rawurlencode( $host );
1041                                $cluster_url    = rawurlencode( $clustername );
1042
1043                                $textval        = "";
1044
1045                                $val            = $metrics[$host][$metricname];
1046                                $class          = "metric";
1047                                $host_link      = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
1048
1049                                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
1050                                {
1051                                        $textval        = date( "r", $val["VAL"] );
1052                                }
1053                                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
1054                                {
1055                                        $textval        = $val["VAL"] . " " . $val["UNITS"];
1056                                }
1057                                else
1058                                {
1059                                        $load_color     = load_color($host_load[$host]);
1060                                        $graphargs      = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
1061                                        $graphargs      .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" . "&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
1062                                        if( $max > 0 )
1063                                        {
1064                                                $graphargs      .= "&x=$max&n=$min";
1065                                        }
1066                                }
1067                                if ($textval)
1068                                {
1069                                        $cell   = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
1070                                } else {
1071                                        $cell   = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>";
1072                                }
1073
1074                                $tpl->assign( "metric_image", $cell );
1075
1076                                if(! ($i++ % $hostcols) )
1077                                {
1078                                         $tpl->assign( "br", "</tr><tr>" );
1079                                }
1080                        }
1081                }
1082        }
1083}
1084?>
Note: See TracBrowser for help on using the repository browser.