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

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

libtoga.php,
index.php:

  • fix some weird issue range being overwritten by Ganglia

overview.php:

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