source: trunk/web/addons/job_monarch/overview.php @ 330

Last change on this file since 330 was 330, checked in by bastiaans, 17 years ago

web/addons/job_monarch/overview.php:

  • removed size setting of clusterimage in html assignment

web/addons/job_monarch/libtoga.php:

  • changed clusterimage width/height determination
  • Property svn:keywords set to Id
File size: 22.1 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 330 2007-04-22 13:51:37Z bastiaans $
[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;
[114]27
[116]28$tpl->assign( "clustername", $clustername );
29
[206]30if( $JOB_ARCHIVE )
[328]31{
[129]32        $tpl->assign( "cluster_url", rawurlencode($clustername) );
[328]33}
[129]34
[328]35$ds             = new DataSource();
36$myxml_data     = $ds->getData();
37
38$data_gatherer  = new DataGatherer( $clustername );
[326]39$data_gatherer->parseXML( $myxml_data );
[117]40
[328]41$heartbeat      = $data_gatherer->getHeartbeat();
42$jobs           = $data_gatherer->getJobs();
43$gnodes         = $data_gatherer->getNodes();
44$cpus           = $data_gatherer->getCpus();
[114]45
[328]46function setupFilterSettings() 
47{
48
[326]49        global $tpl, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data;
[122]50
[263]51        $filter_image_url = "";
[119]52
[263]53        $tpl->gotoBlock( "_ROOT" );
[122]54
[328]55        foreach( $filter as $filtername => $filtervalue ) 
56        {
[263]57                $tpl->assign( "f_".$filtername, $filtervalue );
[328]58
59                $filter_image_url       .= "&$filtername=$filtervalue";
[263]60        }
[114]61
[326]62        session_start();
63
[328]64        $_SESSION["data"]       = &$myxml_data;
65
66        $ic                     = new ClusterImage( $myxml_data, $clustername );
67
[326]68        $ic->setBig();
69        $ic->setNoimage();
70        $ic->draw();
71
72        $tpl->assign( "clusterimage", "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
73
[330]74        //$tpl->assign( "clusterimage_width", $ic->getWidth() );
75        //$tpl->assign( "clusterimage_height", $ic->getHeight() );
[326]76
77        $tpl->newBlock( "node_clustermap" );
78        $tpl->assign( "node_area_map", $ic->getImagemapArea() );
79        $tpl->gotoBlock( "_ROOT" );
80
[263]81        $tpl->assign( "f_order", $filterorder );
[114]82
[328]83        if( array_key_exists( "id", $filter ) ) 
84        {
[263]85                $piefilter = 'id';
[328]86        } 
87        else if( array_key_exists( "user", $filter ) ) 
88        {
[263]89                $piefilter = 'user';
[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();
254                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
255                $job_cpu        = 0;
[114]256
[328]257                foreach( $myjobs as $myjob ) 
258                {
[315]259                        $job_cpu        += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
260                }
261
262                $node_freecpu   = $node_cpus - $job_cpu;
263
264                $empty_cpus     += $node_freecpu;
[114]265        }
266
[315]267        $used_cpus              = $nr_cpus - $empty_cpus;
[114]268
[315]269        $empty_percentage       = ($empty_cpus / $nr_cpus) * 100;
[114]270
[315]271        $qcolors                = array();
272        $color                  = randomColor( $qcolors );
273        $qcolors[]              = $color;
274        $pie_args               .= "&free=$empty_percentage,$color";
275
[127]276        if( isset( $piefilter ) )
[328]277        {
[127]278                $filterpie = array();
[328]279        }
[127]280
[328]281        foreach( $nodes as $node )
282        {
[315]283                $node_jobs      = $node->getJobs();
284                $nr_node_jobs   = count( $node_jobs );
285                $myhost         = $node->getHostname();
286                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
[114]287
[328]288                foreach( $node_jobs as $myjob )
289                {
[315]290                        $job_cpu                = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
291
292                        // Determine the weight of this job
293                        // - what percentage of the cpus is in use by this job
[123]294                        //
[315]295                        $job_weight[$myjob]     = ( $job_cpu / $nr_cpus );
[123]296
[315]297
[328]298                        if( isset( $piefilter ) ) {
299
[127]300                                $countjob = 1;
[328]301
302                                if( $piefilter == 'id' )
303                                {
[127]304                                        if( $myjob != $filter[$piefilter] )
[328]305                                        {
[127]306                                                $countjob = 0;
[328]307                                        }
308                                }
309                                else if( $piefilter == 'user' )
310                                {
[127]311                                        if( $jobs[$myjob][owner] != $filter[$piefilter] )
[328]312                                        {
[127]313                                                $countjob = 0;
[328]314                                        }
315                                }
316                                else
317                                {
[127]318                                        if( $jobs[$myjob][$piefilter] != $filter[$piefilter] )
[328]319                                        {
[127]320                                                $countjob = 0;
[328]321                                        }
[127]322                                }
323
[328]324                                if( $countjob )
325                                {
[127]326
327                                        if( !isset( $filterpie[$filter[$piefilter]] ) )
[328]328                                        {
[127]329                                                $filterpie[$filter[$piefilter]] = $job_weight[$myjob];
[328]330                                        }
[127]331                                        else
[328]332                                        {
333
[127]334                                                $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob];
[328]335                                        }
336                                }
337                                else
338                                {
[127]339                                        if( !isset( $filterpie["other"] ) )
[328]340                                        {
[127]341                                                $filterpie["other"] = $job_weight[$myjob];
[328]342                                        }
[127]343                                        else
[328]344                                        {
[127]345                                                $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob];
[328]346                                        }
[127]347
348                                }
349                               
[328]350                        }
351                        else
352                        {
[127]353
[315]354                                $qname          = $jobs[$myjob][queue];
355
[127]356                                if( !isset( $queues[$qname] ) )
[328]357                                {
[127]358                                        $queues[$qname] = $job_weight[$myjob];
[328]359                                }
[127]360                                else
[328]361                                {
[127]362                                        $queues[$qname] = $queues[$qname] + $job_weight[$myjob];
[328]363                                }
[127]364                        }
[114]365                }
366        }
367
[127]368        if( isset( $piefilter ) )
[328]369        {
[127]370                $graphvals = $filterpie;
[328]371        }
[127]372        else
[328]373        {
[127]374                $graphvals = $queues;
[328]375        }
[114]376
[328]377        foreach( $graphvals as $name => $totalweight) 
378        {
[315]379                $percentage     = ( $totalweight * 100 );
[123]380               
[315]381                $color          = randomColor( $qcolors );
382                $qcolors[]      = $color;
383                $pie_args       .= "&$name=$percentage,$color";
[114]384        }
385        $pie = "../../pie.php?$pie_args";
386
387        return $pie;
388}
389
390
[328]391function sortJobs( $jobs, $sortby, $sortorder ) 
392{
393        $sorted = array();
[114]394
[328]395        $cmp    = create_function( '$a, $b', 
[117]396                "global \$sortby, \$sortorder;".
[116]397
[117]398                "if( \$a == \$b ) return 0;".
[116]399
[117]400                "if (\$sortorder==\"desc\")".
401                        "return ( \$a < \$b ) ? 1 : -1;".
402                "else if (\$sortorder==\"asc\")".
403                        "return ( \$a > \$b ) ? 1 : -1;" );
404
[328]405        if( isset( $jobs ) && count( $jobs ) > 0 ) 
406        {
407                foreach( $jobs as $jobid => $jobattrs ) 
408                {
409                                $state          = $jobattrs[status];
410                                $user           = $jobattrs[owner];
411                                $queue          = $jobattrs[queue];
412                                $name           = $jobattrs[name];
413                                $req_cpu        = $jobattrs[requested_time];
414                                $req_memory     = $jobattrs[requested_memory];
[117]415
[301]416                                if( $state == 'R' )
[328]417                                {
[301]418                                        $nodes = count( $jobattrs[nodes] );
[328]419                                }
[301]420                                else
[328]421                                {
[301]422                                        $nodes = $jobattrs[nodes];
[328]423                                }
[117]424
[328]425                                $ppn            = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
426                                $cpus           = $nodes * $ppn;
427                                $queued_time    = (int) $jobattrs[queued_timestamp];
428                                $start_time     = (int) $jobattrs[start_timestamp];
429                                $runningtime    = $report_time - $start_time;
[117]430
[328]431                                switch( $sortby ) 
432                                {
[301]433                                        case "id":
434                                                $sorted[$jobid] = $jobid;
435                                                break;
[117]436
[301]437                                        case "state":
438                                                $sorted[$jobid] = $state;
439                                                break;
[117]440
[301]441                                        case "user":
442                                                $sorted[$jobid] = $user;
443                                                break;
[117]444
[301]445                                        case "queue":
446                                                $sorted[$jobid] = $queue;
447                                                break;
[117]448
[301]449                                        case "name":
450                                                $sorted[$jobid] = $name;
451                                                break;
[117]452
[301]453                                        case "req_cpu":
454                                                $sorted[$jobid] = timeToEpoch( $req_cpu );
455                                                break;
[117]456
[301]457                                        case "req_mem":
458                                                $sorted[$jobid] = $req_memory;
459                                                break;
[117]460
[301]461                                        case "nodes":
462                                                $sorted[$jobid] = $nodes;
463                                                break;
[117]464
[301]465                                        case "cpus":
466                                                $sorted[$jobid] = $cpus;
467                                                break;
[245]468
[301]469                                        case "queued":
470                                                $sorted[$jobid] = $queued_time;
471                                                break;
[117]472
[301]473                                        case "start":
474                                                $sorted[$jobid] = $start_time;
475                                                break;
[117]476
[301]477                                        case "runningtime":
478                                                $sorted[$jobid] = $runningtime;
479                                                break;
[117]480
[301]481                                        default:
482                                                break;
483                                }
484                }
485        }
486
[128]487        if( $sortorder == "asc" )
[328]488        {
[128]489                arsort( $sorted );
[328]490        }
[128]491        else if( $sortorder == "desc" )
[328]492        {
[128]493                asort( $sorted );
[328]494        }
[117]495
496        return $sorted;
497}
498
[328]499function makeOverview() 
500{
[117]501        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
[126]502        global $sortorder, $sortby, $filter, $sh, $hc, $m;
503        global $cluster_url, $get_metric_string, $host_url, $metrics;
[129]504        global $start, $end, $reports, $gnodes, $default_showhosts;
[299]505        global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname;
[126]506
[328]507        $metricname             = $m;
508
[117]509        $tpl->assign("sortorder", $sortorder );
510        $tpl->assign("sortby", $sortby );
511
[328]512        $sorted_jobs            = sortJobs( $jobs, $sortby, $sortorder );
[117]513
[328]514        $even                   = 1;
[118]515
[328]516        $used_jobs              = 0;
517        $used_cpus              = 0;
518        $used_nodes             = 0;
[124]519
[328]520        $queued_jobs            = 0;
521        $queued_nodes           = 0;
522        $queued_cpus            = 0;
[208]523
[328]524        $total_nodes            = 0;
525        $total_cpus             = 0;
526        $total_jobs             = 0;
[208]527
[328]528        $all_used_nodes         = array();
529        $total_used_nodes       = array();
[124]530
[328]531        $running_name_nodes     = array();
[208]532
[328]533        $running_nodes          = 0;
534        $running_jobs           = 0;
535        $running_cpus           = 0;
[208]536
[328]537        $avail_nodes            = count( $gnodes );
538        $avail_cpus             = cluster_sum("cpu_num", $metrics);
[135]539
[328]540        $view_cpus              = 0;
541        $view_jobs              = 0;
542        $view_nodes             = 0;
[135]543
[328]544        $all_nodes              = 0;
545        $all_jobs               = 0;
546        $all_cpus               = 0;
[135]547
[328]548        $view_name_nodes        = array();
[208]549
[328]550        if( $COLUMN_REQUESTED_MEMORY ) 
551        {
[242]552                $tpl->newBlock( "column_header_req_mem" );
[241]553        }
554
[328]555        if( $COLUMN_NODES ) 
556        {
[299]557                $tpl->newBlock( "column_header_nodes" );
558        }
559
[328]560        if( $COLUMN_QUEUED ) 
561        {
[242]562                $tpl->newBlock( "column_header_queued" );
563        }
564
[328]565        $last_displayed_job     = null;
[263]566
[328]567        foreach( $sorted_jobs as $jobid => $sortdec ) 
568        {
569                $report_time    = $jobs[$jobid][reported];
[117]570
[208]571                if( $jobs[$jobid][status] == 'R' )
[328]572                {
[208]573                        $nodes = count( $jobs[$jobid][nodes] );
[328]574                }
[208]575                else if( $jobs[$jobid][status] == 'Q' )
[328]576                {
[208]577                        $nodes = $jobs[$jobid][nodes];
[328]578                }
[208]579
[328]580                $ppn            = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
581                $cpus           = $nodes * $ppn;
[124]582
[328]583                if( $report_time == $heartbeat ) 
584                {
585                        $display_job    = 1;
[124]586
[328]587                        if( $jobs[$jobid][status] == 'R' ) 
588                        {
589                                foreach( $jobs[$jobid][nodes] as $tempnode ) 
590                                {
[300]591                                        $all_used_nodes[] = $tempnode;
592                                }
593                        }
[208]594
[135]595                        $used_cpus += $cpus;
596
[328]597                        if( $jobs[$jobid][status] == 'R' ) 
598                        {
599                                $running_cpus   += $cpus;
600
[208]601                                $running_jobs++;
[117]602
[328]603                                $found_node_job = 0;
[268]604
[328]605                                foreach( $jobs[$jobid][nodes] as $tempnode ) 
606                                {
[208]607                                        $running_name_nodes[] = $tempnode;
[263]608
[328]609                                        if( isset( $hostname ) && $hostname != '' ) 
610                                        {
[263]611                                                //$filter[host] = $hostname;
612
[328]613                                                $domain_len     = 0 - strlen( $jobs[$jobid][domain] );
614                                                $hostnode       = $tempnode;
615
616                                                if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) 
617                                                {
[263]618                                                        $hostnode = $hostnode. '.'. $jobs[$jobid][domain];
619                                                }
620
[328]621                                                if( $hostname == $hostnode ) 
622                                                {
[268]623                                                        $found_node_job = 1;
624                                                        $display_job = 1;
[328]625                                                } 
626                                                else if( !$found_node_job ) 
627                                                {
[263]628                                                        $display_job = 0;
[268]629                                                }
[297]630                                        }
[263]631                                }
[208]632                        }
[117]633
[328]634                        if( $jobs[$jobid][status] == 'Q' ) 
635                        {
[263]636                                if( isset( $hostname ) && $hostname != '' )
[328]637                                {
[263]638                                        $display_job = 0;
[328]639                                }
[263]640
[328]641                                $queued_cpus    += $cpus;
642                                $queued_nodes   += $nodes;
643
[208]644                                $queued_jobs++;
645                        }
646
[328]647                        foreach( $filter as $filtername=>$filtervalue ) 
648                        {
[124]649                                if( $filtername == 'id' && $jobid != $filtervalue )
[328]650                                {
[124]651                                        $display_job = 0;
[328]652                                }
[124]653                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
[328]654                                {
[124]655                                        $display_job = 0;
[328]656                                }
[124]657                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
[328]658                                {
[124]659                                        $display_job = 0;
[328]660                                }
[124]661                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
[328]662                                {
[124]663                                        $display_job = 0;
[328]664                                }
[118]665                        }
666
[328]667                        if( $display_job ) 
668                        {
669                                $tpl->newBlock( "node" );
[119]670                                $tpl->assign( "clustername", $clustername );
[328]671                                $tpl->assign( "id", $jobid );
[263]672
[328]673                                $last_displayed_job     = $jobid;
[263]674
[328]675                                $tpl->assign( "state", $jobs[$jobid][status] );
[240]676
[328]677                                $fullstate              = '';
678
679                                if( $jobs[$jobid][status] == 'R' ) 
680                                {
681                                        $fullstate      = "Running";
682                                } 
683                                else if( $jobs[$jobid][status] == 'Q' ) 
684                                {
685                                        $fullstate      = "Queued";
[240]686                                }
687
[328]688                                $tpl->assign( "fullstate", $fullstate );
[240]689                               
[328]690                                $tpl->assign( "user", $jobs[$jobid][owner] );
691                                $tpl->assign( "queue", $jobs[$jobid][queue] );
[240]692
[328]693                                $fulljobname            = $jobs[$jobid][name];
694                                $shortjobname           = '';
[240]695
[328]696                                $tpl->assign( "fulljobname", $fulljobname );
[240]697
[311]698                                $fulljobname_fields     = explode( ' ', $fulljobname );
699
[328]700                                $capjobname             = 0;
[311]701
702                                if( strlen( $fulljobname_fields[0] ) > 10 )
[328]703                                {
[311]704                                        $capjobname     = 1;
[328]705                                }
[311]706
[328]707                                if( $capjobname ) 
708                                {
709                                        $tpl->newBlock( "jobname_hint_start" );
710                                        $tpl->gotoBlock( "node" );
[240]711
[328]712                                        $shortjobname   = substr( $fulljobname, 0, 10 ) . '..';
713                                } 
714                                else 
715                                {
716                                        $shortjobname   = $fulljobname;
[240]717                                }
718                               
[328]719                                $tpl->assign( "name", $shortjobname );
[240]720
[328]721                                if( $capjobname ) 
722                                {
723                                        $tpl->newBlock( "jobname_hint_end" );
724                                        $tpl->gotoBlock( "node" );
[240]725                                }
726
[328]727                                $domain                 = $jobs[$jobid][domain];
[135]728
[328]729                                $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
730
731                                if( $COLUMN_REQUESTED_MEMORY ) 
732                                {
[241]733                                        $tpl->newBlock( "column_req_mem" );
734                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
735                                        $tpl->gotoBlock( "node" );
736                                }
[135]737
[299]738
[328]739                                if( $COLUMN_QUEUED ) 
740                                {
[242]741                                        $tpl->newBlock( "column_queued" );
[243]742                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
[242]743                                        $tpl->gotoBlock( "node" );
744                                }
[328]745                                if( $COLUMN_NODES ) 
746                                {
[322]747                                        $tpl->newBlock( "column_nodes" );
748                                        $tpl->gotoBlock( "node" );
749                                }
[242]750
[328]751                                $ppn                    = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
752                                $cpus                   = $nodes * $ppn;
[119]753
[328]754                                $tpl->assign( "nodes", $nodes );
755                                $tpl->assign( "cpus", $cpus );
756
757                                $start_time             = (int) $jobs[$jobid][start_timestamp];
758                                $job_start              = $start_time;
759
760                                $view_cpus              += $cpus;
761
[135]762                                $view_jobs++;
[124]763
[328]764                                if( $jobs[$jobid][status] == 'R' ) 
765                                {
[135]766                                        foreach( $jobs[$jobid][nodes] as $tempnode )
[328]767                                        {
768                                                $view_name_nodes[]      = $tempnode;
769                                        }
[299]770
[328]771                                        if( $COLUMN_NODES ) 
772                                        {
[322]773                                                $tpl->gotoBlock( "column_nodes" );
[328]774
775                                                $mynodehosts            = array();
776
777                                                foreach( $jobs[$jobid][nodes] as $mynode ) 
778                                                {
779                                                        $myhost_href    = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain];
780                                                        $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$mynode."</A>";
[302]781                                                }
[328]782
783                                                $nodes_hostnames        = implode( " ", $mynodehosts );
784
[299]785                                                $tpl->assign( "nodes_hostnames", $nodes_hostnames );
786                                                $tpl->gotoBlock( "node" );
787                                        }
[328]788                                } 
789                                else if( $jobs[$jobid][status] == 'Q' ) 
790                                {
791                                        $view_nodes     += (int) $jobs[$jobid][nodes];
[299]792                                }
[135]793
[328]794                                if( $even ) 
795                                {
796                                        $tpl->assign( "nodeclass", "even" );
[119]797
[328]798                                        $even           = 0;
799                                } 
800                                else 
801                                {
802                                        $tpl->assign( "nodeclass", "odd" );
[119]803
[328]804                                        $even           = 1;
[119]805                                }
806
[328]807                                if( $start_time ) 
808                                {
809                                        $runningtime            = makeTime( $report_time - $start_time );
810                                        $job_runningtime        = $report_time - $start_time;
[119]811
[328]812                                        $tpl->assign( "started", makeDate( $start_time ) );
813                                        $tpl->assign( "runningtime", $runningtime );
[119]814                                }
[117]815                        }
[116]816                }
[114]817        }
[208]818
[328]819        $all_used_nodes         = array_unique( $all_used_nodes );
820        $view_name_nodes        = array_unique( $view_name_nodes );
821        $running_name_nodes     = array_unique( $running_name_nodes );
[124]822
[328]823        $used_nodes             = count( $all_used_nodes );
824        $view_nodes             += count( $view_name_nodes );
825        $running_nodes          += count( $running_name_nodes );
[208]826
[328]827        $total_nodes            = $queued_nodes + $running_nodes;
828        $total_cpus             = $queued_cpus + $running_cpus;
829        $total_jobs             = $queued_jobs + $running_jobs;
[135]830
[328]831        $free_nodes             = $avail_nodes - $running_nodes;
832        $free_cpus              = $avail_cpus - $running_cpus;
[208]833
[328]834        $tpl->assignGlobal( "avail_nodes", $avail_nodes );
835        $tpl->assignGlobal( "avail_cpus", $avail_cpus );
[208]836
[328]837        $tpl->assignGlobal( "queued_nodes", $queued_nodes );
838        $tpl->assignGlobal( "queued_jobs", $queued_jobs );
839        $tpl->assignGlobal( "queued_cpus", $queued_cpus );
[208]840
[328]841        $tpl->assignGlobal( "total_nodes", $total_nodes );
842        $tpl->assignGlobal( "total_jobs", $total_jobs );
843        $tpl->assignGlobal( "total_cpus", $total_cpus );
[135]844
[328]845        $tpl->assignGlobal( "running_nodes", $running_nodes );
846        $tpl->assignGlobal( "running_jobs", $running_jobs );
847        $tpl->assignGlobal( "running_cpus", $running_cpus );
[208]848
[328]849        $tpl->assignGlobal( "used_nodes", $used_nodes );
850        $tpl->assignGlobal( "used_jobs", $used_jobs );
851        $tpl->assignGlobal( "used_cpus", $used_cpus );
[208]852
[328]853        $tpl->assignGlobal( "free_nodes", $free_nodes );
854        $tpl->assignGlobal( "free_cpus", $free_cpus );
[135]855
[328]856        $tpl->assignGlobal( "view_nodes", $view_nodes );
857        $tpl->assignGlobal( "view_jobs", $view_jobs );
858        $tpl->assignGlobal( "view_cpus", $view_cpus );
[126]859
[328]860        $tpl->assignGlobal( "report_time", makeDate( $heartbeat) );
861
[266]862        if( intval($view_jobs) == 1 and $start_time )
[328]863        {
[266]864                if( $last_displayed_job != null )
[328]865                {
[266]866                        $filter[id] = $last_displayed_job;
[328]867                }
868        }
[263]869
[266]870        makeHeader( 'overview' );
[328]871
[263]872        setupFilterSettings();
873
[328]874        if( intval($view_jobs) == 1 and $start_time ) 
875        {
[126]876                $tpl->newBlock( "showhosts" );
877
878                # Present a width list
[328]879                $cols_menu      = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
[126]880
[328]881                $hostcols       = ($hc) ? $hc : 4;
[263]882
[328]883                foreach( range( 1, 25 ) as $cols ) 
884                {
885                        $cols_menu      .= "<OPTION VALUE=$cols ";
[126]886
887                        if ($cols == $hostcols)
[328]888                        {
889                                $cols_menu      .= "SELECTED";
890                        }
891                        $cols_menu      .= ">$cols\n";
[126]892                }
[328]893                $cols_menu      .= "</SELECT>\n";
[126]894
[328]895                $tpl->assign( "metric","$metricname $units" );
896                $tpl->assign( "id", $filter[id] );
897
[126]898                # Host columns menu defined in header.php
[328]899                $tpl->assign( "cols_menu", $cols_menu );
[126]900
[328]901                $showhosts      = isset($sh) ? $sh : $default_showhosts;
[126]902
[328]903                $tpl->assign( "checked$showhosts", "checked" );
[126]904
[328]905                if( $showhosts ) 
906                {
907                        if( !isset( $start ) ) 
908                        {
909                                $start  ="jobstart";
910                        }
911                        if( !isset( $stop ) ) 
912                        {
913                                $stop   ="now";
914                        }
[126]915
[328]916                        $sorted_hosts   = array();
917                        $hosts_up       = $jobs[$filter[id]][nodes];
[126]918
[328]919                        $r              = intval($job_runningtime * 1.25);
[126]920
[328]921                        $jobrange       = ($job_runningtime < 3600) ? -3600 : -$r ;
922                        $jobstart       = $report_time - $job_runningtime;
[126]923
[328]924                        if ( $reports[$metricname] )
925                        {
926                                $metricval      = "g";
927                        }
[126]928                        else
[328]929                        {
930                                $metricval      = "m";
931                        }
[263]932                               
[328]933                        foreach ( $hosts_up as $host ) 
934                        {
935                                $domain_len             = 0 - strlen( $domain );
[195]936
[328]937                                if( substr( $host, $domain_len ) != $domain ) 
938                                {
939                                        $host           = $host . '.' . $domain;
[195]940                                }
[328]941
942                                $cpus                   = $metrics[$host]["cpu_num"]["VAL"];
943
944                                if ( !$cpus )
945                                {
946                                        $cpus           = 1;
947                                }
948
949                                $load_one               = $metrics[$host]["load_one"][VAL];
950                                $load                   = ((float) $load_one) / $cpus;
951                                $host_load[$host]       = $load;
952
953                                $percent_hosts[load_color($load)] ++;
954
[126]955                                if ($metricname=="load_one")
[328]956                                {
957                                        $sorted_hosts[$host]    = $load;
958                                }
[126]959                                else
[328]960                                {
961                                        $sorted_hosts[$host]    = $metrics[$host][$metricname][VAL];
962                                }
[126]963                        }
[328]964                        switch ( $sort ) 
965                        {
[126]966                                case "descending":
[328]967                                        arsort( $sorted_hosts );
[126]968                                        break;
[328]969
[126]970                                case "by hostname":
[328]971                                        ksort( $sorted_hosts );
[126]972                                        break;
[328]973
[126]974                                case "ascending":
[328]975                                        asort( $sorted_hosts );
[126]976                                        break;
[328]977
978                                default:
979                                        break;
[126]980                        }
981
[328]982                        // First pass to find the max value in all graphs for this
983                        // metric. The $start,$end variables comes from get_context.php,
984                        // included in index.php.
985                        //
[126]986                        list($min, $max) = find_limits($sorted_hosts, $metricname);
987
[328]988                        // Second pass to output the graphs or metrics.
[126]989                        $i = 1;
990
[328]991                        foreach ( $sorted_hosts as $host=>$value  ) 
992                        {
993                                $tpl->newBlock( "sorted_list" );
[126]994
[328]995                                $host_url       = rawurlencode( $host );
996                                $cluster_url    = rawurlencode( $clustername );
[193]997
[328]998                                $textval        = "";
999
1000                                $val            = $metrics[$host][$metricname];
1001                                $class          = "metric";
1002                                $host_link      = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
1003
1004                                if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] )
1005                                {
1006                                        $textval        = date( "r", $val["VAL"] );
1007                                }
1008                                elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs ))
1009                                {
1010                                        $textval        = $val["VAL"] . " " . $val["UNITS"];
1011                                }
1012                                else
1013                                {
1014                                        $load_color     = load_color($host_load[$host]);
1015                                        $graphargs      = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
1016                                        $graphargs      .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" . "&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
1017                                        if( $max > 0 )
1018                                        {
1019                                                $graphargs      .= "&x=$max&n=$min";
[193]1020                                        }
[126]1021                                }
[328]1022                                if ($textval)
1023                                {
1024                                        $cell   = "<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
[126]1025                                } else {
[328]1026                                        $cell   = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>";
[126]1027                                }
1028
[328]1029                                $tpl->assign( "metric_image", $cell );
1030
1031                                if(! ($i++ % $hostcols) )
1032                                {
1033                                         $tpl->assign( "br", "</tr><tr>" );
1034                                }
[126]1035                        }
1036                }
1037        }
[114]1038}
[113]1039?>
Note: See TracBrowser for help on using the repository browser.