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

Last change on this file since 624 was 617, checked in by ramonb, 15 years ago

job_monarch/chart.php,
job_monarch/overview.php:

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