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

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

graph.php:

  • fixed GET variables
  • added overview graph size
  • set jobstart color
  • set rrd_dirs to current ganglia RRDs if overview-graph
  • fixed RRD colors to new Ganglia conf array

overview.php:

  • use our graph.php for RRDs
  • set job start and period start/end
  • Property svn:keywords set to Id
File size: 32.6 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 731 2013-03-24 01:07:26Z 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    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    // Running / queued amount jobs graph
608    //
609    if( $rjqj_host != null )
610    {
611
612        $rjqj_str  = "<A HREF=\"./graph.php?z=large&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">";
613        $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php?z=small&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">";
614        $rjqj_str .= "</A>";
615
616        $tpl->gotoBlock( "_ROOT" );
617
618        $tpl->assign( "rjqj_graph", $rjqj_str );
619    }
620
621    foreach( $sorted_jobs as $jobid => $sortdec ) 
622    {
623        $report_time     = $jobs[$jobid]['reported'];
624
625        if( $jobs[$jobid]['status'] == 'R' )
626        {
627            $nodes = count( $jobs[$jobid]['nodes'] );
628        }
629        else if( $jobs[$jobid]['status'] == 'Q' )
630        {
631            $nodes = $jobs[$jobid]['nodes'];
632        }
633
634        $ppn         = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
635        $cpus         = $nodes * $ppn;
636
637        if( $report_time == $heartbeat ) 
638        {
639            $display_job    = 1;
640
641            if( $jobs[$jobid]['status'] == 'R' ) 
642            {
643                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
644                {
645                    $all_used_nodes[] = $tempnode;
646                }
647            }
648
649            $used_cpus += $cpus;
650
651            if( $jobs[$jobid]['status'] == 'R' ) 
652            {
653                $running_cpus     += $cpus;
654
655                $running_jobs++;
656
657                $found_node_job    = 0;
658
659                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
660                {
661                    $running_name_nodes[] = $tempnode;
662
663                    if( isset( $hostname ) && $hostname != '' ) 
664                    {
665                        $domain_len     = 0 - strlen( $jobs[$jobid]['domain'] );
666                        $hostnode     = $tempnode;
667
668                        if( $use_fqdn == 1)
669                        {
670                            if( substr( $hostnode, $domain_len ) != $jobs[$jobid]['domain'] ) 
671                            {
672                                $hostnode = $hostnode. '.'. $jobs[$jobid]['domain'];
673                            }
674                        }
675
676                        if( $hostname == $hostnode ) 
677                        {
678                            $found_node_job = 1;
679                            $display_job = 1;
680                        } 
681                        else if( !$found_node_job ) 
682                        {
683                            $display_job = 0;
684                        }
685                    }
686                }
687            }
688
689            if( $jobs[$jobid]['status'] == 'Q' ) 
690            {
691                if( isset( $hostname ) && $hostname != '' )
692                {
693                    $display_job = 0;
694                }
695
696                $queued_cpus     += $cpus;
697                $queued_nodes     += $nodes;
698
699                $queued_jobs++;
700            }
701
702            foreach( $filter as $filtername=>$filtervalue ) 
703            {
704                if( $filtername == 'id' && $jobid != $filtervalue )
705                {
706                    $display_job = 0;
707                }
708                else if( $filtername == 'state' && $jobs[$jobid]['status'] != $filtervalue )
709                {
710                    $display_job = 0;
711                }
712                else if( $filtername == 'queue' && $jobs[$jobid]['queue'] != $filtervalue )
713                {
714                    $display_job = 0;
715                }
716                else if( $filtername == 'owner' && $jobs[$jobid]['owner'] != $filtervalue )
717                {
718                    $display_job = 0;
719                }
720            }
721
722            if( $display_job ) 
723            {
724                $tpl->newBlock( "node" );
725                $tpl->assign( "clustername", $clustername );
726                $tpl->assign( "id", $jobid );
727
728                $last_displayed_job     = $jobid;
729
730                $tpl->assign( "state", $jobs[$jobid]['status'] );
731
732                $fullstate         = '';
733
734                if( $jobs[$jobid]['status'] == 'R' ) 
735                {
736                    $fullstate     = "Running";
737                } 
738                else if( $jobs[$jobid]['status'] == 'Q' ) 
739                {
740                    $fullstate     = "Queued";
741                }
742
743                $tpl->assign( "fullstate", $fullstate );
744               
745                $tpl->assign( "owner", $jobs[$jobid]['owner'] );
746                $tpl->assign( "queue", $jobs[$jobid]['queue'] );
747
748                $fulljobname         = $jobs[$jobid]['name'];
749                $shortjobname         = '';
750
751                $tpl->assign( "fulljobname", $fulljobname );
752
753                $fulljobname_fields    = explode( ' ', $fulljobname );
754
755                $capjobname        = 0;
756
757                if( strlen( $fulljobname_fields[0] ) > 10 )
758                {
759                    $capjobname    = 1;
760                }
761
762                if( $capjobname ) 
763                {
764                    $tpl->newBlock( "jobname_hint_start" );
765                    $tpl->gotoBlock( "node" );
766
767                    $shortjobname     = substr( $fulljobname, 0, 10 ) . '..';
768                } 
769                else 
770                {
771                    $shortjobname     = $fulljobname;
772                }
773               
774                $tpl->assign( "name", $shortjobname );
775
776                if( $capjobname ) 
777                {
778                    $tpl->newBlock( "jobname_hint_end" );
779                    $tpl->gotoBlock( "node" );
780                }
781
782                $domain         = $jobs[$jobid]['domain'];
783
784                $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) ) );
785
786                if( $COLUMN_REQUESTED_MEMORY ) 
787                {
788                    $tpl->newBlock( "column_req_mem" );
789                    $tpl->assign( "req_memory", $jobs[$jobid]['requested_memory'] );
790                    $tpl->gotoBlock( "node" );
791                }
792
793
794                if( $COLUMN_QUEUED ) 
795                {
796                    $tpl->newBlock( "column_queued" );
797                    $tpl->assign( "queued", makeDate( $jobs[$jobid]['queued_timestamp'] ) );
798                    $tpl->gotoBlock( "node" );
799                }
800                if( $COLUMN_NODES ) 
801                {
802                    $tpl->newBlock( "column_nodes" );
803                    $tpl->gotoBlock( "node" );
804                }
805
806                $ppn             = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
807                $cpus             = $nodes * $ppn;
808
809                $tpl->assign( "nodes", $nodes );
810                $tpl->assign( "cpus", $cpus );
811
812                $start_time         = (int) $jobs[$jobid]['start_timestamp'];
813                $job_start         = $start_time;
814
815                $view_cpus         += $cpus;
816
817                $view_jobs++;
818
819                if( $jobs[$jobid]['status'] == 'R' ) 
820                {
821                    foreach( $jobs[$jobid]['nodes'] as $tempnode )
822                    {
823                        $view_name_nodes[]     = $tempnode;
824                    }
825
826                    if( $COLUMN_NODES ) 
827                    {
828                        $tpl->gotoBlock( "column_nodes" );
829
830                        $mynodehosts         = array();
831
832                        foreach( $jobs[$jobid]['nodes'] as $shortnode ) 
833                        {
834                            if( $use_fqdn == 1)
835                            {
836                                $mynode    = $shortnode.".".$jobs[$jobid]['domain'];
837                            }
838                            $myhost_href     = "./?c=".$clustername."&h=".$mynode;
839                            $mynodehosts[]     = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
840                        }
841
842                        $nodes_hostnames     = implode( " ", $mynodehosts );
843
844                        $tpl->assign( "nodes_hostnames", $nodes_hostnames );
845                        $tpl->gotoBlock( "node" );
846                    }
847                } 
848                else if( $jobs[$jobid]['status'] == 'Q' ) 
849                {
850                    $view_nodes     += (int) $jobs[$jobid]['nodes'];
851                }
852
853                if( $even ) 
854                {
855                    $tpl->assign( "nodeclass", "even" );
856
857                    $even         = 0;
858                } 
859                else 
860                {
861                    $tpl->assign( "nodeclass", "odd" );
862
863                    $even         = 1;
864                }
865
866                if( $start_time ) 
867                {
868                    $runningtime         = makeTime( $report_time - $start_time );
869                    $job_runningtime    = $heartbeat - $start_time;
870
871                    $tpl->assign( "started", makeDate( $start_time ) );
872                    $tpl->assign( "runningtime", $runningtime );
873                }
874            }
875        }
876    }
877
878    $all_used_nodes     = array_unique( $all_used_nodes );
879    $view_name_nodes     = array_unique( $view_name_nodes );
880    $running_name_nodes     = array_unique( $running_name_nodes );
881
882    $used_nodes         = count( $all_used_nodes );
883    $view_nodes         += count( $view_name_nodes );
884    $running_nodes         += count( $running_name_nodes );
885
886    $total_nodes         = $queued_nodes + $running_nodes;
887    $total_cpus         = $queued_cpus + $running_cpus;
888    $total_jobs         = $queued_jobs + $running_jobs;
889
890    $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
891    $free_nodes        = ( $free_nodes >= 0 ) ? $free_nodes : 0;
892    $free_cpus         = $avail_cpus - $running_cpus - $na_cpus;
893    $free_cpus        = ( $free_cpus >= 0 ) ? $free_cpus : 0;
894
895    $tpl->assignGlobal( "avail_nodes", $avail_nodes );
896    $tpl->assignGlobal( "avail_cpus", $avail_cpus );
897
898    $tpl->assignGlobal( "queued_nodes", $queued_nodes );
899    $tpl->assignGlobal( "queued_jobs", $queued_jobs );
900    $tpl->assignGlobal( "queued_cpus", $queued_cpus );
901
902    // Only display "Unavailable" in count overview there are any
903    //
904    if( $na_nodes > 0 )
905    {
906        $tpl->newBlock( "na_nodes" );
907
908        $tpl->assignGlobal( "na_nodes", $na_nodes );
909        $tpl->assignGlobal( "na_cpus", $na_cpus );
910
911        $tpl->gotoBlock( "_ROOT" );
912    }
913
914    $tpl->assignGlobal( "total_nodes", $total_nodes );
915    $tpl->assignGlobal( "total_jobs", $total_jobs );
916    $tpl->assignGlobal( "total_cpus", $total_cpus );
917
918    $tpl->assignGlobal( "running_nodes", $running_nodes );
919    $tpl->assignGlobal( "running_jobs", $running_jobs );
920    $tpl->assignGlobal( "running_cpus", $running_cpus );
921
922    $tpl->assignGlobal( "used_nodes", $used_nodes );
923    $tpl->assignGlobal( "used_jobs", $used_jobs );
924    $tpl->assignGlobal( "used_cpus", $used_cpus );
925
926    $tpl->assignGlobal( "free_nodes", $free_nodes );
927    $tpl->assignGlobal( "free_cpus", $free_cpus );
928
929    $tpl->assignGlobal( "view_nodes", $view_nodes );
930    $tpl->assignGlobal( "view_jobs", $view_jobs );
931    $tpl->assignGlobal( "view_cpus", $view_cpus );
932
933    $tpl->assignGlobal( "report_time", makeDate( $heartbeat) );
934
935    if( intval($view_jobs) == 1 and $start_time )
936    {
937        if( $last_displayed_job != null )
938        {
939            $filter['id'] = $last_displayed_job;
940        }
941    }
942
943    global $longtitle, $title;
944
945    $longtitle = "Batch Report :: Powered by Job Monarch!";
946    $title = "Batch Report";
947
948    makeHeader( 'overview', $title, $longtitle );
949
950    setupFilterSettings();
951
952    if( intval($view_jobs) == 1 and $start_time ) 
953    {
954        $tpl->newBlock( "showhosts" );
955
956        # Present a width list
957        $cols_menu     = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
958
959        $hostcols     = ($hc) ? $hc : 4;
960
961        foreach( range( 1, 25 ) as $cols ) 
962        {
963            $cols_menu    .= "<OPTION VALUE=$cols ";
964
965            if ($cols == $hostcols)
966            {
967                $cols_menu    .= "SELECTED";
968            }
969            $cols_menu    .= ">$cols\n";
970        }
971        $cols_menu     .= "</SELECT>\n";
972
973        $tpl->assign( "metric","$metricname $units" );
974        $tpl->assign( "id", $filter['id'] );
975
976        # Host columns menu defined in header.php
977        $tpl->assign( "cols_menu", $cols_menu );
978
979        $showhosts     = isset($sh) ? $sh : $default_showhosts;
980
981        $tpl->assign( "checked$showhosts", "checked" );
982
983        if( $showhosts ) 
984        {
985            if( !isset( $start ) ) 
986            {
987                $start    ="jobstart";
988            }
989            if( !isset( $stop ) ) 
990            {
991                $stop    ="now";
992            }
993
994            $sorted_hosts = array();
995            $hosts_up     = $jobs[$filter['id']]['nodes'];
996
997            $r            = intval($job_runningtime * 1.2);
998
999            $jobrange     = -$r ;
1000            $jobstart     = $start_time;
1001
1002            if ( $reports[$metricname] )
1003            {
1004                $metricval     = "g";
1005            }
1006            else
1007            {
1008                $metricval    = "m";
1009            }
1010               
1011            foreach ( $hosts_up as $host ) 
1012            {
1013                $domain_len         = 0 - strlen( $domain );
1014
1015                if( $use_fqdn )
1016                {
1017                    if( substr( $host, $domain_len ) != $domain ) 
1018                    {
1019                        $host         = $host . '.' . $domain;
1020                    }
1021                }
1022
1023                $cpus             = $metrics[$host]["cpu_num"]["VAL"];
1024
1025                if ( !$cpus )
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                $host_link   = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
1085
1086                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
1087                {
1088                    $textval     = date( "r", $val["VAL"] );
1089                }
1090                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
1091                {
1092                    $textval     = $val["VAL"] . " " . $val["UNITS"];
1093                }
1094                else
1095                {
1096                    $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
1097                    $period_end    = time();
1098                    $runningtime   = time() - intval( $job_start );
1099                    $load_color    = load_color($host_load[$host]);
1100                    $period_start  = intval( $job_start - (intval( $runningtime * 0.10 ) ) );
1101                    //printf("last job %s job start %s runningtime %s period start %s", $last_displayed_job, $jobstart, $job_runningtime, $period_start);
1102                    $graphargs     = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
1103                    $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";
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.