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

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

templates/overview.tpl:

  • removed notice about tasks/array jobs

host_view.php:

  • cleanup graphargs

index.php:

  • setup range to job by default

overview.php:

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