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

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