Changeset 328 for trunk/web


Ignore:
Timestamp:
04/21/07 21:10:48 (17 years ago)
Author:
bastiaans
Message:

web/addons/job_monarch/overview.php:

  • code cleanup, realign and formatting
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/job_monarch/overview.php

    r326 r328  
    2626global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter;
    2727
     28$tpl->assign( "clustername", $clustername );
     29
     30if( $JOB_ARCHIVE )
     31{
     32        $tpl->assign( "cluster_url", rawurlencode($clustername) );
     33}
     34
    2835$ds             = new DataSource();
    2936$myxml_data     = $ds->getData();
    3037
    31 $data_gatherer = new DataGatherer( $clustername );
    32 
    33 $tpl->assign( "clustername", $clustername );
    34 
    35 if( $JOB_ARCHIVE )
    36         $tpl->assign( "cluster_url", rawurlencode($clustername) );
    37 
     38$data_gatherer  = new DataGatherer( $clustername );
    3839$data_gatherer->parseXML( $myxml_data );
    3940
    40 $heartbeat = $data_gatherer->getHeartbeat();
    41 $jobs = $data_gatherer->getJobs();
    42 $gnodes = $data_gatherer->getNodes();
    43 $cpus = $data_gatherer->getCpus();
    44 
    45 function setupFilterSettings() {
     41$heartbeat      = $data_gatherer->getHeartbeat();
     42$jobs           = $data_gatherer->getJobs();
     43$gnodes         = $data_gatherer->getNodes();
     44$cpus           = $data_gatherer->getCpus();
     45
     46function setupFilterSettings()
     47{
     48
    4649        global $tpl, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data;
    4750
     
    5053        $tpl->gotoBlock( "_ROOT" );
    5154
    52         foreach( $filter as $filtername => $filtervalue ) {
     55        foreach( $filter as $filtername => $filtervalue )
     56        {
    5357                $tpl->assign( "f_".$filtername, $filtervalue );
    54                 $filter_image_url .= "&$filtername=$filtervalue";
    55         }
    56 
    57         //include( "./ci_test.php" );
     58
     59                $filter_image_url       .= "&$filtername=$filtervalue";
     60        }
     61
    5862        session_start();
    59         //printf("data %s\n", strval( $myxml_data ) );
    60         $_SESSION["data"] = &$myxml_data;
    61 
    62         $ic = new ClusterImage( $myxml_data, $clustername );
     63
     64        $_SESSION["data"]       = &$myxml_data;
     65
     66        $ic                     = new ClusterImage( $myxml_data, $clustername );
     67
    6368        $ic->setBig();
    6469        $ic->setNoimage();
    6570        $ic->draw();
    6671
    67         //$tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
    6872        $tpl->assign( "clusterimage", "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
    6973
     
    7781        $tpl->assign( "f_order", $filterorder );
    7882
    79         if( array_key_exists( "id", $filter ) )
     83        if( array_key_exists( "id", $filter ) )
     84        {
    8085                $piefilter = 'id';
    81         else if( array_key_exists( "user", $filter ) )
     86        }
     87        else if( array_key_exists( "user", $filter ) )
     88        {
    8289                $piefilter = 'user';
    83         else if( array_key_exists( "queue", $filter ) )
     90        }
     91        else if( array_key_exists( "queue", $filter ) )
     92        {
    8493                $piefilter = 'queue';
    85 
    86         $pie = drawPie();
     94        }
     95
     96        $pie    = drawPie();
     97
    8798        $tpl->assign("pie", $pie );
    8899}
    89100
    90 function timeToEpoch( $time ) {
    91 
    92         $time_fields = explode( ':', $time );
    93 
    94         if( count($time_fields) == 3 ) {
    95 
    96                 $hours = $time_fields[0];
    97                 $minutes = $time_fields[1];
    98                 $seconds = $time_fields[2];
    99 
    100         } else if( count($time_fields) == 2 ) {
    101 
    102                 $hours = 0;
    103                 $minutes = $time_fields[0];
    104                 $seconds = $time_fields[1];
    105 
    106         } else if( count($time_fields) == 1 ) {
    107 
    108                 $hours = 0;
    109                 $minutes = 0;
    110                 $seconds = $time_fields[0];
    111         }
    112 
    113         $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
     101function timeToEpoch( $time )
     102{
     103        $time_fields    = explode( ':', $time );
     104
     105        if( count( $time_fields ) == 3 )
     106        {
     107                $hours          = $time_fields[0];
     108                $minutes        = $time_fields[1];
     109                $seconds        = $time_fields[2];
     110
     111        }
     112        else if( count( $time_fields ) == 2 )
     113        {
     114                $hours          = 0;
     115                $minutes        = $time_fields[0];
     116                $seconds        = $time_fields[1];
     117
     118        }
     119        else if( count( $time_fields ) == 1 )
     120        {
     121                $hours          = 0;
     122                $minutes        = 0;
     123                $seconds        = $time_fields[0];
     124        }
     125
     126        $myepoch        = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
    114127
    115128        return $myepoch;
    116129}
    117130
    118 //function makeDate( $time ) {
    119 //      return strftime( "%a %d %b %Y %H:%M:%S", $time );
    120 //}
    121 
    122 function colorRed( $color ) {
     131function colorRed( $color )
     132{
    123133        return substr( $color, 0, 2 );
    124134}
    125 function colorGreen( $color ) {
     135
     136function colorGreen( $color )
     137{
    126138        return substr( $color, 2, 2 );
    127139}
    128 function colorBlue( $color ) {
     140
     141function colorBlue( $color )
     142{
    129143        return substr( $color, 4, 2 );
    130144}
    131145
    132 function colorDiffer( $first, $second ) {
    133 
     146function colorDiffer( $first, $second )
     147{
    134148        // Make sure these two colors differ atleast 50 R/G/B
    135149        $min_diff = 50;
    136150
    137         $c1r = hexDec( colorRed( $first ) );
    138         $c1g = hexDec( colorGreen( $first ) );
    139         $c1b = hexDec( colorBlue( $first ) );
    140 
    141         $c2r = hexDec( colorRed( $second ) );
    142         $c2g = hexDec( colorGreen( $second ) );
    143         $c2b = hexDec( colorBlue( $second ) );
    144 
    145         $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
    146         $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
    147         $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
    148 
    149         if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
     151        $c1r    = hexDec( colorRed( $first ) );
     152        $c1g    = hexDec( colorGreen( $first ) );
     153        $c1b    = hexDec( colorBlue( $first ) );
     154
     155        $c2r    = hexDec( colorRed( $second ) );
     156        $c2g    = hexDec( colorGreen( $second ) );
     157        $c2b    = hexDec( colorBlue( $second ) );
     158
     159        $rdiff  = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
     160        $gdiff  = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
     161        $bdiff  = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
     162
     163        if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
     164        {
    150165                return TRUE;
    151         else
     166
     167        }
     168        else
     169        {
    152170                return FALSE;
     171        }
    153172}
    154173
    155 function randomColor( $known_colors ) {
    156 
    157         $start = "004E00";
     174function randomColor( $known_colors )
     175{
     176        // White (000000) would be invisible
     177        $start          = "004E00";
    158178       
    159         $start_red = colorRed( $start );
    160         $start_green = colorGreen( $start );
    161         $start_blue = colorBlue( $start );
     179        $start_red      = colorRed( $start );
     180        $start_green    = colorGreen( $start );
     181        $start_blue     = colorBlue( $start );
    162182       
    163         $end = "FFFFFF";
    164 
    165         $end_red = colorRed( $end );
    166         $end_green = colorGreen( $end );
    167         $end_blue = colorBlue( $end );
    168 
    169         $change_color = TRUE;
    170 
    171         while( $change_color ) {
    172 
    173                 $change_color = FALSE;
    174 
    175                 $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) );
    176                 $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) );
    177                 $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
    178 
    179                 $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
     183        $end            = "FFFFFF";
     184
     185        $end_red        = colorRed( $end );
     186        $end_green      = colorGreen( $end );
     187        $end_blue       = colorBlue( $end );
     188
     189        $change_color   = TRUE;
     190
     191        while( $change_color )
     192        {
     193                $change_color   = FALSE;
     194
     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 ) );
     198
     199                $new            = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
    180200
    181201                foreach( $known_colors as $old )
    182 
     202                {
    183203                        if( !colorDiffer( $new, $old ) )
    184 
     204                        {
    185205                                $change_color = TRUE;
     206                        }
     207                }
    186208        }
    187209
     
    190212}
    191213
    192 function drawJobPie() {
    193 }
    194 
    195 function drawUserPie() {
    196 
    197 }
    198 
    199 function drawQueuePie() {
    200 
    201 }
    202 
    203 
    204 function drawPie() {
    205 
     214// Code these some day
     215function drawJobPie() { }
     216
     217function drawUserPie() { }
     218
     219function drawQueuePie() { }
     220
     221
     222function drawPie()
     223{
    206224        global $jobs, $gnodes, $piefilter, $filter, $metrics;
    207225
     
    209227
    210228        if( isset($piefilter) )
     229        {
    211230                $pie_args       = "title=" . rawurlencode("Cluster ".$piefilter." usage");
    212         else
     231        }
     232        else
     233        {
    213234                $pie_args       = "title=" . rawurlencode("Cluster queue usage");
    214                
     235        }
     236
    215237        $pie_args       .= "&size=250x150";
    216238
     
    226248        $job_weight     = array();
    227249
    228         foreach( $nodes as $node ) {
    229 
     250        foreach( $nodes as $node )
     251        {
    230252                $myjobs         = $node->getJobs();
    231253                $myhost         = $node->getHostname();
     
    233255                $job_cpu        = 0;
    234256
    235                 foreach( $myjobs as $myjob ) {
    236 
     257                foreach( $myjobs as $myjob )
     258                {
    237259                        $job_cpu        += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
    238260                }
     
    253275
    254276        if( isset( $piefilter ) )
     277        {
    255278                $filterpie = array();
    256 
    257         foreach( $nodes as $node ) {
    258 
     279        }
     280
     281        foreach( $nodes as $node )
     282        {
    259283                $node_jobs      = $node->getJobs();
    260284                $nr_node_jobs   = count( $node_jobs );
     
    262286                $node_cpus      = $metrics[$myhost]["cpu_num"][VAL];
    263287
    264                 foreach( $node_jobs as $myjob ) {
    265 
     288                foreach( $node_jobs as $myjob )
     289                {
    266290                        $job_cpu                = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1;
    267291
     
    272296
    273297
    274                         if( isset($piefilter) ) {
     298                        if( isset( $piefilter ) ) {
     299
    275300                                $countjob = 1;
    276                                 if( $piefilter == 'id' ) {
     301
     302                                if( $piefilter == 'id' )
     303                                {
    277304                                        if( $myjob != $filter[$piefilter] )
     305                                        {
    278306                                                $countjob = 0;
    279                                 } else if( $piefilter == 'user' ) {
     307                                        }
     308                                }
     309                                else if( $piefilter == 'user' )
     310                                {
    280311                                        if( $jobs[$myjob][owner] != $filter[$piefilter] )
     312                                        {
    281313                                                $countjob = 0;
    282                                 } else {
     314                                        }
     315                                }
     316                                else
     317                                {
    283318                                        if( $jobs[$myjob][$piefilter] != $filter[$piefilter] )
     319                                        {
    284320                                                $countjob = 0;
    285                                 }
    286 
    287                                 if( $countjob ) {
     321                                        }
     322                                }
     323
     324                                if( $countjob )
     325                                {
    288326
    289327                                        if( !isset( $filterpie[$filter[$piefilter]] ) )
     328                                        {
    290329                                                $filterpie[$filter[$piefilter]] = $job_weight[$myjob];
     330                                        }
    291331                                        else
     332                                        {
     333
    292334                                                $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob];
    293                                 } else {
     335                                        }
     336                                }
     337                                else
     338                                {
    294339                                        if( !isset( $filterpie["other"] ) )
     340                                        {
    295341                                                $filterpie["other"] = $job_weight[$myjob];
     342                                        }
    296343                                        else
     344                                        {
    297345                                                $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob];
     346                                        }
    298347
    299348                                }
    300349                               
    301                         } else {
     350                        }
     351                        else
     352                        {
    302353
    303354                                $qname          = $jobs[$myjob][queue];
    304355
    305356                                if( !isset( $queues[$qname] ) )
     357                                {
    306358                                        $queues[$qname] = $job_weight[$myjob];
     359                                }
    307360                                else
     361                                {
    308362                                        $queues[$qname] = $queues[$qname] + $job_weight[$myjob];
     363                                }
    309364                        }
    310365                }
     
    312367
    313368        if( isset( $piefilter ) )
     369        {
    314370                $graphvals = $filterpie;
     371        }
    315372        else
     373        {
    316374                $graphvals = $queues;
    317 
    318         foreach( $graphvals as $name => $totalweight) {
    319 
     375        }
     376
     377        foreach( $graphvals as $name => $totalweight)
     378        {
    320379                $percentage     = ( $totalweight * 100 );
    321380               
     
    330389
    331390
    332 function sortJobs( $jobs, $sortby, $sortorder ) {
    333 
    334         $sorted = array();
    335 
    336         $cmp = create_function( '$a, $b',
     391function sortJobs( $jobs, $sortby, $sortorder )
     392{
     393        $sorted = array();
     394
     395        $cmp    = create_function( '$a, $b',
    337396                "global \$sortby, \$sortorder;".
    338397
     
    344403                        "return ( \$a > \$b ) ? 1 : -1;" );
    345404
    346         if( isset( $jobs ) && count( $jobs ) > 0 ) {
    347 
    348                 foreach( $jobs as $jobid => $jobattrs ) {
    349 
    350                                 $state = $jobattrs[status];
    351                                 $user = $jobattrs[owner];
    352                                 $queue = $jobattrs[queue];
    353                                 $name = $jobattrs[name];
    354                                 $req_cpu = $jobattrs[requested_time];
    355                                 $req_memory = $jobattrs[requested_memory];
     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];
    356415
    357416                                if( $state == 'R' )
     417                                {
    358418                                        $nodes = count( $jobattrs[nodes] );
     419                                }
    359420                                else
     421                                {
    360422                                        $nodes = $jobattrs[nodes];
    361 
    362                                 $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
    363                                 $cpus = $nodes * $ppn;
    364                                 $queued_time = (int) $jobattrs[queued_timestamp];
    365                                 $start_time = (int) $jobattrs[start_timestamp];
    366                                 $runningtime = $report_time - $start_time;
    367 
    368                                 switch( $sortby ) {
     423                                }
     424
     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;
     430
     431                                switch( $sortby )
     432                                {
    369433                                        case "id":
    370434                                                $sorted[$jobid] = $jobid;
     
    417481                                        default:
    418482                                                break;
    419 
    420483                                }
    421484                }
    422485        }
    423486
    424         //uasort( $sorted, $cmp );
    425487        if( $sortorder == "asc" )
     488        {
    426489                arsort( $sorted );
     490        }
    427491        else if( $sortorder == "desc" )
     492        {
    428493                asort( $sorted );
     494        }
    429495
    430496        return $sorted;
    431497}
    432498
    433 function makeOverview() {
    434 
     499function makeOverview()
     500{
    435501        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
    436502        global $sortorder, $sortby, $filter, $sh, $hc, $m;
     
    438504        global $start, $end, $reports, $gnodes, $default_showhosts;
    439505        global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname;
    440         $metricname = $m;
     506
     507        $metricname             = $m;
    441508
    442509        $tpl->assign("sortorder", $sortorder );
    443510        $tpl->assign("sortby", $sortby );
    444511
    445         $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder );
    446 
    447         $even = 1;
    448 
    449         $used_jobs = 0;
    450         $used_cpus = 0;
    451         $used_nodes = 0;
    452 
    453         $queued_jobs = 0;
    454         $queued_nodes = 0;
    455         $queued_cpus = 0;
    456 
    457         $total_nodes = 0;
    458         $total_cpus = 0;
    459         $total_jobs = 0;
    460 
    461         $all_used_nodes = array();
    462         $total_used_nodes = array();
    463 
    464         $running_name_nodes = array();
    465 
    466         $running_nodes = 0;
    467         $running_jobs = 0;
    468         $running_cpus = 0;
    469 
    470         $avail_nodes = count( $gnodes );
    471         $avail_cpus = cluster_sum("cpu_num", $metrics);
    472 
    473         $view_cpus = 0;
    474         $view_jobs = 0;
    475         $view_nodes = 0;
    476 
    477         $all_nodes = 0;
    478         $all_jobs = 0;
    479         $all_cpus = 0;
    480 
    481         $view_name_nodes = array();
    482 
    483         if( $COLUMN_REQUESTED_MEMORY ) {
     512        $sorted_jobs            = sortJobs( $jobs, $sortby, $sortorder );
     513
     514        $even                   = 1;
     515
     516        $used_jobs              = 0;
     517        $used_cpus              = 0;
     518        $used_nodes             = 0;
     519
     520        $queued_jobs            = 0;
     521        $queued_nodes           = 0;
     522        $queued_cpus            = 0;
     523
     524        $total_nodes            = 0;
     525        $total_cpus             = 0;
     526        $total_jobs             = 0;
     527
     528        $all_used_nodes         = array();
     529        $total_used_nodes       = array();
     530
     531        $running_name_nodes     = array();
     532
     533        $running_nodes          = 0;
     534        $running_jobs           = 0;
     535        $running_cpus           = 0;
     536
     537        $avail_nodes            = count( $gnodes );
     538        $avail_cpus             = cluster_sum("cpu_num", $metrics);
     539
     540        $view_cpus              = 0;
     541        $view_jobs              = 0;
     542        $view_nodes             = 0;
     543
     544        $all_nodes              = 0;
     545        $all_jobs               = 0;
     546        $all_cpus               = 0;
     547
     548        $view_name_nodes        = array();
     549
     550        if( $COLUMN_REQUESTED_MEMORY )
     551        {
    484552                $tpl->newBlock( "column_header_req_mem" );
    485553        }
    486554
    487         if( $COLUMN_NODES ) {
     555        if( $COLUMN_NODES )
     556        {
    488557                $tpl->newBlock( "column_header_nodes" );
    489558        }
    490559
    491         if( $COLUMN_QUEUED ) {
     560        if( $COLUMN_QUEUED )
     561        {
    492562                $tpl->newBlock( "column_header_queued" );
    493563        }
    494564
    495         $last_displayed_job = null;
    496 
    497         foreach( $sorted_jobs as $jobid => $sortdec ) {
    498 
    499                 $report_time = $jobs[$jobid][reported];
     565        $last_displayed_job     = null;
     566
     567        foreach( $sorted_jobs as $jobid => $sortdec )
     568        {
     569                $report_time    = $jobs[$jobid][reported];
    500570
    501571                if( $jobs[$jobid][status] == 'R' )
     572                {
    502573                        $nodes = count( $jobs[$jobid][nodes] );
     574                }
    503575                else if( $jobs[$jobid][status] == 'Q' )
     576                {
    504577                        $nodes = $jobs[$jobid][nodes];
    505 
    506                 $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
    507                 $cpus = $nodes * $ppn;
    508 
    509                 if( $report_time == $heartbeat ) {
    510 
    511                         $display_job = 1;
    512 
    513                         if( $jobs[$jobid][status] == 'R' ) {
    514                                 foreach( $jobs[$jobid][nodes] as $tempnode ) {
     578                }
     579
     580                $ppn            = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
     581                $cpus           = $nodes * $ppn;
     582
     583                if( $report_time == $heartbeat )
     584                {
     585                        $display_job    = 1;
     586
     587                        if( $jobs[$jobid][status] == 'R' )
     588                        {
     589                                foreach( $jobs[$jobid][nodes] as $tempnode )
     590                                {
    515591                                        $all_used_nodes[] = $tempnode;
    516592                                }
     
    519595                        $used_cpus += $cpus;
    520596
    521                         if( $jobs[$jobid][status] == 'R' ) {
    522                                 $running_cpus += $cpus;
     597                        if( $jobs[$jobid][status] == 'R' )
     598                        {
     599                                $running_cpus   += $cpus;
     600
    523601                                $running_jobs++;
    524602
    525                                 $found_node_job = 0;
    526 
    527                                 foreach( $jobs[$jobid][nodes] as $tempnode ) {
     603                                $found_node_job = 0;
     604
     605                                foreach( $jobs[$jobid][nodes] as $tempnode )
     606                                {
    528607                                        $running_name_nodes[] = $tempnode;
    529608
    530                                         if( isset( $hostname ) && $hostname != '' ) {
     609                                        if( isset( $hostname ) && $hostname != '' )
     610                                        {
    531611                                                //$filter[host] = $hostname;
    532612
    533                                                 $domain_len = 0 - strlen( $jobs[$jobid][domain] );
    534                                                 $hostnode = $tempnode;
    535                                                 if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) {
     613                                                $domain_len     = 0 - strlen( $jobs[$jobid][domain] );
     614                                                $hostnode       = $tempnode;
     615
     616                                                if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] )
     617                                                {
    536618                                                        $hostnode = $hostnode. '.'. $jobs[$jobid][domain];
    537619                                                }
    538620
    539                                                 if( $hostname == $hostnode ) {
     621                                                if( $hostname == $hostnode )
     622                                                {
    540623                                                        $found_node_job = 1;
    541624                                                        $display_job = 1;
    542                                                 } else if( !$found_node_job ) {
     625                                                }
     626                                                else if( !$found_node_job )
     627                                                {
    543628                                                        $display_job = 0;
    544629                                                }
     
    547632                        }
    548633
    549                         if( $jobs[$jobid][status] == 'Q' ) {
     634                        if( $jobs[$jobid][status] == 'Q' )
     635                        {
    550636                                if( isset( $hostname ) && $hostname != '' )
     637                                {
    551638                                        $display_job = 0;
    552 
    553                                 $queued_cpus += $cpus;
    554                                 $queued_nodes += $nodes;
     639                                }
     640
     641                                $queued_cpus    += $cpus;
     642                                $queued_nodes   += $nodes;
     643
    555644                                $queued_jobs++;
    556645                        }
    557646
    558                         foreach( $filter as $filtername=>$filtervalue ) {
    559 
     647                        foreach( $filter as $filtername=>$filtervalue )
     648                        {
    560649                                if( $filtername == 'id' && $jobid != $filtervalue )
     650                                {
    561651                                        $display_job = 0;
     652                                }
    562653                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
     654                                {
    563655                                        $display_job = 0;
     656                                }
    564657                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
     658                                {
    565659                                        $display_job = 0;
     660                                }
    566661                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
     662                                {
    567663                                        $display_job = 0;
    568                         }
    569 
    570                         if( $display_job ) {
    571 
    572                                 $tpl->newBlock("node");
     664                                }
     665                        }
     666
     667                        if( $display_job )
     668                        {
     669                                $tpl->newBlock( "node" );
    573670                                $tpl->assign( "clustername", $clustername );
    574                                 $tpl->assign("id", $jobid );
    575 
    576                                 $last_displayed_job = $jobid;
    577 
    578                                 $tpl->assign("state", $jobs[$jobid][status] );
    579 
    580                                 $fullstate = '';
    581                                 if( $jobs[$jobid][status] == 'R' ) {
    582                                         $fullstate = "Running";
    583                                 } else if( $jobs[$jobid][status] == 'Q' ) {
    584                                         $fullstate = "Queued";
    585                                 }
    586 
    587                                 $tpl->assign("fullstate", $fullstate );
     671                                $tpl->assign( "id", $jobid );
     672
     673                                $last_displayed_job     = $jobid;
     674
     675                                $tpl->assign( "state", $jobs[$jobid][status] );
     676
     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";
     686                                }
     687
     688                                $tpl->assign( "fullstate", $fullstate );
    588689                               
    589                                 $tpl->assign("user", $jobs[$jobid][owner] );
    590                                 $tpl->assign("queue", $jobs[$jobid][queue] );
    591 
    592                                 $fulljobname = $jobs[$jobid][name];
    593                                 $shortjobname = '';
    594 
    595                                 $tpl->assign("fulljobname", $fulljobname );
     690                                $tpl->assign( "user", $jobs[$jobid][owner] );
     691                                $tpl->assign( "queue", $jobs[$jobid][queue] );
     692
     693                                $fulljobname            = $jobs[$jobid][name];
     694                                $shortjobname           = '';
     695
     696                                $tpl->assign( "fulljobname", $fulljobname );
    596697
    597698                                $fulljobname_fields     = explode( ' ', $fulljobname );
    598699
    599                                 $capjobname     = 0;
     700                                $capjobname             = 0;
    600701
    601702                                if( strlen( $fulljobname_fields[0] ) > 10 )
     703                                {
    602704                                        $capjobname     = 1;
    603 
    604                                 if( $capjobname ) {
    605                                         $tpl->newBlock("jobname_hint_start");
    606                                         $tpl->gotoBlock("node");
    607 
    608                                         $shortjobname = substr( $fulljobname, 0, 10 ) . '..';
    609                                 } else {
    610                                         $shortjobname = $fulljobname;
     705                                }
     706
     707                                if( $capjobname )
     708                                {
     709                                        $tpl->newBlock( "jobname_hint_start" );
     710                                        $tpl->gotoBlock( "node" );
     711
     712                                        $shortjobname   = substr( $fulljobname, 0, 10 ) . '..';
     713                                }
     714                                else
     715                                {
     716                                        $shortjobname   = $fulljobname;
    611717                                }
    612718                               
    613                                 $tpl->assign("name", $shortjobname );
    614 
    615                                 if( $capjobname ) {
    616                                         $tpl->newBlock("jobname_hint_end");
    617                                         $tpl->gotoBlock("node");
    618                                 }
    619 
    620                                 $domain = $jobs[$jobid][domain];
    621                                 $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
    622 
    623                                 if( $COLUMN_REQUESTED_MEMORY ) {
     719                                $tpl->assign( "name", $shortjobname );
     720
     721                                if( $capjobname )
     722                                {
     723                                        $tpl->newBlock( "jobname_hint_end" );
     724                                        $tpl->gotoBlock( "node" );
     725                                }
     726
     727                                $domain                 = $jobs[$jobid][domain];
     728
     729                                $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
     730
     731                                if( $COLUMN_REQUESTED_MEMORY )
     732                                {
    624733                                        $tpl->newBlock( "column_req_mem" );
    625734                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
     
    628737
    629738
    630                                 if( $COLUMN_QUEUED ) {
     739                                if( $COLUMN_QUEUED )
     740                                {
    631741                                        $tpl->newBlock( "column_queued" );
    632742                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
    633743                                        $tpl->gotoBlock( "node" );
    634744                                }
    635                                 if( $COLUMN_NODES ) {
     745                                if( $COLUMN_NODES )
     746                                {
    636747                                        $tpl->newBlock( "column_nodes" );
    637748                                        $tpl->gotoBlock( "node" );
    638749                                }
    639750
    640                                 $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
    641                                 $cpus = $nodes * $ppn;
    642                                 $tpl->assign("nodes", $nodes );
    643                                 $tpl->assign("cpus", $cpus );
    644                                 $start_time = (int) $jobs[$jobid][start_timestamp];
    645                                 $job_start = $start_time;
    646 
    647                                 $view_cpus += $cpus;
     751                                $ppn                    = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
     752                                $cpus                   = $nodes * $ppn;
     753
     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
    648762                                $view_jobs++;
    649763
    650                                 if( $jobs[$jobid][status] == 'R' ) {
     764                                if( $jobs[$jobid][status] == 'R' )
     765                                {
    651766                                        foreach( $jobs[$jobid][nodes] as $tempnode )
    652                                                 $view_name_nodes[] = $tempnode;
    653 
    654                                         if( $COLUMN_NODES ) {
     767                                        {
     768                                                $view_name_nodes[]      = $tempnode;
     769                                        }
     770
     771                                        if( $COLUMN_NODES )
     772                                        {
    655773                                                $tpl->gotoBlock( "column_nodes" );
    656                                                 $mynodehosts = array();
    657                                                 foreach( $jobs[$jobid][nodes] as $mynode ) {
    658                                                         $myhost_href = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain];
    659                                                         $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>";
     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>";
    660781                                                }
    661                                                 $nodes_hostnames = implode( " ", $mynodehosts );
     782
     783                                                $nodes_hostnames        = implode( " ", $mynodehosts );
     784
    662785                                                $tpl->assign( "nodes_hostnames", $nodes_hostnames );
    663786                                                $tpl->gotoBlock( "node" );
    664787                                        }
    665                                 } else if( $jobs[$jobid][status] == 'Q' ) {
    666                                         $view_nodes += (int) $jobs[$jobid][nodes];
    667                                 }
    668 
    669                                 if( $even ) {
    670 
    671                                         $tpl->assign("nodeclass", "even");
    672                                         $even = 0;
     788                                }
     789                                else if( $jobs[$jobid][status] == 'Q' )
     790                                {
     791                                        $view_nodes     += (int) $jobs[$jobid][nodes];
     792                                }
     793
     794                                if( $even )
     795                                {
     796                                        $tpl->assign( "nodeclass", "even" );
     797
     798                                        $even           = 0;
     799                                }
     800                                else
     801                                {
     802                                        $tpl->assign( "nodeclass", "odd" );
     803
     804                                        $even           = 1;
     805                                }
     806
     807                                if( $start_time )
     808                                {
     809                                        $runningtime            = makeTime( $report_time - $start_time );
     810                                        $job_runningtime        = $report_time - $start_time;
     811
     812                                        $tpl->assign( "started", makeDate( $start_time ) );
     813                                        $tpl->assign( "runningtime", $runningtime );
     814                                }
     815                        }
     816                }
     817        }
     818
     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 );
     822
     823        $used_nodes             = count( $all_used_nodes );
     824        $view_nodes             += count( $view_name_nodes );
     825        $running_nodes          += count( $running_name_nodes );
     826
     827        $total_nodes            = $queued_nodes + $running_nodes;
     828        $total_cpus             = $queued_cpus + $running_cpus;
     829        $total_jobs             = $queued_jobs + $running_jobs;
     830
     831        $free_nodes             = $avail_nodes - $running_nodes;
     832        $free_cpus              = $avail_cpus - $running_cpus;
     833
     834        $tpl->assignGlobal( "avail_nodes", $avail_nodes );
     835        $tpl->assignGlobal( "avail_cpus", $avail_cpus );
     836
     837        $tpl->assignGlobal( "queued_nodes", $queued_nodes );
     838        $tpl->assignGlobal( "queued_jobs", $queued_jobs );
     839        $tpl->assignGlobal( "queued_cpus", $queued_cpus );
     840
     841        $tpl->assignGlobal( "total_nodes", $total_nodes );
     842        $tpl->assignGlobal( "total_jobs", $total_jobs );
     843        $tpl->assignGlobal( "total_cpus", $total_cpus );
     844
     845        $tpl->assignGlobal( "running_nodes", $running_nodes );
     846        $tpl->assignGlobal( "running_jobs", $running_jobs );
     847        $tpl->assignGlobal( "running_cpus", $running_cpus );
     848
     849        $tpl->assignGlobal( "used_nodes", $used_nodes );
     850        $tpl->assignGlobal( "used_jobs", $used_jobs );
     851        $tpl->assignGlobal( "used_cpus", $used_cpus );
     852
     853        $tpl->assignGlobal( "free_nodes", $free_nodes );
     854        $tpl->assignGlobal( "free_cpus", $free_cpus );
     855
     856        $tpl->assignGlobal( "view_nodes", $view_nodes );
     857        $tpl->assignGlobal( "view_jobs", $view_jobs );
     858        $tpl->assignGlobal( "view_cpus", $view_cpus );
     859
     860        $tpl->assignGlobal( "report_time", makeDate( $heartbeat) );
     861
     862        if( intval($view_jobs) == 1 and $start_time )
     863        {
     864                if( $last_displayed_job != null )
     865                {
     866                        $filter[id] = $last_displayed_job;
     867                }
     868        }
     869
     870        makeHeader( 'overview' );
     871
     872        setupFilterSettings();
     873
     874        if( intval($view_jobs) == 1 and $start_time )
     875        {
     876                $tpl->newBlock( "showhosts" );
     877
     878                # Present a width list
     879                $cols_menu      = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
     880
     881                $hostcols       = ($hc) ? $hc : 4;
     882
     883                foreach( range( 1, 25 ) as $cols )
     884                {
     885                        $cols_menu      .= "<OPTION VALUE=$cols ";
     886
     887                        if ($cols == $hostcols)
     888                        {
     889                                $cols_menu      .= "SELECTED";
     890                        }
     891                        $cols_menu      .= ">$cols\n";
     892                }
     893                $cols_menu      .= "</SELECT>\n";
     894
     895                $tpl->assign( "metric","$metricname $units" );
     896                $tpl->assign( "id", $filter[id] );
     897
     898                # Host columns menu defined in header.php
     899                $tpl->assign( "cols_menu", $cols_menu );
     900
     901                $showhosts      = isset($sh) ? $sh : $default_showhosts;
     902
     903                $tpl->assign( "checked$showhosts", "checked" );
     904
     905                if( $showhosts )
     906                {
     907                        if( !isset( $start ) )
     908                        {
     909                                $start  ="jobstart";
     910                        }
     911                        if( !isset( $stop ) )
     912                        {
     913                                $stop   ="now";
     914                        }
     915
     916                        $sorted_hosts   = array();
     917                        $hosts_up       = $jobs[$filter[id]][nodes];
     918
     919                        $r              = intval($job_runningtime * 1.25);
     920
     921                        $jobrange       = ($job_runningtime < 3600) ? -3600 : -$r ;
     922                        $jobstart       = $report_time - $job_runningtime;
     923
     924                        if ( $reports[$metricname] )
     925                        {
     926                                $metricval      = "g";
     927                        }
     928                        else
     929                        {
     930                                $metricval      = "m";
     931                        }
     932                               
     933                        foreach ( $hosts_up as $host )
     934                        {
     935                                $domain_len             = 0 - strlen( $domain );
     936
     937                                if( substr( $host, $domain_len ) != $domain )
     938                                {
     939                                        $host           = $host . '.' . $domain;
     940                                }
     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
     955                                if ($metricname=="load_one")
     956                                {
     957                                        $sorted_hosts[$host]    = $load;
     958                                }
     959                                else
     960                                {
     961                                        $sorted_hosts[$host]    = $metrics[$host][$metricname][VAL];
     962                                }
     963                        }
     964                        switch ( $sort )
     965                        {
     966                                case "descending":
     967                                        arsort( $sorted_hosts );
     968                                        break;
     969
     970                                case "by hostname":
     971                                        ksort( $sorted_hosts );
     972                                        break;
     973
     974                                case "ascending":
     975                                        asort( $sorted_hosts );
     976                                        break;
     977
     978                                default:
     979                                        break;
     980                        }
     981
     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                        //
     986                        list($min, $max) = find_limits($sorted_hosts, $metricname);
     987
     988                        // Second pass to output the graphs or metrics.
     989                        $i = 1;
     990
     991                        foreach ( $sorted_hosts as $host=>$value  )
     992                        {
     993                                $tpl->newBlock( "sorted_list" );
     994
     995                                $host_url       = rawurlencode( $host );
     996                                $cluster_url    = rawurlencode( $clustername );
     997
     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";
     1020                                        }
     1021                                }
     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>";
    6731025                                } else {
    674 
    675                                         $tpl->assign("nodeclass", "odd");
    676                                         $even = 1;
    677                                 }
    678 
    679                                 if( $start_time ) {
    680 
    681                                         $runningtime = makeTime( $report_time - $start_time );
    682                                         $job_runningtime = $report_time - $start_time;
    683                                         $tpl->assign("started", makeDate( $start_time ) );
    684                                         $tpl->assign("runningtime", $runningtime );
     1026                                        $cell   = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>";
     1027                                }
     1028
     1029                                $tpl->assign( "metric_image", $cell );
     1030
     1031                                if(! ($i++ % $hostcols) )
     1032                                {
     1033                                         $tpl->assign( "br", "</tr><tr>" );
    6851034                                }
    6861035                        }
    6871036                }
    688         }
    689         $all_used_nodes = array_unique( $all_used_nodes );
    690         $view_name_nodes = array_unique( $view_name_nodes );
    691         $running_name_nodes = array_unique( $running_name_nodes );
    692 
    693         $used_nodes = count( $all_used_nodes );
    694         $view_nodes += count( $view_name_nodes );
    695         $running_nodes += count( $running_name_nodes );
    696 
    697         $total_nodes = $queued_nodes + $running_nodes;
    698         $total_cpus = $queued_cpus + $running_cpus;
    699         $total_jobs = $queued_jobs + $running_jobs;
    700 
    701         $tpl->assignGlobal("avail_nodes", $avail_nodes );
    702         $tpl->assignGlobal("avail_cpus", $avail_cpus );
    703 
    704         $tpl->assignGlobal("queued_nodes", $queued_nodes );
    705         $tpl->assignGlobal("queued_jobs", $queued_jobs );
    706         $tpl->assignGlobal("queued_cpus", $queued_cpus );
    707 
    708         $tpl->assignGlobal("total_nodes", $total_nodes );
    709         $tpl->assignGlobal("total_jobs", $total_jobs );
    710         $tpl->assignGlobal("total_cpus", $total_cpus );
    711 
    712         $tpl->assignGlobal("running_nodes", $running_nodes );
    713         $tpl->assignGlobal("running_jobs", $running_jobs );
    714         $tpl->assignGlobal("running_cpus", $running_cpus );
    715 
    716         $tpl->assignGlobal("used_nodes", $used_nodes );
    717         $tpl->assignGlobal("used_jobs", $used_jobs );
    718         $tpl->assignGlobal("used_cpus", $used_cpus );
    719 
    720         $free_nodes = $avail_nodes - $running_nodes;
    721         $free_cpus = $avail_cpus - $running_cpus;
    722 
    723         $tpl->assignGlobal("free_nodes", $free_nodes );
    724         $tpl->assignGlobal("free_cpus", $free_cpus );
    725 
    726         $tpl->assignGlobal("view_nodes", $view_nodes );
    727         $tpl->assignGlobal("view_jobs", $view_jobs );
    728         $tpl->assignGlobal("view_cpus", $view_cpus );
    729 
    730         $tpl->assignGlobal("report_time", makeDate( $heartbeat));
    731 
    732         if( intval($view_jobs) == 1 and $start_time )
    733                 if( $last_displayed_job != null )
    734                         $filter[id] = $last_displayed_job;
    735 
    736         makeHeader( 'overview' );
    737         setupFilterSettings();
    738 
    739         if( intval($view_jobs) == 1 and $start_time ) {
    740 
    741                 $tpl->newBlock( "showhosts" );
    742 
    743                 # Present a width list
    744                 $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
    745 
    746 
    747                 $hostcols = ($hc) ? $hc : 4;
    748 
    749                 foreach(range(1,25) as $cols) {
    750                         $cols_menu .= "<OPTION VALUE=$cols ";
    751                         if ($cols == $hostcols)
    752                                 $cols_menu .= "SELECTED";
    753                         $cols_menu .= ">$cols\n";
    754                 }
    755                 $cols_menu .= "</SELECT>\n";
    756 
    757                 //$tpl->assign("cluster", $clustername);
    758                 $tpl->assign("metric","$metricname $units");
    759                 $tpl->assign("id", $filter[id]);
    760                 # Host columns menu defined in header.php
    761                 $tpl->assign("cols_menu", $cols_menu);
    762 
    763                 $showhosts = isset($sh) ? $sh : $default_showhosts;
    764                 //if( !$showhosts) $showhosts = $default_showhosts;
    765                 $tpl->assign("checked$showhosts", "checked");
    766 
    767                 if( $showhosts ) {
    768                         //-----
    769 
    770                         if( !isset($start) ) $start="jobstart";
    771                         if( !isset($stop) ) $stop="now";
    772                         //$tpl->assign("start", $start);
    773                         //$tpl->assign("stop", $stop);
    774 
    775                         $sorted_hosts = array();
    776                         $hosts_up = $jobs[$filter[id]][nodes];
    777 
    778                         $r = intval($job_runningtime * 1.25);
    779 
    780                         $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ;
    781                         $jobstart = $report_time - $job_runningtime;
    782 
    783                         if ($reports[$metricname])
    784                                 $metricval = "g";
    785                         else
    786                                 $metricval = "m";
    787                                
    788                         foreach ($hosts_up as $host ) {
    789 
    790                                 $domain_len = 0 - strlen( $domain );
    791                                 if( substr( $host, $domain_len ) != $domain ) {
    792                                         $host = $host. '.'.$domain;
    793                                 }
    794                                 $cpus = $metrics[$host]["cpu_num"][VAL];
    795                                 if (!$cpus) $cpus=1;
    796                                 $load_one  = $metrics[$host]["load_one"][VAL];
    797                                 $load = ((float) $load_one)/$cpus;
    798                                 $host_load[$host] = $load;
    799                                 $percent_hosts[load_color($load)] += 1;
    800                                 if ($metricname=="load_one")
    801                                         $sorted_hosts[$host] = $load;
    802                                 else
    803                                         $sorted_hosts[$host] = $metrics[$host][$metricname][VAL];
    804                         }
    805                         switch ($sort) {
    806                                 case "descending":
    807                                         arsort($sorted_hosts);
    808                                         break;
    809                                 case "by hostname":
    810                                         ksort($sorted_hosts);
    811                                         break;
    812                                 default:
    813                                 case "ascending":
    814                                         asort($sorted_hosts);
    815                                         break;
    816                         }
    817 
    818                         //$sorted_hosts = array_merge($down_hosts, $sorted_hosts);
    819 
    820                         # First pass to find the max value in all graphs for this
    821                         # metric. The $start,$end variables comes from get_context.php,
    822                         # included in index.php.
    823                         list($min, $max) = find_limits($sorted_hosts, $metricname);
    824 
    825                         # Second pass to output the graphs or metrics.
    826                         $i = 1;
    827                         foreach ( $sorted_hosts as $host=>$value  ) {
    828                                 $tpl->newBlock ("sorted_list");
    829                                 //$host = $host. '.'.$domain;
    830                                 $host_url = rawurlencode($host);
    831                                 $cluster_url = rawurlencode($clustername);
    832 
    833                                 $textval = "";
    834                                 //printf("host = %s, value = %s", $host, $value);
    835                                 //echo "$host: $value, ";
    836                                 $val = $metrics[$host][$metricname];
    837                                 $class = "metric";
    838                                 $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
    839 
    840                                 if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) {
    841                                         $textval = date("r", $val[VAL]);
    842                                 } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
    843                                         $textval = "$val[VAL] $val[UNITS]";
    844                                 } else {
    845                                         $load_color = load_color($host_load[$host]);
    846                                         $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
    847                                         $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
    848                                         if( $max > 0 ) {
    849 
    850                                                 $graphargs .= "&x=$max&n=$min";
    851                                         }
    852                                 }
    853                                 if ($textval) {
    854                                         $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
    855                                 } else {
    856                                         $cell="<td><a href=$host_link>".  "<img src=\"../../graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
    857                                 }
    858 
    859                                 $tpl->assign("metric_image", $cell);
    860                                 if (! ($i++ % $hostcols) )
    861                                          $tpl->assign ("br", "</tr><tr>");
    862                         }
    863                 }
    864 //---
    8651037        }
    8661038}
Note: See TracChangeset for help on using the changeset viewer.