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

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