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

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

search.php,
templates/search.tpl:

  • pass self to search pages

overview.php:

  • set sourcetime as period end
  • Property svn:keywords set to Id
File size: 34.0 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 805 2013-04-08 18:49:18Z 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        arsort( $sorted );
502    }
503    else if( $sortorder == "desc" )
504    {
505        asort( $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                $job_loop = array();
725                $job_loop["clustername"] = $clustername;
726
727                $job_loop["id"] = $jobid;
728
729                $last_displayed_job     = $jobid;
730
731                $job_loop["state"] = $jobs[$jobid]['status'];
732
733                $fullstate         = '';
734
735                if( $jobs[$jobid]['status'] == 'R' ) 
736                {
737                    $fullstate     = "Running";
738                } 
739                else if( $jobs[$jobid]['status'] == 'Q' ) 
740                {
741                    $fullstate     = "Queued";
742                }
743
744                $job_loop["fullstate"] = $fullstate;
745               
746                $job_loop["owner"] = $jobs[$jobid]['owner'];
747                $job_loop["queue"] = $jobs[$jobid]['queue'];
748
749                $fulljobname         = $jobs[$jobid]['name'];
750                $shortjobname        = '';
751
752                $job_loop["fulljobname"] = $fulljobname;
753
754                $fulljobname_fields    = explode( ' ', $fulljobname );
755
756                $capjobname        = 0;
757
758                if( strlen( $fulljobname_fields[0] ) > 10 )
759                {
760                    $capjobname    = 1;
761                }
762
763                if( $capjobname ) 
764                {
765                    //$tpl_data->assign( "jobname_hint_start", "yes" );
766                    $job_loop[ "jobname_hint_start" ] = "yes";
767
768                    $shortjobname     = substr( $fulljobname, 0, 10 ) . '..';
769                } 
770                else 
771                {
772                    $shortjobname     = $fulljobname;
773                }
774               
775                $job_loop["name"] = $shortjobname;
776
777                if( $capjobname ) 
778                {
779                    //$tpl_data->assign( "jobname_hint_end", "yes" );
780                    $job_loop[ "jobname_hint_end" ] = "yes";
781                }
782
783                $domain         = $jobs[$jobid]['domain'];
784
785                $job_loop["req_cpu"] = makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) );
786
787                if( $COLUMN_REQUESTED_MEMORY ) 
788                {
789                    //$tpl_data->assign( "column_req_mem", "yes" );
790                    $job_loop[ "column_req_mem" ] = "yes";
791                    $job_loop["req_memory"] = $jobs[$jobid]['requested_memory'];
792                }
793
794
795                if( $COLUMN_QUEUED ) 
796                {
797                    //$tpl_data->assign( "column_queued", "yes" );
798                    $job_loop[ "column_queued" ] = "yes";
799                    $job_loop["queued"] = makeDate( $jobs[$jobid]['queued_timestamp'] );
800                }
801                if( $COLUMN_NODES ) 
802                {
803                    //$tpl_data->assign( "column_nodes", "yes" );
804                    $job_loop[ "column_nodes" ] = "yes";
805                    //echo "colum nodes";
806                }
807
808                $ppn       = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
809                $cpus      = $nodes * $ppn;
810
811                $job_loop["nodes"] = $nodes;
812                $job_loop["cpus"] = $cpus;
813
814                $start_time= (int) $jobs[$jobid]['start_timestamp'];
815                $job_start = $start_time;
816
817
818                $view_cpus += $cpus;
819
820                $view_jobs++;
821
822                if( $jobs[$jobid]['status'] == 'R' ) 
823                {
824                    $job_runningtime    = $heartbeat - $start_time;
825                    if( $rjqj_start == null ) 
826                    {
827                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
828                    }
829                    else if( $start_time < $rjqj_start )
830                    {
831                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
832                    }
833
834                    foreach( $jobs[$jobid]['nodes'] as $tempnode )
835                    {
836                        $view_name_nodes[]     = $tempnode;
837                    }
838
839                    if( $COLUMN_NODES ) 
840                    {
841                        //$tpl_data->assign( "column_nodes", "yes" );
842                        $job_loop[ "column_nodes" ] = "yes";
843
844                        $mynodehosts         = array();
845
846                        foreach( $jobs[$jobid]['nodes'] as $shortnode ) 
847                        {
848                            if( $use_fqdn == 1)
849                            {
850                                $mynode     = $shortnode.".".$jobs[$jobid]['domain'];
851                            }
852                            $myhost_href    = "./?c=".$clustername."&h=".$mynode;
853                            $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
854                        }
855
856                        $nodes_hostnames    = implode( " ", $mynodehosts );
857
858                        $job_loop["nodes_hostnames"] = $nodes_hostnames;
859                    }
860                } 
861                else if( $jobs[$jobid]['status'] == 'Q' ) 
862                {
863                    $view_nodes     += (int) $jobs[$jobid]['nodes'];
864                }
865
866                if( $even ) 
867                {
868                    $job_loop["nodeclass"] = "even";
869
870                    $even         = 0;
871                } 
872                else 
873                {
874                    $job_loop["nodeclass"] = "odd";
875
876                    $even         = 1;
877                }
878
879                if( $start_time ) 
880                {
881                    $runningtime        = makeTime( $report_time - $start_time );
882                    $job_runningtime    = $heartbeat - $start_time;
883
884                    $job_loop["started"] = makeDate( $start_time );
885                    $job_loop["runningtime"] = $runningtime;
886                }
887                $node_list[] = $job_loop;
888            }
889            $tpl_data->assign("node_list", $node_list );
890        }
891    }
892    if( intval($view_jobs) == 1 and $start_time )
893    {
894        if( $last_displayed_job != null )
895        {
896            $filter['id'] = $last_displayed_job;
897        }
898    }
899    // Running / queued amount jobs graph
900    //
901    if( $rjqj_host != null )
902    {
903        $rjqj_graphargs = "?z=overview-medium&c=$clustername&h=$rjqj_host&g=job_report&r=$range";
904        if( $range == 'job' )
905        {
906            $rjqj_end = time();
907
908            if( $rjqj_start == null ) 
909            { // probably no running jobs in this view: only queued
910                $rjqj_start = $rjqj_end - (24 * 3600); // default to 1 day
911            }
912            $rjqj_title = rawurlencode( makeTime( ($rjqj_end - $rjqj_start) ) );
913            $rjqj_graphargs .= "&period_start=$rjqj_start&period_stop=$rjqj_end&t=$rjqj_title";
914        }
915        else
916        {
917            $rjqj_graphargs .= "&st=$cluster[LOCALTIME]";
918        }
919        if( intval($view_jobs) == 1 and $start_time )
920        {
921            $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
922            $rjqj_graphargs .= "&job_start=$start_time";
923        }
924
925        $rjqj_str  = "<A HREF=\"./graph.php$rjqj_graphargs\">";
926        $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php$rjqj_graphargs\">";
927        $rjqj_str .= "</A>";
928
929        $tpl_data->assign( "rjqj_graph", $rjqj_str );
930    }
931
932    $all_used_nodes     = array_unique( $all_used_nodes );
933    $view_name_nodes    = array_unique( $view_name_nodes );
934    $running_name_nodes = array_unique( $running_name_nodes );
935
936    $used_nodes         = count( $all_used_nodes );
937    $view_nodes        += count( $view_name_nodes );
938    $running_nodes     += count( $running_name_nodes );
939
940    $total_nodes        = $queued_nodes + $running_nodes;
941    $total_cpus         = $queued_cpus + $running_cpus;
942    $total_jobs         = $queued_jobs + $running_jobs;
943
944    $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
945    $free_nodes         = ( $free_nodes >= 0 ) ? $free_nodes : 0;
946    $free_cpus          = $avail_cpus - $running_cpus - $na_cpus;
947    $free_cpus          = ( $free_cpus >= 0 ) ? $free_cpus : 0;
948
949    $tpl_data->assign( "avail_nodes", $avail_nodes );
950    $tpl_data->assign( "avail_cpus", $avail_cpus );
951
952    $tpl_data->assign( "queued_nodes", $queued_nodes );
953    $tpl_data->assign( "queued_jobs", $queued_jobs );
954    $tpl_data->assign( "queued_cpus", $queued_cpus );
955
956    // Only display "Unavailable" in count overview there are any
957    //
958    if( $na_nodes > 0 )
959    {
960        $tpl_data->assign( "na_nodes", "yes");
961
962        $tpl_data->assign( "na_nodes", $na_nodes );
963        $tpl_data->assign( "na_cpus", $na_cpus );
964    }
965
966    $tpl_data->assign( "total_nodes", $total_nodes );
967    $tpl_data->assign( "total_jobs", $total_jobs );
968    $tpl_data->assign( "total_cpus", $total_cpus );
969
970    $tpl_data->assign( "running_nodes", $running_nodes );
971    $tpl_data->assign( "running_jobs", $running_jobs );
972    $tpl_data->assign( "running_cpus", $running_cpus );
973
974    $tpl_data->assign( "used_nodes", $used_nodes );
975    $tpl_data->assign( "used_jobs", $used_jobs );
976    $tpl_data->assign( "used_cpus", $used_cpus );
977
978    $tpl_data->assign( "free_nodes", $free_nodes );
979    $tpl_data->assign( "free_cpus", $free_cpus );
980
981    $tpl_data->assign( "view_nodes", $view_nodes );
982    $tpl_data->assign( "view_jobs", $view_jobs );
983    $tpl_data->assign( "view_cpus", $view_cpus );
984
985    $tpl_data->assign( "report_time", makeDate( $heartbeat) );
986
987
988    global $longtitle, $title;
989
990    $longtitle = "Batch Report :: Powered by Job Monarch!";
991    $title = "Batch Report";
992
993    makeHeader( 'overview', $title, $longtitle );
994
995    setupFilterSettings();
996
997    if( intval($view_jobs) == 1 and $start_time )
998    {
999        $tpl_data->assign( "showhosts", "yes" );
1000
1001        $showhosts     = isset($sh) ? $sh : $default_showhosts;
1002
1003        $tpl_data->assign( "checked$showhosts", "checked" );
1004
1005        $sorted_list = array();
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            $metric_loop = array();
1099            foreach ( $sorted_hosts as $host=>$value  )
1100            {
1101                $host_url    = rawurlencode( $host );
1102                $cluster_url = rawurlencode( $clustername );
1103
1104                $textval     = "";
1105
1106                $val         = $metrics[$host][$metricname];
1107                $class       = "metric";
1108
1109                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
1110                {
1111                    $textval     = date( "r", $val["VAL"] );
1112                }
1113                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
1114                {
1115                    $textval     = $val["VAL"] . " " . $val["UNITS"];
1116                }
1117                else
1118                {
1119                    $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
1120                    $period_end    = $cluster['LOCALTIME'];
1121                    $runningtime   = intval( $period_end ) - intval( $job_start );
1122                    $load_color    = load_color($host_load[$host]);
1123                    $period_start  = intval( $job_start - (intval( $runningtime * 0.10 ) ) );
1124                    //printf("last job %s job start %s runningtime %s period start %s", $last_displayed_job, $jobstart, $job_runningtime, $period_start);
1125                    $graphargs     = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
1126                    $graphargs    .= "z=overview-medium&c=$cluster_url&r=$range&h=$host_url&l=$load_color&v=".$val['VAL']."&job_start=$job_start";
1127                    $host_link     = "?j_view=overview-host&c=$cluster_url&r=$range&h=$host_url&job_start=$jobstart";
1128
1129                    if( $range == 'job' )
1130                    {
1131                        $graphargs     .= "&period_start=$period_start&period_stop=$period_end";
1132                        $host_link     .= "&period_start=$period_start&period_stop=$period_end";
1133                    }
1134                    else
1135                    {
1136                        $graphargs     .= "&st=$period_end";
1137                        $host_link     .= "&st=$period_end";
1138                    }
1139                    if( $max > 0 )
1140                    {
1141                        $graphargs    .= "&x=$max&n=$min";
1142                    }
1143                }
1144                if ($textval)
1145                {
1146                    $cell    = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
1147                } else {
1148                    $cell    = "<A HREF=\"$host_link\">" . "<IMG SRC=\"./graph.php?$graphargs\" " . "ALT=\"$host\" BORDER=0></A>";
1149                }
1150
1151                $metric_loop["metric_image"] = $cell;
1152
1153                //if(! ($i++ % $hostcols) )
1154                //{
1155                //     $metric_loop["br"] = "</tr><tr>";
1156                //}
1157                $sorted_list[] = $metric_loop;
1158            }
1159            $tpl_data->assign("sorted_list", $sorted_list );
1160        }
1161    }
1162    $dwoo->output($tpl, $tpl_data);
1163}
1164
1165?>
Note: See TracBrowser for help on using the repository browser.