source: trunk/web2/addons/job_monarch/overview.php @ 534

Last change on this file since 534 was 534, checked in by ramonb, 16 years ago

job_monarch/jobstore.php:

  • times and dates are now pretty and make sense

job_monarch/js/jobgrid.js:

  • changed column size

job_monarch/js/mainscript.js:

  • removed bogus example

job_monarch/overview.php,
job_monarch/libtoga.php:

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