source: branches/0.4/web/addons/job_monarch/overview.php @ 738

Last change on this file since 738 was 738, checked in by ramonb, 11 years ago

libtoga.php,
index.php:

  • fix some weird issue range being overwritten by Ganglia

overview.php:

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