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

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

libtoga.php:

  • allow jobs and nodes to be set externally for ClusterImage?
  • ONLY parse XML if jobs and nodes not set externally

overview.php:

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