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

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

job_monarch/overview.php:

job_monarch/libtoga.php:

job_monarch/js/jobgrid.js:

job_monarch/jobstore.php:

  • use session

job_monarch/templates/header.tpl:

job_monarch/image.php:

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 530 2008-07-02 11:17:49Z ramonb $
23 */
24
25global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh;
26global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter;
27global $longtitle, $title, $range;
28
29$tpl->assign( "clustername", $clustername );
30
31if( $JOB_ARCHIVE )
32{
33        $tpl->assign( "cluster_url", rawurlencode($clustername) );
34}
35
36$ds             = new DataSource();
37$myxml_data     = $ds->getData();
38
39$data_gatherer  = new DataGatherer( $clustername );
40$data_gatherer->parseXML( $myxml_data );
41
42$heartbeat      = $data_gatherer->getHeartbeat();
43$jobs           = $data_gatherer->getJobs();
44$gnodes         = $data_gatherer->getNodes();
45$cpus           = $data_gatherer->getCpus();
46$use_fqdn       = $data_gatherer->getUsingFQDN();
47
48include("./lib/pchart/pData.class");
49include("./lib/pchart/pChart.class");
50
51function setupFilterSettings() 
52{
53
54        global $tpl, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data, $filterorder;
55
56        $filter_image_url = "";
57
58        $tpl->gotoBlock( "_ROOT" );
59
60        foreach( $filter as $filtername => $filtervalue ) 
61        {
62                $tpl->assign( "f_".$filtername, $filtervalue );
63
64                $filter_image_url       .= "&$filtername=$filtervalue";
65        }
66
67        session_start();
68
69        unset( $_SESSION["data"] );
70        $_SESSION["data"]       = &$myxml_data;
71
72        $ic                     = new ClusterImage( $myxml_data, $clustername );
73
74        $ic->setBig();
75        $ic->setNoimage();
76        $ic->draw();
77
78        $tpl->assign( "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 .= "</A>";
601
602                $tpl->gotoBlock( "_ROOT" );
603
604                $tpl->assign( "rjqj_graph", $rjqj_str );
605        }
606
607        foreach( $sorted_jobs as $jobid => $sortdec ) 
608        {
609                $report_time    = $jobs[$jobid][reported];
610
611                if( $jobs[$jobid][status] == 'R' )
612                {
613                        $nodes = count( $jobs[$jobid][nodes] );
614                }
615                else if( $jobs[$jobid][status] == 'Q' )
616                {
617                        $nodes = $jobs[$jobid][nodes];
618                }
619
620                $ppn            = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
621                $cpus           = $nodes * $ppn;
622
623                if( $report_time == $heartbeat ) 
624                {
625                        $display_job    = 1;
626
627                        if( $jobs[$jobid][status] == 'R' ) 
628                        {
629                                foreach( $jobs[$jobid][nodes] as $tempnode ) 
630                                {
631                                        $all_used_nodes[] = $tempnode;
632                                }
633                        }
634
635                        $used_cpus += $cpus;
636
637                        if( $jobs[$jobid][status] == 'R' ) 
638                        {
639                                $running_cpus   += $cpus;
640
641                                $running_jobs++;
642
643                                $found_node_job = 0;
644
645                                foreach( $jobs[$jobid][nodes] as $tempnode ) 
646                                {
647                                        $running_name_nodes[] = $tempnode;
648
649                                        if( isset( $hostname ) && $hostname != '' ) 
650                                        {
651                                                //$filter[host] = $hostname;
652
653                                                $domain_len     = 0 - strlen( $jobs[$jobid][domain] );
654                                                $hostnode       = $tempnode;
655
656                                                if( $use_fqdn == 1)
657                                                {
658                                                        if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) 
659                                                        {
660                                                                $hostnode = $hostnode. '.'. $jobs[$jobid][domain];
661                                                        }
662                                                }
663
664                                                if( $hostname == $hostnode ) 
665                                                {
666                                                        $found_node_job = 1;
667                                                        $display_job = 1;
668                                                } 
669                                                else if( !$found_node_job ) 
670                                                {
671                                                        $display_job = 0;
672                                                }
673                                        }
674                                }
675                        }
676
677                        if( $jobs[$jobid][status] == 'Q' ) 
678                        {
679                                if( isset( $hostname ) && $hostname != '' )
680                                {
681                                        $display_job = 0;
682                                }
683
684                                $queued_cpus    += $cpus;
685                                $queued_nodes   += $nodes;
686
687                                $queued_jobs++;
688                        }
689
690                        foreach( $filter as $filtername=>$filtervalue ) 
691                        {
692                                if( $filtername == 'id' && $jobid != $filtervalue )
693                                {
694                                        $display_job = 0;
695                                }
696                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
697                                {
698                                        $display_job = 0;
699                                }
700                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
701                                {
702                                        $display_job = 0;
703                                }
704                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
705                                {
706                                        $display_job = 0;
707                                }
708                        }
709
710                        if( $display_job ) 
711                        {
712                                $tpl->newBlock( "node" );
713                                $tpl->assign( "clustername", $clustername );
714                                $tpl->assign( "id", $jobid );
715
716                                $last_displayed_job     = $jobid;
717
718                                $tpl->assign( "state", $jobs[$jobid][status] );
719
720                                $fullstate              = '';
721
722                                if( $jobs[$jobid][status] == 'R' ) 
723                                {
724                                        $fullstate      = "Running";
725                                } 
726                                else if( $jobs[$jobid][status] == 'Q' ) 
727                                {
728                                        $fullstate      = "Queued";
729                                }
730
731                                $tpl->assign( "fullstate", $fullstate );
732                               
733                                $tpl->assign( "user", $jobs[$jobid][owner] );
734                                $tpl->assign( "queue", $jobs[$jobid][queue] );
735
736                                $fulljobname            = $jobs[$jobid][name];
737                                $shortjobname           = '';
738
739                                $tpl->assign( "fulljobname", $fulljobname );
740
741                                $fulljobname_fields     = explode( ' ', $fulljobname );
742
743                                $capjobname             = 0;
744
745                                if( strlen( $fulljobname_fields[0] ) > 10 )
746                                {
747                                        $capjobname     = 1;
748                                }
749
750                                if( $capjobname ) 
751                                {
752                                        $tpl->newBlock( "jobname_hint_start" );
753                                        $tpl->gotoBlock( "node" );
754
755                                        $shortjobname   = substr( $fulljobname, 0, 10 ) . '..';
756                                } 
757                                else 
758                                {
759                                        $shortjobname   = $fulljobname;
760                                }
761                               
762                                $tpl->assign( "name", $shortjobname );
763
764                                if( $capjobname ) 
765                                {
766                                        $tpl->newBlock( "jobname_hint_end" );
767                                        $tpl->gotoBlock( "node" );
768                                }
769
770                                $domain                 = $jobs[$jobid][domain];
771
772                                $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
773
774                                if( $COLUMN_REQUESTED_MEMORY ) 
775                                {
776                                        $tpl->newBlock( "column_req_mem" );
777                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
778                                        $tpl->gotoBlock( "node" );
779                                }
780
781
782                                if( $COLUMN_QUEUED ) 
783                                {
784                                        $tpl->newBlock( "column_queued" );
785                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
786                                        $tpl->gotoBlock( "node" );
787                                }
788                                if( $COLUMN_NODES ) 
789                                {
790                                        $tpl->newBlock( "column_nodes" );
791                                        $tpl->gotoBlock( "node" );
792                                }
793
794                                $ppn                    = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
795                                $cpus                   = $nodes * $ppn;
796
797                                $tpl->assign( "nodes", $nodes );
798                                $tpl->assign( "cpus", $cpus );
799
800                                $start_time             = (int) $jobs[$jobid][start_timestamp];
801                                $job_start              = $start_time;
802
803                                $view_cpus              += $cpus;
804
805                                $view_jobs++;
806
807                                if( $jobs[$jobid][status] == 'R' ) 
808                                {
809                                        foreach( $jobs[$jobid][nodes] as $tempnode )
810                                        {
811                                                $view_name_nodes[]      = $tempnode;
812                                        }
813
814                                        if( $COLUMN_NODES ) 
815                                        {
816                                                $tpl->gotoBlock( "column_nodes" );
817
818                                                $mynodehosts            = array();
819
820                                                foreach( $jobs[$jobid][nodes] as $mynode ) 
821                                                {
822                                                        if( $use_fqdn == 1)
823                                                        {
824                                                                $mynode = $mynode.".".$jobs[$jobid][domain];
825                                                        }
826                                                        $myhost_href    = "./?c=".$clustername."&h=".$mynode;
827                                                        $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$mynode."</A>";
828                                                }
829
830                                                $nodes_hostnames        = implode( " ", $mynodehosts );
831
832                                                $tpl->assign( "nodes_hostnames", $nodes_hostnames );
833                                                $tpl->gotoBlock( "node" );
834                                        }
835                                } 
836                                else if( $jobs[$jobid][status] == 'Q' ) 
837                                {
838                                        $view_nodes     += (int) $jobs[$jobid][nodes];
839                                }
840
841                                if( $even ) 
842                                {
843                                        $tpl->assign( "nodeclass", "even" );
844
845                                        $even           = 0;
846                                } 
847                                else 
848                                {
849                                        $tpl->assign( "nodeclass", "odd" );
850
851                                        $even           = 1;
852                                }
853
854                                if( $start_time ) 
855                                {
856                                        $runningtime            = makeTime( $report_time - $start_time );
857                                        //$job_runningtime      = $report_time - $start_time;
858                                        $job_runningtime        = $heartbeat - $start_time;
859
860                                        $tpl->assign( "started", makeDate( $start_time ) );
861                                        $tpl->assign( "runningtime", $runningtime );
862                                }
863                        }
864                }
865        }
866
867        $all_used_nodes         = array_unique( $all_used_nodes );
868        $view_name_nodes        = array_unique( $view_name_nodes );
869        $running_name_nodes     = array_unique( $running_name_nodes );
870
871        $used_nodes             = count( $all_used_nodes );
872        $view_nodes             += count( $view_name_nodes );
873        $running_nodes          += count( $running_name_nodes );
874
875        $total_nodes            = $queued_nodes + $running_nodes;
876        $total_cpus             = $queued_cpus + $running_cpus;
877        $total_jobs             = $queued_jobs + $running_jobs;
878
879        $free_nodes             = $avail_nodes - $running_nodes - $na_nodes;
880        $free_nodes             = ( $free_nodes >= 0 ) ? $free_nodes : 0;
881        $free_cpus              = $avail_cpus - $running_cpus - $na_cpus;
882        $free_cpus              = ( $free_cpus >= 0 ) ? $free_cpus : 0;
883
884        $tpl->assignGlobal( "avail_nodes", $avail_nodes );
885        $tpl->assignGlobal( "avail_cpus", $avail_cpus );
886
887        $tpl->assignGlobal( "queued_nodes", $queued_nodes );
888        $tpl->assignGlobal( "queued_jobs", $queued_jobs );
889        $tpl->assignGlobal( "queued_cpus", $queued_cpus );
890
891        // Only display "Unavailable" in count overview there are any
892        //
893        if( $na_nodes > 0 )
894        {
895                $tpl->newBlock( "na_nodes" );
896
897                $tpl->assignGlobal( "na_nodes", $na_nodes );
898                $tpl->assignGlobal( "na_cpus", $na_cpus );
899
900                $tpl->gotoBlock( "_ROOT" );
901        }
902
903        $tpl->assignGlobal( "total_nodes", $total_nodes );
904        $tpl->assignGlobal( "total_jobs", $total_jobs );
905        $tpl->assignGlobal( "total_cpus", $total_cpus );
906
907        $tpl->assignGlobal( "running_nodes", $running_nodes );
908        $tpl->assignGlobal( "running_jobs", $running_jobs );
909        $tpl->assignGlobal( "running_cpus", $running_cpus );
910
911        $tpl->assignGlobal( "used_nodes", $used_nodes );
912        $tpl->assignGlobal( "used_jobs", $used_jobs );
913        $tpl->assignGlobal( "used_cpus", $used_cpus );
914
915        $tpl->assignGlobal( "free_nodes", $free_nodes );
916        $tpl->assignGlobal( "free_cpus", $free_cpus );
917
918        $tpl->assignGlobal( "view_nodes", $view_nodes );
919        $tpl->assignGlobal( "view_jobs", $view_jobs );
920        $tpl->assignGlobal( "view_cpus", $view_cpus );
921
922        $tpl->assignGlobal( "report_time", makeDate( $heartbeat) );
923
924        if( intval($view_jobs) == 1 and $start_time )
925        {
926                if( $last_displayed_job != null )
927                {
928                        $filter[id] = $last_displayed_job;
929                }
930        }
931
932        //print_r( $metrics );
933
934        global $longtitle, $title;
935
936        $longtitle = "Batch Report :: Powered by Job Monarch!";
937        $title = "Batch Report";
938
939        makeHeader( 'overview', $title, $longtitle );
940
941        setupFilterSettings();
942
943        if( intval($view_jobs) == 1 and $start_time ) 
944        {
945                $tpl->newBlock( "showhosts" );
946
947                # Present a width list
948                $cols_menu      = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
949
950                $hostcols       = ($hc) ? $hc : 4;
951
952                foreach( range( 1, 25 ) as $cols ) 
953                {
954                        $cols_menu      .= "<OPTION VALUE=$cols ";
955
956                        if ($cols == $hostcols)
957                        {
958                                $cols_menu      .= "SELECTED";
959                        }
960                        $cols_menu      .= ">$cols\n";
961                }
962                $cols_menu      .= "</SELECT>\n";
963
964                $tpl->assign( "metric","$metricname $units" );
965                $tpl->assign( "id", $filter[id] );
966
967                # Host columns menu defined in header.php
968                $tpl->assign( "cols_menu", $cols_menu );
969
970                $showhosts      = isset($sh) ? $sh : $default_showhosts;
971
972                $tpl->assign( "checked$showhosts", "checked" );
973
974                if( $showhosts ) 
975                {
976                        if( !isset( $start ) ) 
977                        {
978                                $start  ="jobstart";
979                        }
980                        if( !isset( $stop ) ) 
981                        {
982                                $stop   ="now";
983                        }
984
985                        $sorted_hosts   = array();
986                        $hosts_up       = $jobs[$filter[id]][nodes];
987
988                        //printf( "r %s\n", $job_runningtime );
989
990                        $r              = intval($job_runningtime * 1.2);
991
992                        //$jobrange     = ($job_runningtime < 3600) ? -3600 : -$r ;
993                        $jobrange       = -$r ;
994                        //$jobstart     = $report_time - $job_runningtime;
995                        $jobstart       = $start_time;
996
997                        //printf( "jr %s\n", $jobrange );
998                        //printf( "js %s\n", $jobstart);
999
1000                        if ( $reports[$metricname] )
1001                        {
1002                                $metricval      = "g";
1003                        }
1004                        else
1005                        {
1006                                $metricval      = "m";
1007                        }
1008                               
1009                        foreach ( $hosts_up as $host ) 
1010                        {
1011                                $domain_len             = 0 - strlen( $domain );
1012
1013                                if( $use_fqdn )
1014                                {
1015                                        if( substr( $host, $domain_len ) != $domain ) 
1016                                        {
1017                                                $host           = $host . '.' . $domain;
1018                                        }
1019                                }
1020
1021                                $cpus                   = $metrics[$host]["cpu_num"]["VAL"];
1022
1023                                if ( !$cpus )
1024                                {
1025                                        $cpus           = 1;
1026                                }
1027
1028                                $load_one               = $metrics[$host]["load_one"][VAL];
1029                                $load                   = ((float) $load_one) / $cpus;
1030                                $host_load[$host]       = $load;
1031
1032                                $percent_hosts[load_color($load)] ++;
1033
1034                                if ($metricname=="load_one")
1035                                {
1036                                        $sorted_hosts[$host]    = $load;
1037                                }
1038                                else
1039                                {
1040                                        $sorted_hosts[$host]    = $metrics[$host][$metricname][VAL];
1041                                }
1042                        }
1043
1044                        switch ( $sort ) 
1045                        {
1046                                case "descending":
1047                                        arsort( $sorted_hosts );
1048                                        break;
1049
1050                                case "by hostname":
1051                                        ksort( $sorted_hosts );
1052                                        break;
1053
1054                                case "ascending":
1055                                        asort( $sorted_hosts );
1056                                        break;
1057
1058                                default:
1059                                        break;
1060                        }
1061
1062                        // First pass to find the max value in all graphs for this
1063                        // metric. The $start,$end variables comes from get_context.php,
1064                        // included in index.php.
1065                        //
1066                        list($min, $max) = find_limits($sorted_hosts, $metricname);
1067
1068                        // Second pass to output the graphs or metrics.
1069                        $i = 1;
1070
1071                        foreach ( $sorted_hosts as $host=>$value  ) 
1072                        {
1073                                $tpl->newBlock( "sorted_list" );
1074
1075                                $host_url       = rawurlencode( $host );
1076                                $cluster_url    = rawurlencode( $clustername );
1077
1078                                $textval        = "";
1079
1080                                $val            = $metrics[$host][$metricname];
1081                                $class          = "metric";
1082                                $host_link      = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
1083
1084                                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
1085                                {
1086                                        $textval        = date( "r", $val["VAL"] );
1087                                }
1088                                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
1089                                {
1090                                        $textval        = $val["VAL"] . " " . $val["UNITS"];
1091                                }
1092                                else
1093                                {
1094                                        $load_color     = load_color($host_load[$host]);
1095                                        $graphargs      = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
1096                                        $graphargs      .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" . "&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
1097                                        if( $max > 0 )
1098                                        {
1099                                                $graphargs      .= "&x=$max&n=$min";
1100                                        }
1101                                }
1102                                if ($textval)
1103                                {
1104                                        $cell   = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
1105                                } else {
1106                                        $cell   = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>";
1107                                }
1108
1109                                $tpl->assign( "metric_image", $cell );
1110
1111                                if(! ($i++ % $hostcols) )
1112                                {
1113                                         $tpl->assign( "br", "</tr><tr>" );
1114                                }
1115                        }
1116                }
1117        }
1118}
1119?>
Note: See TracBrowser for help on using the repository browser.