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

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

templates/footer.tpl:

  • changed URL for rrdtool

graph.php,
overview.php,
libtoga.php:

  • changed seperator to _

libtoga.php:

  • changed job-id-incr to job_incr_id
  • Property svn:keywords set to Id
File size: 32.0 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 726 2013-03-22 12:45:32Z 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
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( $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)."&j_view=big-clusterimage".$filter_image_url );
76
77    $tpl->newBlock( "node_clustermap" );
78    $tpl->assign( "node_area_map", $ic->getImagemapArea() );
79    $tpl->gotoBlock( "_ROOT" );
80
81    $tpl->assign( "order", $filterorder );
82
83    if( array_key_exists( "id", $filter ) ) 
84    {
85        $piefilter = 'id';
86    } 
87    else if( array_key_exists( "owner", $filter ) ) 
88    {
89        $piefilter = 'owner';
90    } 
91    else if( array_key_exists( "queue", $filter ) ) 
92    {
93        $piefilter = 'queue';
94    }
95
96    $pie    = drawPie();
97
98    $tpl->assign("pie", $pie );
99}
100
101function timeToEpoch( $time ) 
102{
103    $time_fields    = explode( ':', $time );
104
105    if( count( $time_fields ) == 3 ) 
106    {
107        $hours        = $time_fields[0];
108        $minutes    = $time_fields[1];
109        $seconds    = $time_fields[2];
110
111    } 
112    else if( count( $time_fields ) == 2 ) 
113    {
114        $hours         = 0;
115        $minutes     = $time_fields[0];
116        $seconds     = $time_fields[1];
117
118    } 
119    else if( count( $time_fields ) == 1 ) 
120    {
121        $hours         = 0;
122        $minutes     = 0;
123        $seconds     = $time_fields[0];
124    }
125
126    $myepoch     = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
127
128    return $myepoch;
129}
130
131function colorRed( $color ) 
132{
133    return substr( $color, 0, 2 );
134}
135
136function colorGreen( $color ) 
137{
138    return substr( $color, 2, 2 );
139}
140
141function colorBlue( $color ) 
142{
143    return substr( $color, 4, 2 );
144}
145
146function colorDiffer( $first, $second ) 
147{
148    // Make sure these two colors differ atleast 50 R/G/B
149    $min_diff = 50;
150
151    $c1r     = hexDec( colorRed( $first ) );
152    $c1g     = hexDec( colorGreen( $first ) );
153    $c1b     = hexDec( colorBlue( $first ) );
154
155    $c2r     = hexDec( colorRed( $second ) );
156    $c2g     = hexDec( colorGreen( $second ) );
157    $c2b     = hexDec( colorBlue( $second ) );
158
159    $rdiff     = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
160    $gdiff     = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
161    $bdiff     = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
162
163    if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) 
164    {
165        return TRUE;
166
167    } 
168    else 
169    {
170        return FALSE;
171    }
172}
173
174function randomColor( $known_colors ) 
175{
176    // White (000000) would be invisible
177    $start        = "004E00";
178   
179    $start_red    = colorRed( $start );
180    $start_green    = colorGreen( $start );
181    $start_blue    = colorBlue( $start );
182   
183    $end        = "FFFFFF";
184
185    $end_red    = colorRed( $end );
186    $end_green    = colorGreen( $end );
187    $end_blue    = colorBlue( $end );
188
189    $change_color     = TRUE;
190
191    while( $change_color ) 
192    {
193        $change_color    = FALSE;
194
195        $new_red     = rand( hexDec( $start_red ), hexDec( $end_red ) );
196        $new_green     = rand( hexDec( $start_green ), hexDec( $end_green ) );
197        $new_blue     = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
198
199        $new         = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
200
201        foreach( $known_colors as $old )
202        {
203            if( !colorDiffer( $new, $old ) )
204            {
205                 $change_color = TRUE;
206            }
207        }
208    }
209
210    // Whoa! Actually found a good color ;)
211    return $new;
212}
213
214// Code these some day
215function drawJobPie() { }
216
217function drawUserPie() { }
218
219function drawQueuePie() { }
220
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
511    $tpl->assign("sortorder", $sortorder );
512    $tpl->assign("sortby", $sortby );
513
514    $sorted_jobs         = sortJobs( $jobs, $sortby, $sortorder );
515
516    $even             = 1;
517
518    $used_jobs         = 0;
519    $used_cpus         = 0;
520    $used_nodes         = 0;
521
522    $queued_jobs         = 0;
523    $queued_nodes         = 0;
524    $queued_cpus         = 0;
525
526    $total_nodes         = 0;
527    $total_cpus         = 0;
528    $total_jobs         = 0;
529
530    $all_used_nodes     = array();
531    $total_used_nodes     = array();
532
533    $running_name_nodes     = array();
534
535    $running_nodes         = 0;
536    $running_jobs         = 0;
537    $running_cpus         = 0;
538
539    $avail_nodes         = count( $gnodes );
540    $avail_cpus         = cluster_sum("cpu_num", $metrics);
541
542    $view_cpus         = 0;
543    $view_jobs         = 0;
544    $view_nodes         = 0;
545
546    $all_nodes         = 0;
547    $all_jobs         = 0;
548    $all_cpus         = 0;
549
550    $view_name_nodes     = array();
551
552    // Is the "requested memory" column enabled in the config
553    //
554    if( $COLUMN_REQUESTED_MEMORY ) 
555    {
556        $tpl->newBlock( "column_header_req_mem" );
557    }
558
559    // Is the "nodes hostnames" column enabled in the config
560    //
561    if( $COLUMN_NODES ) 
562    {
563        $tpl->newBlock( "column_header_nodes" );
564    }
565
566    // Is the "queued time" column enabled in the config
567    //
568    if( $COLUMN_QUEUED ) 
569    {
570        $tpl->newBlock( "column_header_queued" );
571    }
572
573    $last_displayed_job     = null;
574
575    $rjqj_host        = null;
576
577    $na_nodes        = 0;
578    $na_cpus        = 0;
579
580    foreach( $metrics as $bhost => $bmetric )
581    {
582        foreach( $bmetric as $mname => $mval )
583        {
584            if( ( $mname == 'zplugin_monarch_rj' ) || ($mname == 'zplugin_monarch_qj') )
585            {
586                $rjqj_host      = $bhost;
587            }
588        }
589    }
590
591    foreach( $gnodes as $ghost => $gnode )
592    {
593        if( $gnode->isDown() || $gnode->isOffline() )
594        {
595            $na_nodes    += 1;
596            $na_cpus    += $metrics[$ghost]['cpu_num']['VAL'];
597        }
598    }
599
600    // Running / queued amount jobs graph
601    //
602    if( $rjqj_host != null )
603    {
604
605        $rjqj_str  = "<A HREF=\"./graph.php?z=large&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">";
606        $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php?z=small&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">";
607        $rjqj_str .= "</A>";
608
609        $tpl->gotoBlock( "_ROOT" );
610
611        $tpl->assign( "rjqj_graph", $rjqj_str );
612    }
613
614    foreach( $sorted_jobs as $jobid => $sortdec ) 
615    {
616        $report_time     = $jobs[$jobid]['reported'];
617
618        if( $jobs[$jobid]['status'] == 'R' )
619        {
620            $nodes = count( $jobs[$jobid]['nodes'] );
621        }
622        else if( $jobs[$jobid]['status'] == 'Q' )
623        {
624            $nodes = $jobs[$jobid]['nodes'];
625        }
626
627        $ppn         = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
628        $cpus         = $nodes * $ppn;
629
630        if( $report_time == $heartbeat ) 
631        {
632            $display_job    = 1;
633
634            if( $jobs[$jobid]['status'] == 'R' ) 
635            {
636                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
637                {
638                    $all_used_nodes[] = $tempnode;
639                }
640            }
641
642            $used_cpus += $cpus;
643
644            if( $jobs[$jobid]['status'] == 'R' ) 
645            {
646                $running_cpus     += $cpus;
647
648                $running_jobs++;
649
650                $found_node_job    = 0;
651
652                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
653                {
654                    $running_name_nodes[] = $tempnode;
655
656                    if( isset( $hostname ) && $hostname != '' ) 
657                    {
658                        $domain_len     = 0 - strlen( $jobs[$jobid]['domain'] );
659                        $hostnode     = $tempnode;
660
661                        if( $use_fqdn == 1)
662                        {
663                            if( substr( $hostnode, $domain_len ) != $jobs[$jobid]['domain'] ) 
664                            {
665                                $hostnode = $hostnode. '.'. $jobs[$jobid]['domain'];
666                            }
667                        }
668
669                        if( $hostname == $hostnode ) 
670                        {
671                            $found_node_job = 1;
672                            $display_job = 1;
673                        } 
674                        else if( !$found_node_job ) 
675                        {
676                            $display_job = 0;
677                        }
678                    }
679                }
680            }
681
682            if( $jobs[$jobid]['status'] == 'Q' ) 
683            {
684                if( isset( $hostname ) && $hostname != '' )
685                {
686                    $display_job = 0;
687                }
688
689                $queued_cpus     += $cpus;
690                $queued_nodes     += $nodes;
691
692                $queued_jobs++;
693            }
694
695            foreach( $filter as $filtername=>$filtervalue ) 
696            {
697                if( $filtername == 'id' && $jobid != $filtervalue )
698                {
699                    $display_job = 0;
700                }
701                else if( $filtername == 'state' && $jobs[$jobid]['status'] != $filtervalue )
702                {
703                    $display_job = 0;
704                }
705                else if( $filtername == 'queue' && $jobs[$jobid]['queue'] != $filtervalue )
706                {
707                    $display_job = 0;
708                }
709                else if( $filtername == 'owner' && $jobs[$jobid]['owner'] != $filtervalue )
710                {
711                    $display_job = 0;
712                }
713            }
714
715            if( $display_job ) 
716            {
717                $tpl->newBlock( "node" );
718                $tpl->assign( "clustername", $clustername );
719                $tpl->assign( "id", $jobid );
720
721                $last_displayed_job     = $jobid;
722
723                $tpl->assign( "state", $jobs[$jobid]['status'] );
724
725                $fullstate         = '';
726
727                if( $jobs[$jobid]['status'] == 'R' ) 
728                {
729                    $fullstate     = "Running";
730                } 
731                else if( $jobs[$jobid]['status'] == 'Q' ) 
732                {
733                    $fullstate     = "Queued";
734                }
735
736                $tpl->assign( "fullstate", $fullstate );
737               
738                $tpl->assign( "owner", $jobs[$jobid]['owner'] );
739                $tpl->assign( "queue", $jobs[$jobid]['queue'] );
740
741                $fulljobname         = $jobs[$jobid]['name'];
742                $shortjobname         = '';
743
744                $tpl->assign( "fulljobname", $fulljobname );
745
746                $fulljobname_fields    = explode( ' ', $fulljobname );
747
748                $capjobname        = 0;
749
750                if( strlen( $fulljobname_fields[0] ) > 10 )
751                {
752                    $capjobname    = 1;
753                }
754
755                if( $capjobname ) 
756                {
757                    $tpl->newBlock( "jobname_hint_start" );
758                    $tpl->gotoBlock( "node" );
759
760                    $shortjobname     = substr( $fulljobname, 0, 10 ) . '..';
761                } 
762                else 
763                {
764                    $shortjobname     = $fulljobname;
765                }
766               
767                $tpl->assign( "name", $shortjobname );
768
769                if( $capjobname ) 
770                {
771                    $tpl->newBlock( "jobname_hint_end" );
772                    $tpl->gotoBlock( "node" );
773                }
774
775                $domain         = $jobs[$jobid]['domain'];
776
777                $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) ) );
778
779                if( $COLUMN_REQUESTED_MEMORY ) 
780                {
781                    $tpl->newBlock( "column_req_mem" );
782                    $tpl->assign( "req_memory", $jobs[$jobid]['requested_memory'] );
783                    $tpl->gotoBlock( "node" );
784                }
785
786
787                if( $COLUMN_QUEUED ) 
788                {
789                    $tpl->newBlock( "column_queued" );
790                    $tpl->assign( "queued", makeDate( $jobs[$jobid]['queued_timestamp'] ) );
791                    $tpl->gotoBlock( "node" );
792                }
793                if( $COLUMN_NODES ) 
794                {
795                    $tpl->newBlock( "column_nodes" );
796                    $tpl->gotoBlock( "node" );
797                }
798
799                $ppn             = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
800                $cpus             = $nodes * $ppn;
801
802                $tpl->assign( "nodes", $nodes );
803                $tpl->assign( "cpus", $cpus );
804
805                $start_time         = (int) $jobs[$jobid]['start_timestamp'];
806                $job_start         = $start_time;
807
808                $view_cpus         += $cpus;
809
810                $view_jobs++;
811
812                if( $jobs[$jobid]['status'] == 'R' ) 
813                {
814                    foreach( $jobs[$jobid]['nodes'] as $tempnode )
815                    {
816                        $view_name_nodes[]     = $tempnode;
817                    }
818
819                    if( $COLUMN_NODES ) 
820                    {
821                        $tpl->gotoBlock( "column_nodes" );
822
823                        $mynodehosts         = array();
824
825                        foreach( $jobs[$jobid]['nodes'] as $mynode ) 
826                        {
827                            if( $use_fqdn == 1)
828                            {
829                                $mynode    = $mynode.".".$jobs[$jobid]['domain'];
830                            }
831                            $myhost_href     = "./?c=".$clustername."&h=".$mynode;
832                            $mynodehosts[]     = "<A HREF=\"".$myhost_href."\">".$mynode."</A>";
833                        }
834
835                        $nodes_hostnames     = implode( " ", $mynodehosts );
836
837                        $tpl->assign( "nodes_hostnames", $nodes_hostnames );
838                        $tpl->gotoBlock( "node" );
839                    }
840                } 
841                else if( $jobs[$jobid]['status'] == 'Q' ) 
842                {
843                    $view_nodes     += (int) $jobs[$jobid]['nodes'];
844                }
845
846                if( $even ) 
847                {
848                    $tpl->assign( "nodeclass", "even" );
849
850                    $even         = 0;
851                } 
852                else 
853                {
854                    $tpl->assign( "nodeclass", "odd" );
855
856                    $even         = 1;
857                }
858
859                if( $start_time ) 
860                {
861                    $runningtime         = makeTime( $report_time - $start_time );
862                    $job_runningtime    = $heartbeat - $start_time;
863
864                    $tpl->assign( "started", makeDate( $start_time ) );
865                    $tpl->assign( "runningtime", $runningtime );
866                }
867            }
868        }
869    }
870
871    $all_used_nodes     = array_unique( $all_used_nodes );
872    $view_name_nodes     = array_unique( $view_name_nodes );
873    $running_name_nodes     = array_unique( $running_name_nodes );
874
875    $used_nodes         = count( $all_used_nodes );
876    $view_nodes         += count( $view_name_nodes );
877    $running_nodes         += count( $running_name_nodes );
878
879    $total_nodes         = $queued_nodes + $running_nodes;
880    $total_cpus         = $queued_cpus + $running_cpus;
881    $total_jobs         = $queued_jobs + $running_jobs;
882
883    $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
884    $free_nodes        = ( $free_nodes >= 0 ) ? $free_nodes : 0;
885    $free_cpus         = $avail_cpus - $running_cpus - $na_cpus;
886    $free_cpus        = ( $free_cpus >= 0 ) ? $free_cpus : 0;
887
888    $tpl->assignGlobal( "avail_nodes", $avail_nodes );
889    $tpl->assignGlobal( "avail_cpus", $avail_cpus );
890
891    $tpl->assignGlobal( "queued_nodes", $queued_nodes );
892    $tpl->assignGlobal( "queued_jobs", $queued_jobs );
893    $tpl->assignGlobal( "queued_cpus", $queued_cpus );
894
895    // Only display "Unavailable" in count overview there are any
896    //
897    if( $na_nodes > 0 )
898    {
899        $tpl->newBlock( "na_nodes" );
900
901        $tpl->assignGlobal( "na_nodes", $na_nodes );
902        $tpl->assignGlobal( "na_cpus", $na_cpus );
903
904        $tpl->gotoBlock( "_ROOT" );
905    }
906
907    $tpl->assignGlobal( "total_nodes", $total_nodes );
908    $tpl->assignGlobal( "total_jobs", $total_jobs );
909    $tpl->assignGlobal( "total_cpus", $total_cpus );
910
911    $tpl->assignGlobal( "running_nodes", $running_nodes );
912    $tpl->assignGlobal( "running_jobs", $running_jobs );
913    $tpl->assignGlobal( "running_cpus", $running_cpus );
914
915    $tpl->assignGlobal( "used_nodes", $used_nodes );
916    $tpl->assignGlobal( "used_jobs", $used_jobs );
917    $tpl->assignGlobal( "used_cpus", $used_cpus );
918
919    $tpl->assignGlobal( "free_nodes", $free_nodes );
920    $tpl->assignGlobal( "free_cpus", $free_cpus );
921
922    $tpl->assignGlobal( "view_nodes", $view_nodes );
923    $tpl->assignGlobal( "view_jobs", $view_jobs );
924    $tpl->assignGlobal( "view_cpus", $view_cpus );
925
926    $tpl->assignGlobal( "report_time", makeDate( $heartbeat) );
927
928    if( intval($view_jobs) == 1 and $start_time )
929    {
930        if( $last_displayed_job != null )
931        {
932            $filter['id'] = $last_displayed_job;
933        }
934    }
935
936    global $longtitle, $title;
937
938    $longtitle = "Batch Report :: Powered by Job Monarch!";
939    $title = "Batch Report";
940
941    makeHeader( 'overview', $title, $longtitle );
942
943    setupFilterSettings();
944
945    if( intval($view_jobs) == 1 and $start_time ) 
946    {
947        $tpl->newBlock( "showhosts" );
948
949        # Present a width list
950        $cols_menu     = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
951
952        $hostcols     = ($hc) ? $hc : 4;
953
954        foreach( range( 1, 25 ) as $cols ) 
955        {
956            $cols_menu    .= "<OPTION VALUE=$cols ";
957
958            if ($cols == $hostcols)
959            {
960                $cols_menu    .= "SELECTED";
961            }
962            $cols_menu    .= ">$cols\n";
963        }
964        $cols_menu     .= "</SELECT>\n";
965
966        $tpl->assign( "metric","$metricname $units" );
967        $tpl->assign( "id", $filter['id'] );
968
969        # Host columns menu defined in header.php
970        $tpl->assign( "cols_menu", $cols_menu );
971
972        $showhosts     = isset($sh) ? $sh : $default_showhosts;
973
974        $tpl->assign( "checked$showhosts", "checked" );
975
976        if( $showhosts ) 
977        {
978            if( !isset( $start ) ) 
979            {
980                $start    ="jobstart";
981            }
982            if( !isset( $stop ) ) 
983            {
984                $stop    ="now";
985            }
986
987            $sorted_hosts     = array();
988            $hosts_up     = $jobs[$filter['id']]['nodes'];
989
990            $r         = intval($job_runningtime * 1.2);
991
992            $jobrange     = -$r ;
993            $jobstart     = $start_time;
994
995            if ( $reports[$metricname] )
996            {
997                $metricval     = "g";
998            }
999            else
1000            {
1001                $metricval    = "m";
1002            }
1003               
1004            foreach ( $hosts_up as $host ) 
1005            {
1006                $domain_len         = 0 - strlen( $domain );
1007
1008                if( $use_fqdn )
1009                {
1010                    if( substr( $host, $domain_len ) != $domain ) 
1011                    {
1012                        $host         = $host . '.' . $domain;
1013                    }
1014                }
1015
1016                $cpus             = $metrics[$host]["cpu_num"]["VAL"];
1017
1018                if ( !$cpus )
1019                {
1020                    $cpus        = 1;
1021                }
1022
1023                $load_one         = $metrics[$host]["load_one"]['VAL'];
1024                $load             = ((float) $load_one) / $cpus;
1025                $host_load[$host]     = $load;
1026
1027                $percent_hosts[load_color($load)] ++;
1028
1029                if ($metricname=="load_one")
1030                {
1031                    $sorted_hosts[$host]     = $load;
1032                }
1033                else
1034                {
1035                    $sorted_hosts[$host]     = $metrics[$host][$metricname]['VAL'];
1036                }
1037            }
1038
1039            switch ( $sort ) 
1040            {
1041                case "descending":
1042                    arsort( $sorted_hosts );
1043                    break;
1044
1045                case "by hostname":
1046                    ksort( $sorted_hosts );
1047                    break;
1048
1049                case "ascending":
1050                    asort( $sorted_hosts );
1051                    break;
1052
1053                default:
1054                    break;
1055            }
1056
1057            // First pass to find the max value in all graphs for this
1058            // metric. The $start,$end variables comes from get_context.php,
1059            // included in index.php.
1060            //
1061            list($min, $max) = find_limits($sorted_hosts, $metricname);
1062
1063            // Second pass to output the graphs or metrics.
1064            $i = 1;
1065
1066            foreach ( $sorted_hosts as $host=>$value  ) 
1067            {
1068                $tpl->newBlock( "sorted_list" );
1069
1070                $host_url     = rawurlencode( $host );
1071                $cluster_url     = rawurlencode( $clustername );
1072
1073                $textval     = "";
1074
1075                $val         = $metrics[$host][$metricname];
1076                $class         = "metric";
1077                $host_link    = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
1078
1079                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
1080                {
1081                    $textval     = date( "r", $val["VAL"] );
1082                }
1083                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
1084                {
1085                    $textval     = $val["VAL"] . " " . $val["UNITS"];
1086                }
1087                else
1088                {
1089                    $load_color    = load_color($host_load[$host]);
1090                    $graphargs     = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
1091                    $graphargs     .= "z=small&c=$cluster_url&h=$host_url&l=$load_color&v=".$val['VAL']."&r=job&jr=$jobrange&js=$jobstart";
1092                    if( $max > 0 )
1093                    {
1094                        $graphargs    .= "&x=$max&n=$min";
1095                    }
1096                }
1097                if ($textval)
1098                {
1099                    $cell    = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
1100                } else {
1101                    $cell    = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>";
1102                }
1103
1104                $tpl->assign( "metric_image", $cell );
1105
1106                if(! ($i++ % $hostcols) )
1107                {
1108                     $tpl->assign( "br", "</tr><tr>" );
1109                }
1110            }
1111        }
1112    }
1113}
1114?>
Note: See TracBrowser for help on using the repository browser.