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

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

graph.php:

  • fixed load color background

overview.php:

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