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

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

libtoga.php:

  • allow jobs and nodes to be set externally for ClusterImage?
  • ONLY parse XML if jobs and nodes not set externally

overview.php:

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