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

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

job_monarch/chart.php:

  • new pChart pie

job_monarch/overview.php:

  • use pChart pie

job_monarch/index.php:

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