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

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