source: trunk/web2/addons/job_monarch/overview.php.orig @ 573

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

web2:

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