source: branches/1.0/web/addons/job_monarch/overview.php @ 825

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

graph.php:

  • pass min/max to rrdtool

overview.php:

  • set units as rrd vertical label
  • Property svn:keywords set to Id
File size: 33.4 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 823 2013-04-11 16:41:32Z 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 = array();
35
36$tpl_data[ "clustername"]= $clustername ;
37
38if( $JOB_ARCHIVE )
39{
40    $tpl_data[ "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[ $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[ "clusterimage"]= "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&j_view=big-clusterimage".$filter_image_url;
89
90    $tpl_data[ "node_clustermap"]= "yes";
91    $tpl_data[ "node_area_map"]= $ic->getImagemapArea();
92
93    $tpl_data[ "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["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["sortorder"]= $sortorder;
530    $tpl_data["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[ "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[ "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[ "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                    $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                    $job_loop[ "jobname_hint_end" ] = "yes";
780                }
781
782                $domain         = $jobs[$jobid]['domain'];
783
784                $job_loop["req_cpu"] = makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) );
785
786                if( $COLUMN_REQUESTED_MEMORY ) 
787                {
788                    $job_loop[ "column_req_mem" ] = "yes";
789                    $job_loop["req_memory"] = $jobs[$jobid]['requested_memory'];
790                }
791
792
793                if( $COLUMN_QUEUED ) 
794                {
795                    $job_loop[ "column_queued" ] = "yes";
796                    $job_loop["queued"] = makeDate( $jobs[$jobid]['queued_timestamp'] );
797                }
798                if( $COLUMN_NODES ) 
799                {
800                    $job_loop[ "column_nodes" ] = "yes";
801                    //echo "colum nodes";
802                }
803
804                $ppn       = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
805                $cpus      = $nodes * $ppn;
806
807                $job_loop["nodes"] = $nodes;
808                $job_loop["cpus"] = $cpus;
809
810                $start_time= (int) $jobs[$jobid]['start_timestamp'];
811                $job_start = $start_time;
812
813
814                $view_cpus += $cpus;
815
816                $view_jobs++;
817
818                if( $jobs[$jobid]['status'] == 'R' ) 
819                {
820                    $job_runningtime    = $heartbeat - $start_time;
821                    if( $rjqj_start == null ) 
822                    {
823                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
824                    }
825                    else if( $start_time < $rjqj_start )
826                    {
827                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
828                    }
829
830                    foreach( $jobs[$jobid]['nodes'] as $tempnode )
831                    {
832                        $view_name_nodes[]     = $tempnode;
833                    }
834
835                    if( $COLUMN_NODES ) 
836                    {
837                        $job_loop[ "column_nodes" ] = "yes";
838
839                        $mynodehosts         = array();
840
841                        foreach( $jobs[$jobid]['nodes'] as $shortnode ) 
842                        {
843                            if( $use_fqdn == 1)
844                            {
845                                $mynode     = $shortnode.".".$jobs[$jobid]['domain'];
846                            }
847                            $myhost_href    = "./?c=".$clustername."&h=".$mynode;
848                            $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
849                        }
850
851                        $nodes_hostnames    = implode( " ", $mynodehosts );
852
853                        $job_loop["nodes_hostnames"] = $nodes_hostnames;
854                    }
855                } 
856                else if( $jobs[$jobid]['status'] == 'Q' ) 
857                {
858                    $view_nodes     += (int) $jobs[$jobid]['nodes'];
859                }
860
861                if( $even ) 
862                {
863                    $job_loop["nodeclass"] = "even";
864
865                    $even         = 0;
866                } 
867                else 
868                {
869                    $job_loop["nodeclass"] = "odd";
870
871                    $even         = 1;
872                }
873
874                if( $start_time ) 
875                {
876                    $runningtime        = makeTime( $report_time - $start_time );
877                    $job_runningtime    = $heartbeat - $start_time;
878
879                    $job_loop["started"] = makeDate( $start_time );
880                    $job_loop["runningtime"] = $runningtime;
881                }
882                $node_list[] = &$job_loop;
883            }
884            $tpl_data["node_list"]= &$node_list ;
885        }
886    }
887    if( intval($view_jobs) == 1 and $start_time )
888    {
889        if( $last_displayed_job != null )
890        {
891            $filter['id'] = $last_displayed_job;
892        }
893    }
894    // Running / queued amount jobs graph
895    //
896    if( $rjqj_host != null )
897    {
898        $rjqj_graphargs = "?z=overview-medium&c=$clustername&h=$rjqj_host&g=job_report&r=$range";
899        if( $range == 'job' )
900        {
901            $rjqj_end = time();
902
903            if( $rjqj_start == null ) 
904            { // probably no running jobs in this view: only queued
905                $rjqj_start = $rjqj_end - (24 * 3600); // default to 1 day
906            }
907            $rjqj_title = rawurlencode( makeTime( ($rjqj_end - $rjqj_start) ) );
908            $rjqj_graphargs .= "&period_start=$rjqj_start&period_stop=$rjqj_end&t=$rjqj_title";
909        }
910        else
911        {
912            $rjqj_graphargs .= "&st=$cluster[LOCALTIME]";
913        }
914        if( intval($view_jobs) == 1 and $start_time )
915        {
916            $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
917            $rjqj_graphargs .= "&job_start=$start_time";
918        }
919
920        $rjqj_str  = "<A HREF=\"./graph.php$rjqj_graphargs\">";
921        $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php$rjqj_graphargs\">";
922        $rjqj_str .= "</A>";
923
924        $tpl_data[ "rjqj_graph"]= $rjqj_str ;
925    }
926
927    $all_used_nodes     = array_unique( $all_used_nodes );
928    $view_name_nodes    = array_unique( $view_name_nodes );
929    $running_name_nodes = array_unique( $running_name_nodes );
930
931    $used_nodes         = count( $all_used_nodes );
932    $view_nodes        += count( $view_name_nodes );
933    $running_nodes     += count( $running_name_nodes );
934
935    $total_nodes        = $queued_nodes + $running_nodes;
936    $total_cpus         = $queued_cpus + $running_cpus;
937    $total_jobs         = $queued_jobs + $running_jobs;
938
939    $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
940    $free_nodes         = ( $free_nodes >= 0 ) ? $free_nodes : 0;
941    $free_cpus          = $avail_cpus - $running_cpus - $na_cpus;
942    $free_cpus          = ( $free_cpus >= 0 ) ? $free_cpus : 0;
943
944    $tpl_data[ "avail_nodes"]= $avail_nodes ;
945    $tpl_data[ "avail_cpus"]= $avail_cpus ;
946
947    $tpl_data[ "queued_nodes"]= $queued_nodes ;
948    $tpl_data[ "queued_jobs"]= $queued_jobs ;
949    $tpl_data[ "queued_cpus"]= $queued_cpus ;
950
951    // Only display "Unavailable" in count overview there are any
952    //
953    if( $na_nodes > 0 )
954    {
955        $tpl_data[ "na_nodes"]= "yes";
956
957        $tpl_data[ "na_nodes"]= $na_nodes ;
958        $tpl_data[ "na_cpus"]= $na_cpus ;
959    }
960
961    $tpl_data[ "total_nodes"]= $total_nodes ;
962    $tpl_data[ "total_jobs"]= $total_jobs ;
963    $tpl_data[ "total_cpus"]= $total_cpus ;
964
965    $tpl_data[ "running_nodes"]= $running_nodes ;
966    $tpl_data[ "running_jobs"]= $running_jobs ;
967    $tpl_data[ "running_cpus"]= $running_cpus ;
968
969    $tpl_data[ "used_nodes"]= $used_nodes ;
970    $tpl_data[ "used_jobs"]= $used_jobs ;
971    $tpl_data[ "used_cpus"]= $used_cpus ;
972
973    $tpl_data[ "free_nodes"]= $free_nodes ;
974    $tpl_data[ "free_cpus"]= $free_cpus ;
975
976    $tpl_data[ "view_nodes"]= $view_nodes ;
977    $tpl_data[ "view_jobs"]= $view_jobs ;
978    $tpl_data[ "view_cpus"]= $view_cpus ;
979
980    $tpl_data[ "report_time"]= makeDate( $heartbeat);
981
982
983    global $longtitle, $title;
984
985    $longtitle = "Batch Report :: Powered by Job Monarch!";
986    $title = "Batch Report";
987
988    makeHeader( 'overview', $title, $longtitle );
989
990    setupFilterSettings();
991
992    if( intval($view_jobs) == 1 and $start_time )
993    {
994        $tpl_data[ "showhosts"]= "yes" ;
995
996        $showhosts     = isset($sh) ? $sh : $default_showhosts;
997
998        $tpl_data[ "checked$showhosts"]= "checked" ;
999
1000        $sorted_list = array();
1001
1002        if( $showhosts )
1003        {
1004            if( !isset( $start ) )
1005            {
1006                $start    ="jobstart";
1007            }
1008            if( !isset( $stop ) )
1009            {
1010                $stop    ="now";
1011            }
1012
1013            $sorted_hosts = array();
1014            $hosts_up     = $jobs[$filter['id']]['nodes'];
1015
1016            $r            = intval($job_runningtime * 1.2);
1017
1018            $jobrange     = -$r ;
1019            $jobstart     = $start_time;
1020
1021            if ( $reports[$metricname] )
1022            {
1023                $metricval     = "g";
1024            }
1025            else
1026            {
1027                $metricval    = "m";
1028            }
1029               
1030            foreach ( $hosts_up as $host )
1031            {
1032                $domain_len         = 0 - strlen( $domain );
1033
1034                if( $use_fqdn )
1035                {
1036                    if( substr( $host, $domain_len ) != $domain )
1037                    {
1038                        $host         = $host . '.' . $domain;
1039                    }
1040                }
1041                $cpus             = 0;
1042
1043                $cpus             = $metrics[$host]["cpu_num"]["VAL"];
1044
1045                if( $cpus == 0 )
1046                {
1047                    $cpus        = 1;
1048                }
1049
1050                $load_one         = $metrics[$host]["load_one"]['VAL'];
1051                $load             = ((float) $load_one) / $cpus;
1052                $host_load[$host] = $load;
1053
1054                $percent_hosts[load_color($load)] ++;
1055
1056                if ($metricname=="load_one")
1057                {
1058                    $sorted_hosts[$host]     = $load;
1059                }
1060                else
1061                {
1062                    $sorted_hosts[$host]     = $metrics[$host][$metricname]['VAL'];
1063                }
1064            }
1065
1066            switch ( $sort )
1067            {
1068                case "descending":
1069                    arsort( $sorted_hosts );
1070                    break;
1071
1072                case "by hostname":
1073                    ksort( $sorted_hosts );
1074                    break;
1075
1076                case "ascending":
1077                    asort( $sorted_hosts );
1078                    break;
1079
1080                default:
1081                    break;
1082            }
1083
1084            // First pass to find the max value in all graphs for this
1085            // metric. The $start,$end variables comes from get_context.php,
1086            // included in index.php.
1087            //
1088            list($min, $max) = find_limits($sorted_hosts, $metricname);
1089
1090            // Second pass to output the graphs or metrics.
1091            $i = 1;
1092
1093            $metric_loop = array();
1094            foreach ( $sorted_hosts as $host=>$value  )
1095            {
1096                $host_url    = rawurlencode( $host );
1097                $cluster_url = rawurlencode( $clustername );
1098
1099                $textval     = "";
1100
1101                $val         = $metrics[$host][$metricname];
1102                $class       = "metric";
1103
1104                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
1105                {
1106                    $textval     = date( "r", $val["VAL"] );
1107                }
1108                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
1109                {
1110                    $textval     = $val["VAL"] . " " . $val["UNITS"];
1111                }
1112                else
1113                {
1114                    $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
1115                    $period_end    = $cluster['LOCALTIME'];
1116                    $runningtime   = intval( $period_end ) - intval( $job_start );
1117                    $load_color    = load_color($host_load[$host]);
1118                    $period_start  = intval( $job_start - (intval( $runningtime * 0.10 ) ) );
1119                    //printf("last job %s job start %s runningtime %s period start %s", $last_displayed_job, $jobstart, $job_runningtime, $period_start);
1120                    $graphargs     = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
1121                    $graphargs    .= "z=overview-medium&c=$cluster_url&r=$range&h=$host_url&l=$load_color&v=".$val['VAL']."&job_start=$job_start&vl=".$val['UNITS'];
1122                    $host_link     = "?j_view=overview-host&c=$cluster_url&r=$range&h=$host_url&job_start=$jobstart";
1123
1124                    if( $range == 'job' )
1125                    {
1126                        $graphargs     .= "&period_start=$period_start&period_stop=$period_end";
1127                        $host_link     .= "&period_start=$period_start&period_stop=$period_end";
1128                    }
1129                    else
1130                    {
1131                        $graphargs     .= "&st=$period_end";
1132                        $host_link     .= "&st=$period_end";
1133                    }
1134                    if( $max > 0 )
1135                    {
1136                        $graphargs    .= "&x=$max&n=$min";
1137                    }
1138                }
1139                if ($textval)
1140                {
1141                    $cell    = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
1142                } else {
1143                    $cell    = "<A HREF=\"$host_link\">" . "<IMG SRC=\"./graph.php?$graphargs\" " . "ALT=\"$host\" BORDER=0></A>";
1144                }
1145
1146                $metric_loop["metric_image"] = $cell;
1147
1148                //if(! ($i++ % $hostcols) )
1149                //{
1150                //     $metric_loop["br"] = "</tr><tr>";
1151                //}
1152                $sorted_list[] = $metric_loop;
1153            }
1154            $tpl_data["sorted_list"]= $sorted_list ;
1155        }
1156    }
1157    $dwoo->output($tpl, $tpl_data);
1158}
1159
1160?>
Note: See TracBrowser for help on using the repository browser.