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

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