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

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