source: branches/1.1/web/addons/job_monarch/overview.php @ 932

Last change on this file since 932 was 932, checked in by sil, 11 years ago

Removed deprecated compare-function for array-sorting.

  • Property svn:keywords set to Id
File size: 27.7 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 932 2013-08-06 12:48:14Z sil $
[225]23 */
24
[753]25global $GANGLIA_PATH, $clustername, $tpl_data, $filter, $cluster, $get_metric_string, $cluster_url, $sh;
[299]26global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter;
[409]27global $longtitle, $title, $range;
[114]28
[753]29include_once "./dwoo/dwooAutoload.php";
[116]30
[753]31global $dwoo;
32
33$tpl = new Dwoo_Template_File("templates/overview.tpl");
[822]34$tpl_data = array();
[753]35
[822]36$tpl_data[ "clustername"]= $clustername ;
[753]37
[206]38if( $JOB_ARCHIVE )
[328]39{
[822]40    $tpl_data[ "cluster_url"]= rawurlencode($clustername) ;
[328]41}
[129]42
[738]43$rjqj_start = null;
[732]44$ds         = new DataSource();
45$myxml_data = $ds->getData();
[328]46
[764]47//print_r( $myxml_data );
48
[732]49$data_gatherer = new DataGatherer( $clustername );
[326]50$data_gatherer->parseXML( $myxml_data );
[117]51
[836]52$parsetime = $data_gatherer->parsetime;
[732]53$heartbeat = $data_gatherer->getHeartbeat();
54$jobs      = $data_gatherer->getJobs();
55$gnodes    = $data_gatherer->getNodes();
56$cpus      = $data_gatherer->getCpus();
[114]57
[743]58//print_r( $gnodes );
59
[328]60function setupFilterSettings() 
61{
62
[764]63    global $tpl_data, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data, $filterorder, $_SESSION, $data_gatherer;
64    global $jobs, $gnodes;
[122]65
[719]66    $filter_image_url = "";
[119]67
[719]68    foreach( $filter as $filtername => $filtervalue ) 
69    {
[822]70        $tpl_data[ $filtername ] = $filtervalue;
[328]71
[719]72        $filter_image_url    .= "&$filtername=$filtervalue";
73    }
[114]74
[719]75    session_start();
[326]76
[719]77    unset( $_SESSION["data"] );
[732]78    $_SESSION["data"] = &$myxml_data;
[328]79
[732]80    $ic = new ClusterImage( $myxml_data, $clustername );
[328]81
[764]82    $ic->setJobs( $jobs );
83    $ic->setNodes( $gnodes );
[719]84    $ic->setBig();
85    $ic->setNoimage();
86    $ic->draw();
[326]87
[822]88    $tpl_data[ "clusterimage"]= "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&j_view=big-clusterimage".$filter_image_url;
[326]89
[822]90    $tpl_data[ "node_clustermap"]= "yes";
91    $tpl_data[ "node_area_map"]= $ic->getImagemapArea();
[326]92
[822]93    $tpl_data[ "order"]= $filterorder;
[263]94}
[122]95
[328]96function timeToEpoch( $time ) 
97{
[732]98    $time_fields = explode( ':', $time );
[120]99
[719]100    if( count( $time_fields ) == 3 ) 
101    {
[732]102        $hours   = $time_fields[0];
103        $minutes = $time_fields[1];
104        $seconds = $time_fields[2];
[120]105
[719]106    } 
107    else if( count( $time_fields ) == 2 ) 
108    {
[732]109        $hours   = 0;
110        $minutes = $time_fields[0];
111        $seconds = $time_fields[1];
[120]112
[719]113    } 
114    else if( count( $time_fields ) == 1 ) 
115    {
[732]116        $hours   = 0;
117        $minutes = 0;
118        $seconds = $time_fields[0];
[719]119    }
[128]120
[732]121    $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
[128]122
[719]123    return $myepoch;
[120]124}
125
[328]126function colorRed( $color ) 
127{
[719]128    return substr( $color, 0, 2 );
[114]129}
[328]130
131function colorGreen( $color ) 
132{
[719]133    return substr( $color, 2, 2 );
[114]134}
[328]135
136function colorBlue( $color ) 
137{
[719]138    return substr( $color, 4, 2 );
[114]139}
140
[328]141function colorDiffer( $first, $second ) 
142{
[719]143    // Make sure these two colors differ atleast 50 R/G/B
144    $min_diff = 50;
[114]145
[732]146    $c1r   = hexDec( colorRed( $first ) );
147    $c1g   = hexDec( colorGreen( $first ) );
148    $c1b   = hexDec( colorBlue( $first ) );
[114]149
[732]150    $c2r   = hexDec( colorRed( $second ) );
151    $c2g   = hexDec( colorGreen( $second ) );
152    $c2b   = hexDec( colorBlue( $second ) );
[114]153
[732]154    $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
155    $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
156    $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
[114]157
[719]158    if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) 
159    {
160        return TRUE;
[328]161
[719]162    } 
163    else 
164    {
165        return FALSE;
166    }
[114]167}
168
[328]169function randomColor( $known_colors ) 
170{
[719]171    // White (000000) would be invisible
[732]172    $start       = "004E00";
[719]173   
[732]174    $start_red   = colorRed( $start );
175    $start_green = colorGreen( $start );
176    $start_blue  = colorBlue( $start );
[719]177   
[732]178    $end         = "FFFFFF";
[114]179
[732]180    $end_red     = colorRed( $end );
181    $end_green   = colorGreen( $end );
[719]182    $end_blue    = colorBlue( $end );
[114]183
[732]184    $change_color= TRUE;
[114]185
[719]186    while( $change_color ) 
187    {
[732]188        $change_color= FALSE;
[114]189
[719]190        $new_red     = rand( hexDec( $start_red ), hexDec( $end_red ) );
[732]191        $new_green   = rand( hexDec( $start_green ), hexDec( $end_green ) );
192        $new_blue    = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
[114]193
[719]194        $new         = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
[114]195
[719]196        foreach( $known_colors as $old )
197        {
198            if( !colorDiffer( $new, $old ) )
199            {
200                 $change_color = TRUE;
201            }
202        }
203    }
[114]204
[719]205    // Whoa! Actually found a good color ;)
206    return $new;
[114]207}
208
[328]209function sortJobs( $jobs, $sortby, $sortorder ) 
210{
[719]211    $sorted    = array();
[114]212
[719]213    if( isset( $jobs ) && count( $jobs ) > 0 ) 
214    {
215        foreach( $jobs as $jobid => $jobattrs ) 
216        {
[732]217                $state     = $jobattrs['status'];
218                $owner     = $jobattrs['owner'];
219                $queue     = $jobattrs['queue'];
220                $name      = $jobattrs['name'];
221                $req_cpu   = $jobattrs['requested_time'];
222                $req_memory= $jobattrs['requested_memory'];
[117]223
[719]224                if( $state == 'R' )
225                {
226                    $nodes = count( $jobattrs['nodes'] );
227                }
228                else
229                {
230                    $nodes = $jobattrs['nodes'];
231                }
[117]232
[719]233                $ppn         = (int) $jobattrs['ppn'] ? $jobattrs['ppn'] : 1;
[731]234                $cpus        = $nodes * $ppn;
235                $queued_time = (int) $jobattrs['queued_timestamp'];
236                $start_time  = (int) $jobattrs['start_timestamp'];
237                $runningtime = $report_time - $start_time;
[117]238
[719]239                switch( $sortby ) 
240                {
241                    case "id":
242                        $sorted[$jobid] = $jobid;
243                        break;
[117]244
[719]245                    case "state":
246                        $sorted[$jobid] = $state;
247                        break;
[117]248
[719]249                    case "owner":
250                        $sorted[$jobid] = $owner;
251                        break;
[117]252
[719]253                    case "queue":
254                        $sorted[$jobid] = $queue;
255                        break;
[117]256
[719]257                    case "name":
258                        $sorted[$jobid] = $name;
259                        break;
[117]260
[719]261                    case "req_cpu":
262                        $sorted[$jobid] = timeToEpoch( $req_cpu );
263                        break;
[117]264
[719]265                    case "req_mem":
266                        $sorted[$jobid] = $req_memory;
267                        break;
[117]268
[719]269                    case "nodes":
270                        $sorted[$jobid] = $nodes;
271                        break;
[117]272
[719]273                    case "cpus":
274                        $sorted[$jobid] = $cpus;
275                        break;
[245]276
[719]277                    case "queued":
278                        $sorted[$jobid] = $queued_time;
279                        break;
[117]280
[719]281                    case "start":
282                        $sorted[$jobid] = $start_time;
283                        break;
[117]284
[719]285                    case "runningtime":
286                        $sorted[$jobid] = $runningtime;
287                        break;
[117]288
[719]289                    default:
290                        break;
291                }
292        }
293    }
[301]294
[719]295    if( $sortorder == "asc" )
296    {
[818]297        asort( $sorted );
[719]298    }
299    else if( $sortorder == "desc" )
300    {
[818]301        arsort( $sorted );
[719]302    }
[117]303
[719]304    return $sorted;
[117]305}
306
[328]307function makeOverview() 
308{
[753]309    global $dwoo, $tpl, $tpl_data, $jobs, $nodes, $heartbeat, $clustername, $tpl_data;
[719]310    global $sortorder, $sortby, $filter, $sh, $hc, $m, $range;
311    global $cluster_url, $get_metric_string, $host_url, $metrics;
312    global $start, $end, $reports, $gnodes, $default_showhosts;
313    global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname;
[764]314    global $cluster, $use_fqdn, $myxml_data, $data_gatherer;
[126]315
[719]316    $metricname        = $m;
[731]317    if( isset($conf['default_metric']) and ($metricname =='') )
318        $metricname = $conf['default_metric'];
319    else
320        if( isset( $m ) )
321            $metricname = $m;
322        else
323            $metricname = "load_one";
[328]324
[822]325    $tpl_data["sortorder"]= $sortorder;
326    $tpl_data["sortby"]= $sortby;
[117]327
[732]328    $sorted_jobs        = sortJobs( $jobs, $sortby, $sortorder );
[117]329
[732]330    $even               = 1;
[118]331
[732]332    $used_jobs          = 0;
333    $used_cpus          = 0;
[719]334    $used_nodes         = 0;
[124]335
[732]336    $queued_jobs        = 0;
337    $queued_nodes       = 0;
338    $queued_cpus        = 0;
[208]339
[732]340    $total_nodes        = 0;
[719]341    $total_cpus         = 0;
342    $total_jobs         = 0;
[208]343
[719]344    $all_used_nodes     = array();
[732]345    $total_used_nodes   = array();
[124]346
[732]347    $running_name_nodes = array();
[208]348
[732]349    $running_nodes      = 0;
350    $running_jobs       = 0;
351    $running_cpus       = 0;
[208]352
[732]353    $avail_nodes        = count( $gnodes );
[719]354    $avail_cpus         = cluster_sum("cpu_num", $metrics);
[135]355
[732]356    $view_cpus          = 0;
357    $view_jobs          = 0;
[719]358    $view_nodes         = 0;
[135]359
[732]360    $all_nodes          = 0;
361    $all_jobs           = 0;
362    $all_cpus           = 0;
[135]363
[732]364    $view_name_nodes    = array();
[208]365
[719]366    // Is the "requested memory" column enabled in the config
367    //
368    if( $COLUMN_REQUESTED_MEMORY ) 
369    {
[822]370        $tpl_data[ "column_header_req_mem"]= "yes";
[719]371    }
[241]372
[719]373    // Is the "nodes hostnames" column enabled in the config
374    //
375    if( $COLUMN_NODES ) 
376    {
[822]377        $tpl_data[ "column_header_nodes"]= "yes";
[719]378    }
[299]379
[719]380    // Is the "queued time" column enabled in the config
381    //
382    if( $COLUMN_QUEUED ) 
383    {
[822]384        $tpl_data[ "column_header_queued"]= "yes" ;
[719]385    }
[242]386
[732]387    $last_displayed_job = null;
[263]388
[732]389    $rjqj_host = null;
[406]390
[732]391    $na_nodes  = 0;
392    $na_cpus   = 0;
[512]393
[719]394    foreach( $metrics as $bhost => $bmetric )
395    {
396        foreach( $bmetric as $mname => $mval )
397        {
[726]398            if( ( $mname == 'zplugin_monarch_rj' ) || ($mname == 'zplugin_monarch_qj') )
[719]399            {
[732]400                $rjqj_host = $bhost;
[719]401            }
402        }
403    }
[409]404
[719]405    foreach( $gnodes as $ghost => $gnode )
406    {
407        if( $gnode->isDown() || $gnode->isOffline() )
408        {
[732]409            $na_nodes += 1;
410            $na_cpus  += $metrics[$ghost]['cpu_num']['VAL'];
[719]411        }
412    }
[516]413
[753]414    $node_list = array();
[409]415
[719]416    foreach( $sorted_jobs as $jobid => $sortdec ) 
417    {
418        $report_time     = $jobs[$jobid]['reported'];
[117]419
[719]420        if( $jobs[$jobid]['status'] == 'R' )
421        {
422            $nodes = count( $jobs[$jobid]['nodes'] );
423        }
424        else if( $jobs[$jobid]['status'] == 'Q' )
425        {
426            $nodes = $jobs[$jobid]['nodes'];
427        }
[208]428
[732]429        $ppn  = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
430        $cpus = $nodes * $ppn;
[124]431
[719]432        if( $report_time == $heartbeat ) 
433        {
434            $display_job    = 1;
[124]435
[719]436            if( $jobs[$jobid]['status'] == 'R' ) 
437            {
438                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
439                {
440                    $all_used_nodes[] = $tempnode;
441                }
442            }
[208]443
[719]444            $used_cpus += $cpus;
[135]445
[719]446            if( $jobs[$jobid]['status'] == 'R' ) 
447            {
448                $running_cpus     += $cpus;
[328]449
[719]450                $running_jobs++;
[117]451
[719]452                $found_node_job    = 0;
[268]453
[719]454                foreach( $jobs[$jobid]['nodes'] as $tempnode ) 
455                {
456                    $running_name_nodes[] = $tempnode;
[263]457
[874]458                    $hostnode = $data_gatherer->makeHostname( $tempnode, $jobs[$jobid]['domain'] );
459
[719]460                    if( isset( $hostname ) && $hostname != '' ) 
461                    {
462                        if( $hostname == $hostnode ) 
463                        {
464                            $found_node_job = 1;
465                            $display_job = 1;
466                        } 
467                        else if( !$found_node_job ) 
468                        {
469                            $display_job = 0;
470                        }
471                    }
472                }
473            }
[117]474
[719]475            if( $jobs[$jobid]['status'] == 'Q' ) 
476            {
477                if( isset( $hostname ) && $hostname != '' )
478                {
479                    $display_job = 0;
480                }
[263]481
[732]482                $queued_cpus  += $cpus;
483                $queued_nodes += $nodes;
[328]484
[719]485                $queued_jobs++;
486            }
[208]487
[719]488            foreach( $filter as $filtername=>$filtervalue ) 
489            {
490                if( $filtername == 'id' && $jobid != $filtervalue )
491                {
492                    $display_job = 0;
493                }
494                else if( $filtername == 'state' && $jobs[$jobid]['status'] != $filtervalue )
495                {
496                    $display_job = 0;
497                }
498                else if( $filtername == 'queue' && $jobs[$jobid]['queue'] != $filtervalue )
499                {
500                    $display_job = 0;
501                }
502                else if( $filtername == 'owner' && $jobs[$jobid]['owner'] != $filtervalue )
503                {
504                    $display_job = 0;
505                }
506            }
[118]507
[753]508
[719]509            if( $display_job ) 
510            {
[816]511                unset( $job_loop );
[753]512                $job_loop = array();
513                $job_loop["clustername"] = $clustername;
[263]514
[753]515                $job_loop["id"] = $jobid;
516
[719]517                $last_displayed_job     = $jobid;
[263]518
[753]519                $job_loop["state"] = $jobs[$jobid]['status'];
[240]520
[719]521                $fullstate         = '';
[328]522
[719]523                if( $jobs[$jobid]['status'] == 'R' ) 
524                {
525                    $fullstate     = "Running";
526                } 
527                else if( $jobs[$jobid]['status'] == 'Q' ) 
528                {
529                    $fullstate     = "Queued";
530                }
[240]531
[753]532                $job_loop["fullstate"] = $fullstate;
[719]533               
[753]534                $job_loop["owner"] = $jobs[$jobid]['owner'];
535                $job_loop["queue"] = $jobs[$jobid]['queue'];
[240]536
[719]537                $fulljobname         = $jobs[$jobid]['name'];
[753]538                $shortjobname        = '';
[240]539
[753]540                $job_loop["fulljobname"] = $fulljobname;
[240]541
[719]542                $fulljobname_fields    = explode( ' ', $fulljobname );
[311]543
[719]544                $capjobname        = 0;
[311]545
[719]546                if( strlen( $fulljobname_fields[0] ) > 10 )
547                {
548                    $capjobname    = 1;
549                }
[311]550
[719]551                if( $capjobname ) 
552                {
[753]553                    $job_loop[ "jobname_hint_start" ] = "yes";
[240]554
[719]555                    $shortjobname     = substr( $fulljobname, 0, 10 ) . '..';
556                } 
557                else 
558                {
559                    $shortjobname     = $fulljobname;
560                }
561               
[753]562                $job_loop["name"] = $shortjobname;
[240]563
[719]564                if( $capjobname ) 
565                {
[753]566                    $job_loop[ "jobname_hint_end" ] = "yes";
[719]567                }
[240]568
[719]569                $domain         = $jobs[$jobid]['domain'];
[135]570
[753]571                $job_loop["req_cpu"] = makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) );
[328]572
[719]573                if( $COLUMN_REQUESTED_MEMORY ) 
574                {
[753]575                    $job_loop[ "column_req_mem" ] = "yes";
576                    $job_loop["req_memory"] = $jobs[$jobid]['requested_memory'];
[719]577                }
[135]578
[299]579
[719]580                if( $COLUMN_QUEUED ) 
581                {
[753]582                    $job_loop[ "column_queued" ] = "yes";
583                    $job_loop["queued"] = makeDate( $jobs[$jobid]['queued_timestamp'] );
[719]584                }
585                if( $COLUMN_NODES ) 
586                {
[753]587                    $job_loop[ "column_nodes" ] = "yes";
588                    //echo "colum nodes";
[719]589                }
[242]590
[732]591                $ppn       = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
592                $cpus      = $nodes * $ppn;
[119]593
[753]594                $job_loop["nodes"] = $nodes;
595                $job_loop["cpus"] = $cpus;
[328]596
[732]597                $start_time= (int) $jobs[$jobid]['start_timestamp'];
598                $job_start = $start_time;
[328]599
[738]600
[732]601                $view_cpus += $cpus;
[328]602
[719]603                $view_jobs++;
[124]604
[719]605                if( $jobs[$jobid]['status'] == 'R' ) 
606                {
[763]607                    $job_runningtime    = $heartbeat - $start_time;
[738]608                    if( $rjqj_start == null ) 
609                    {
[763]610                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
[738]611                    }
612                    else if( $start_time < $rjqj_start )
613                    {
[763]614                        $rjqj_start = intval( $start_time - (intval( $job_runningtime * 0.10 ) ) );
[738]615                    }
616
[719]617                    foreach( $jobs[$jobid]['nodes'] as $tempnode )
618                    {
619                        $view_name_nodes[]     = $tempnode;
620                    }
[299]621
[719]622                    if( $COLUMN_NODES ) 
623                    {
[753]624                        $job_loop[ "column_nodes" ] = "yes";
[328]625
[719]626                        $mynodehosts         = array();
[328]627
[730]628                        foreach( $jobs[$jobid]['nodes'] as $shortnode ) 
[719]629                        {
[874]630                            $domain         = $jobs[$jobid]['domain'];
631                            $mynode         = $data_gatherer->makeHostname( $shortnode, $domain );
[732]632                            $myhost_href    = "./?c=".$clustername."&h=".$mynode;
633                            $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
[719]634                        }
[328]635
[732]636                        $nodes_hostnames    = implode( " ", $mynodehosts );
[328]637
[753]638                        $job_loop["nodes_hostnames"] = $nodes_hostnames;
[719]639                    }
640                } 
641                else if( $jobs[$jobid]['status'] == 'Q' ) 
642                {
643                    $view_nodes     += (int) $jobs[$jobid]['nodes'];
644                }
[135]645
[719]646                if( $even ) 
647                {
[753]648                    $job_loop["nodeclass"] = "even";
[119]649
[719]650                    $even         = 0;
651                } 
652                else 
653                {
[753]654                    $job_loop["nodeclass"] = "odd";
[119]655
[719]656                    $even         = 1;
657                }
[119]658
[719]659                if( $start_time ) 
660                {
[732]661                    $runningtime        = makeTime( $report_time - $start_time );
[719]662                    $job_runningtime    = $heartbeat - $start_time;
[119]663
[753]664                    $job_loop["started"] = makeDate( $start_time );
665                    $job_loop["runningtime"] = $runningtime;
[719]666                }
[815]667                $node_list[] = &$job_loop;
[719]668            }
[822]669            $tpl_data["node_list"]= &$node_list ;
[719]670        }
671    }
[763]672    if( intval($view_jobs) == 1 and $start_time )
673    {
674        if( $last_displayed_job != null )
675        {
676            $filter['id'] = $last_displayed_job;
677        }
678    }
[738]679    // Running / queued amount jobs graph
680    //
681    if( $rjqj_host != null )
682    {
[761]683        $rjqj_graphargs = "?z=overview-medium&c=$clustername&h=$rjqj_host&g=job_report&r=$range";
[738]684        if( $range == 'job' )
685        {
686            $rjqj_end = time();
[768]687
688            if( $rjqj_start == null ) 
689            { // probably no running jobs in this view: only queued
690                $rjqj_start = $rjqj_end - (24 * 3600); // default to 1 day
691            }
[758]692            $rjqj_title = rawurlencode( makeTime( ($rjqj_end - $rjqj_start) ) );
693            $rjqj_graphargs .= "&period_start=$rjqj_start&period_stop=$rjqj_end&t=$rjqj_title";
[738]694        }
695        else
696        {
697            $rjqj_graphargs .= "&st=$cluster[LOCALTIME]";
698        }
[763]699        if( intval($view_jobs) == 1 and $start_time )
700        {
701            $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
702            $rjqj_graphargs .= "&job_start=$start_time";
703        }
[208]704
[738]705        $rjqj_str  = "<A HREF=\"./graph.php$rjqj_graphargs\">";
[796]706        $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php$rjqj_graphargs\">";
[738]707        $rjqj_str .= "</A>";
708
[822]709        $tpl_data[ "rjqj_graph"]= $rjqj_str ;
[738]710    }
711
[719]712    $all_used_nodes     = array_unique( $all_used_nodes );
[732]713    $view_name_nodes    = array_unique( $view_name_nodes );
714    $running_name_nodes = array_unique( $running_name_nodes );
[124]715
[719]716    $used_nodes         = count( $all_used_nodes );
[732]717    $view_nodes        += count( $view_name_nodes );
718    $running_nodes     += count( $running_name_nodes );
[208]719
[732]720    $total_nodes        = $queued_nodes + $running_nodes;
[719]721    $total_cpus         = $queued_cpus + $running_cpus;
722    $total_jobs         = $queued_jobs + $running_jobs;
[135]723
[719]724    $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
[732]725    $free_nodes         = ( $free_nodes >= 0 ) ? $free_nodes : 0;
726    $free_cpus          = $avail_cpus - $running_cpus - $na_cpus;
727    $free_cpus          = ( $free_cpus >= 0 ) ? $free_cpus : 0;
[208]728
[822]729    $tpl_data[ "avail_nodes"]= $avail_nodes ;
730    $tpl_data[ "avail_cpus"]= $avail_cpus ;
[208]731
[822]732    $tpl_data[ "queued_nodes"]= $queued_nodes ;
733    $tpl_data[ "queued_jobs"]= $queued_jobs ;
734    $tpl_data[ "queued_cpus"]= $queued_cpus ;
[208]735
[719]736    // Only display "Unavailable" in count overview there are any
737    //
738    if( $na_nodes > 0 )
739    {
[875]740        $tpl_data[ "show_na_nodes"]= "yes";
[512]741
[822]742        $tpl_data[ "na_nodes"]= $na_nodes ;
743        $tpl_data[ "na_cpus"]= $na_cpus ;
[719]744    }
[517]745
[822]746    $tpl_data[ "total_nodes"]= $total_nodes ;
747    $tpl_data[ "total_jobs"]= $total_jobs ;
748    $tpl_data[ "total_cpus"]= $total_cpus ;
[135]749
[822]750    $tpl_data[ "running_nodes"]= $running_nodes ;
751    $tpl_data[ "running_jobs"]= $running_jobs ;
752    $tpl_data[ "running_cpus"]= $running_cpus ;
[208]753
[822]754    $tpl_data[ "used_nodes"]= $used_nodes ;
755    $tpl_data[ "used_jobs"]= $used_jobs ;
756    $tpl_data[ "used_cpus"]= $used_cpus ;
[208]757
[822]758    $tpl_data[ "free_nodes"]= $free_nodes ;
759    $tpl_data[ "free_cpus"]= $free_cpus ;
[135]760
[822]761    $tpl_data[ "view_nodes"]= $view_nodes ;
762    $tpl_data[ "view_jobs"]= $view_jobs ;
763    $tpl_data[ "view_cpus"]= $view_cpus ;
[126]764
[822]765    $tpl_data[ "report_time"]= makeDate( $heartbeat);
[328]766
[263]767
[719]768    global $longtitle, $title;
[406]769
[719]770    $longtitle = "Batch Report :: Powered by Job Monarch!";
771    $title = "Batch Report";
[406]772
[719]773    makeHeader( 'overview', $title, $longtitle );
[406]774
[719]775    setupFilterSettings();
[263]776
[719]777    if( intval($view_jobs) == 1 and $start_time )
778    {
[822]779        $tpl_data[ "showhosts"]= "yes" ;
[126]780
[719]781        $showhosts     = isset($sh) ? $sh : $default_showhosts;
[126]782
[822]783        $tpl_data[ "checked$showhosts"]= "checked" ;
[126]784
[753]785        $sorted_list = array();
786
[719]787        if( $showhosts )
788        {
789            if( !isset( $start ) )
790            {
791                $start    ="jobstart";
792            }
793            if( !isset( $stop ) )
794            {
795                $stop    ="now";
796            }
[126]797
[731]798            $sorted_hosts = array();
[719]799            $hosts_up     = $jobs[$filter['id']]['nodes'];
[126]800
[731]801            $r            = intval($job_runningtime * 1.2);
[126]802
[719]803            $jobrange     = -$r ;
804            $jobstart     = $start_time;
[402]805
[719]806            if ( $reports[$metricname] )
807            {
808                $metricval     = "g";
809            }
810            else
811            {
812                $metricval    = "m";
813            }
814               
815            foreach ( $hosts_up as $host )
816            {
[874]817                $host             = $data_gatherer->makeHostname( $host, $domain );
[195]818
[733]819                $cpus             = 0;
[328]820
[719]821                $cpus             = $metrics[$host]["cpu_num"]["VAL"];
[328]822
[733]823                if( $cpus == 0 )
[719]824                {
825                    $cpus        = 1;
826                }
[328]827
[719]828                $load_one         = $metrics[$host]["load_one"]['VAL'];
829                $load             = ((float) $load_one) / $cpus;
[731]830                $host_load[$host] = $load;
[328]831
[719]832                $percent_hosts[load_color($load)] ++;
[328]833
[719]834                if ($metricname=="load_one")
835                {
836                    $sorted_hosts[$host]     = $load;
837                }
838                else
839                {
840                    $sorted_hosts[$host]     = $metrics[$host][$metricname]['VAL'];
841                }
842            }
[463]843
[719]844            switch ( $sort )
845            {
846                case "descending":
847                    arsort( $sorted_hosts );
848                    break;
[328]849
[719]850                case "by hostname":
851                    ksort( $sorted_hosts );
852                    break;
[328]853
[719]854                case "ascending":
855                    asort( $sorted_hosts );
856                    break;
[328]857
[719]858                default:
859                    break;
860            }
[126]861
[719]862            // First pass to find the max value in all graphs for this
863            // metric. The $start,$end variables comes from get_context.php,
864            // included in index.php.
865            //
866            list($min, $max) = find_limits($sorted_hosts, $metricname);
[126]867
[719]868            // Second pass to output the graphs or metrics.
869            $i = 1;
[126]870
[753]871            $metric_loop = array();
[719]872            foreach ( $sorted_hosts as $host=>$value  )
873            {
[731]874                $host_url    = rawurlencode( $host );
875                $cluster_url = rawurlencode( $clustername );
[193]876
[719]877                $textval     = "";
[328]878
[719]879                $val         = $metrics[$host][$metricname];
[731]880                $class       = "metric";
[328]881
[719]882                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
883                {
884                    $textval     = date( "r", $val["VAL"] );
885                }
886                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
887                {
888                    $textval     = $val["VAL"] . " " . $val["UNITS"];
889                }
890                else
891                {
[731]892                    $job_start     = $jobs[$last_displayed_job]['start_timestamp'];
[805]893                    $period_end    = $cluster['LOCALTIME'];
894                    $runningtime   = intval( $period_end ) - intval( $job_start );
[719]895                    $load_color    = load_color($host_load[$host]);
[731]896                    $period_start  = intval( $job_start - (intval( $runningtime * 0.10 ) ) );
897                    //printf("last job %s job start %s runningtime %s period start %s", $last_displayed_job, $jobstart, $job_runningtime, $period_start);
[719]898                    $graphargs     = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
[823]899                    $graphargs    .= "z=overview-medium&c=$cluster_url&r=$range&h=$host_url&l=$load_color&v=".$val['VAL']."&job_start=$job_start&vl=".$val['UNITS'];
[739]900                    $host_link     = "?j_view=overview-host&c=$cluster_url&r=$range&h=$host_url&job_start=$jobstart";
901
902                    if( $range == 'job' )
903                    {
904                        $graphargs     .= "&period_start=$period_start&period_stop=$period_end";
905                        $host_link     .= "&period_start=$period_start&period_stop=$period_end";
906                    }
907                    else
908                    {
909                        $graphargs     .= "&st=$period_end";
910                        $host_link     .= "&st=$period_end";
911                    }
[719]912                    if( $max > 0 )
913                    {
914                        $graphargs    .= "&x=$max&n=$min";
915                    }
916                }
917                if ($textval)
918                {
919                    $cell    = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
920                } else {
[798]921                    $cell    = "<A HREF=\"$host_link\">" . "<IMG SRC=\"./graph.php?$graphargs\" " . "ALT=\"$host\" BORDER=0></A>";
[719]922                }
[126]923
[753]924                $metric_loop["metric_image"] = $cell;
[328]925
[757]926                //if(! ($i++ % $hostcols) )
927                //{
928                //     $metric_loop["br"] = "</tr><tr>";
929                //}
[753]930                $sorted_list[] = $metric_loop;
[719]931            }
[822]932            $tpl_data["sorted_list"]= $sorted_list ;
[719]933        }
934    }
[753]935    $dwoo->output($tpl, $tpl_data);
[114]936}
[753]937
[113]938?>
Note: See TracBrowser for help on using the repository browser.