Ignore:
Timestamp:
03/21/13 21:33:48 (11 years ago)
Author:
ramonb
Message:
  • replace tabs with spaces
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.4/web/addons/job_monarch/search.php

    r713 r716  
    2626
    2727function validateFormInput() {
    28         global $clustername, $tpl, $id, $owner, $name, $start_from_time, $start_to_time, $queue;
    29         global $end_from_time, $end_to_time, $period_start, $period_stop;
    30 
    31         $error = 0;
    32         $error_msg = "<FONT COLOR=\"red\"><B>";
    33         $show_msg = 0;
    34 
    35         $none_set = 0;
    36 
    37         if( $id == '' and $owner== '' and $name == '' and $start_from_time == '' and $start_to_time == '' and $queue == '' and $end_from_time == '' and $end_to_time == '') {
    38                 $error = 1;
    39                 $show_msg = 1;
    40                 $error_msg .= "No search criteria set!";
    41         }
    42 
    43         if( !is_numeric($id) and !$error and $id != '')
     28    global $clustername, $tpl, $id, $owner, $name, $start_from_time, $start_to_time, $queue;
     29    global $end_from_time, $end_to_time, $period_start, $period_stop;
     30
     31    $error = 0;
     32    $error_msg = "<FONT COLOR=\"red\"><B>";
     33    $show_msg = 0;
     34
     35    $none_set = 0;
     36
     37    if( $id == '' and $owner== '' and $name == '' and $start_from_time == '' and $start_to_time == '' and $queue == '' and $end_from_time == '' and $end_to_time == '') {
     38        $error = 1;
     39        $show_msg = 1;
     40        $error_msg .= "No search criteria set!";
     41    }
     42
     43    if( !is_numeric($id) and !$error and $id != '')
    4444    {
    4545
    46                 $error = 1;
    47                 $show_msg = 1;
    48                 $error_msg .= "Id must be a number";
    49         }
    50 
    51         if( !$error and $period_start != '' )
     46        $error = 1;
     47        $show_msg = 1;
     48        $error_msg .= "Id must be a number";
     49    }
     50
     51    if( !$error and $period_start != '' )
    5252    {
    53                 $pstart_epoch = datetimeToEpoch( $period_start );
    54                 if( $period_stop != '' )
     53        $pstart_epoch = datetimeToEpoch( $period_start );
     54        if( $period_stop != '' )
    5555        {
    5656
    57                         $pstop_epoch = datetimeToEpoch( $period_stop );
    58 
    59                         if( $pstart_epoch > $pstop_epoch ) {
    60 
    61                                 $show_msg = 1;
    62                                 $error_msg .= "Graph timeperiod reset: start date/time can't be later than end";
    63                                 $period_stop = '';
    64                                 $period_start = '';
    65                         } else if( $pstop_epoch == $pstart_epoch ) {
    66 
    67                                 $show_msg = 1;
    68                                 $error_msg .= "Graph timeperiod reset: start and end date/time can't be the same";
    69                                 $period_stop = '';
    70                                 $period_start = '';
    71                         }
    72                 }
    73         }
    74 
    75         $error_msg .= "</B></FONT>";
    76         // doe checks en set error en error_msg in case shit
    77 
    78         if( $show_msg )
    79                 $tpl->assign( "form_error_msg", $error_msg );
    80 
    81         return ($error ? 0 : 1 );
     57            $pstop_epoch = datetimeToEpoch( $period_stop );
     58
     59            if( $pstart_epoch > $pstop_epoch ) {
     60
     61                $show_msg = 1;
     62                $error_msg .= "Graph timeperiod reset: start date/time can't be later than end";
     63                $period_stop = '';
     64                $period_start = '';
     65            } else if( $pstop_epoch == $pstart_epoch ) {
     66
     67                $show_msg = 1;
     68                $error_msg .= "Graph timeperiod reset: start and end date/time can't be the same";
     69                $period_stop = '';
     70                $period_start = '';
     71            }
     72        }
     73    }
     74
     75    $error_msg .= "</B></FONT>";
     76    // doe checks en set error en error_msg in case shit
     77
     78    if( $show_msg )
     79        $tpl->assign( "form_error_msg", $error_msg );
     80
     81    return ($error ? 0 : 1 );
    8282}
    8383
    8484function datetimeToEpoch( $datetime ) {
    8585
    86         $datetime_fields = explode( ' ', $datetime );
    87 
    88         $date = $datetime_fields[0];
    89         $time = $datetime_fields[1];
    90 
    91         $date_fields = explode( '-', $date );
    92 
    93         $days = $date_fields[0];
    94         $months = $date_fields[1];
    95         $years = $date_fields[2];
    96 
    97         $time_fields = explode( ':', $time );
    98 
    99         $hours = $time_fields[0];
    100         $minutes = $time_fields[1];
    101         $seconds = $time_fields[2];
    102 
    103         $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years );
    104 
    105         return $timestamp;
     86    $datetime_fields = explode( ' ', $datetime );
     87
     88    $date = $datetime_fields[0];
     89    $time = $datetime_fields[1];
     90
     91    $date_fields = explode( '-', $date );
     92
     93    $days = $date_fields[0];
     94    $months = $date_fields[1];
     95    $years = $date_fields[2];
     96
     97    $time_fields = explode( ':', $time );
     98
     99    $hours = $time_fields[0];
     100    $minutes = $time_fields[1];
     101    $seconds = $time_fields[2];
     102
     103    $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years );
     104
     105    return $timestamp;
    106106}
    107107
     
    206206                                        break;
    207207
    208                                 case "finished":
    209                                         $sorted[$jobid] = $stop_time;
    210                                         break;
     208                case "finished":
     209                    $sorted[$jobid] = $stop_time;
     210                    break;
    211211
    212212                                case "runningtime":
     
    229229
    230230function makeSearchPage() {
    231         global $clustername, $tpl, $id, $owner, $name, $start_from_time, $start_to_time, $queue;
    232         global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up, $hc;
    233         global $period_start, $period_stop, $sortby, $sortorder, $COLUMN_REQUESTED_MEMORY;
    234         global $SEARCH_RESULT_LIMIT, $COLUMN_NODES, $metricname;
    235 
    236         $longtitle = "Batch Archive Search :: Powered by Job Monarch!";
    237         $title = "Batch Archive Search";
    238 
    239         makeHeader( 'search', $title, $longtitle );
    240 
    241         $tpl->assign( "cluster", $clustername );
    242         $tpl->assign( "id_value", $id );
    243         $tpl->assign( "owner_value", $owner);
    244         $tpl->assign( "queue_value", $queue );
    245         $tpl->assign( "name_value", $name );
    246         $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) );
    247         $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) );
    248         $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) );
    249         $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) );
    250 
    251         if( validateFormInput() ) {
    252 
    253                 $tpl->newBlock( "search_results" );
    254                 $tpl->assign( "sortby", $sortby);
    255                 $tpl->assign( "sortorder", $sortorder);
    256                 $tdb = new TarchDbase( "127.0.0.1" );
    257                 if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time );
    258                 if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time );
    259                 if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time );
    260                 if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time );
    261                 $search_ids = $tdb->searchDbase( $id, $queue, $owner, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time );
    262 
    263                 if( ($tdb->resultcount) > (int) $SEARCH_RESULT_LIMIT ) {
    264                         $tpl->gotoBlock( "_ROOT" );
    265                
    266                         $tpl->assign( "form_error_msg", "Got " . $tdb->resultcount . " search results, output limited to last " . $SEARCH_RESULT_LIMIT . " jobs." );
    267                         $tpl->gotoBlock( "search_results" );
    268                 }
    269 
    270                 $jobs = array();
    271                 $nodes = array();
    272 
    273                 $even = 1;
    274 
    275                 foreach( $search_ids as $myid ) {
    276 
    277                         $jobs[$myid] = $tdb->getJobArray( $myid );
    278                         $nodes[$myid] = $tdb->getNodesForJob( $myid );
    279                 }
    280 
    281                 if( $COLUMN_REQUESTED_MEMORY ) {
    282                         $tpl->newBlock( "column_header_req_mem" );
    283                 }
    284                 if( $COLUMN_NODES ) {
    285                         $tpl->newBlock( "column_header_nodes" );
    286                 }
    287 
    288                 $sorted_search = sortJobs( $jobs, $nodes, $sortby, $sortorder );
    289 
    290                 foreach( $sorted_search as $sortid ) {
    291 
    292                         $job = $jobs[$sortid];
    293                         $foundid = $job['id'];
    294 
    295                         $tpl->newBlock( "node" );
    296                         $tpl->assign( "id", $job['id'] );
    297                         $tpl->assign( "state", $job['status'] );
    298                         $tpl->assign( "owner", $job['owner'] );
    299                         $tpl->assign( "queue", $job['queue'] );
    300                         $tpl->assign( "name", $job['name'] );
    301                         $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job['requested_time'] ) ) );
    302 
    303                         if( $COLUMN_REQUESTED_MEMORY ) {
    304                                 $tpl->newBlock( "column_req_mem" );
    305                                 $tpl->assign( "req_memory", $job['requested_memory'] );
    306                                 $tpl->gotoBlock( "node" );
    307                         }
    308                         if( $COLUMN_NODES) {
    309 
    310                                 $job_nodes      = array();
    311 
    312                                 foreach( $nodes[$foundid] as $mynode )
    313                                         $job_nodes[] = $mynode['hostname'];
    314 
    315                                 $tpl->newBlock( "column_nodes" );
    316                                 $nodes_hostnames = implode( " ", $job_nodes );
    317                                 $tpl->assign( "nodes_hostnames", $nodes_hostnames );
    318                                 $tpl->gotoBlock( "node" );
    319                         }
    320 
    321                         $nodes_nr = count( $nodes[$foundid] );
    322 
    323                         if( $even ) {
    324 
    325                                 $tpl->assign("nodeclass", "even");
    326                                 $even = 0;
    327                         } else {
    328 
    329                                 $tpl->assign("nodeclass", "odd");
    330                                 $even = 1;
    331                         }
    332 
    333                         $ppn = (int) $job['ppn'] ? $job['ppn'] : 1;
    334                         $cpus = $nodes_nr * $ppn;
    335 
    336                         $tpl->assign( "nodes", $nodes_nr );
    337                         $tpl->assign( "cpus", $cpus );
    338 
    339                         $job_start = $job['start_timestamp'];
    340                         $job_stop = $job['stop_timestamp'];
    341                         $runningtime = intval( $job_stop - $job_start );
    342                         $tpl->assign( "started", makeDate( $job_start ) );
    343                         $tpl->assign( "finished", makeDate( $job_stop ) );
    344                         $tpl->assign( "runningtime", makeTime( $runningtime ) );
    345                        
    346                 }
    347 
    348                 if( count( $search_ids ) == 1 ) {
    349 
    350                         $tpl->newBlock( "showhosts" );
    351 
    352                         $showhosts = isset($sh) ? $sh : $default_showhosts;
    353                         $tpl->assign("checked$showhosts", "checked");
    354 
    355                         # Present a width list
    356                         $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"archive_search_form.submit();\">\n";
    357 
    358                         $hostcols = ($hc) ? $hc : 4;
    359 
    360                         foreach(range(1,25) as $cols) {
    361                                 $cols_menu .= "<OPTION VALUE=$cols ";
    362                                 if ($cols == $hostcols)
    363                                         $cols_menu .= "SELECTED";
    364                                 $cols_menu .= ">$cols\n";
    365                         }
    366                         $cols_menu .= "</SELECT>\n";
    367 
    368                         $tpl->assign("metric","$metricname $units");
    369                         $tpl->assign("id", $id);
    370                         # Host columns menu defined in header.php
    371                         $tpl->assign("cols_menu", $cols_menu);
    372 
    373                         if( $showhosts ) {
    374 
    375                                 if( !$period_start ) // Add an extra 10% to graphstart
    376                                         $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) );
    377                                 else
    378                                         $period_start = datetimeToEpoch( $period_start );
    379 
    380                                 if( !$period_stop ) // Add an extra 10% to graphend
    381                                         $period_stop = intval( $job_stop + (intval( $runningtime * 0.10 ) ) );
    382                                 else
    383                                         $period_stop = datetimeToEpoch( $period_stop );
    384 
    385                                 $tpl->gotoBlock( "timeperiod" );
    386 
    387                                 $tpl->assign("period_start", epochToDatetime( $period_start ) );
    388                                 $tpl->assign("period_stop", epochToDatetime( $period_stop ) );
    389 
    390                                 $tpl->gotoBlock( "_ROOT" );
    391 
    392                                 $hosts_up = array();
    393 
    394                                 foreach( $nodes[$id] as $mynode )
    395                                         $hosts_up[] = $mynode['hostname'];
    396 
    397                                 $sorted_hosts = array();
    398 
    399                                 foreach ($hosts_up as $host ) {
    400                                         $cpus = $metrics[$host]["cpu_num"]['VAL'];
    401                                         if (!$cpus) $cpus=1;
    402                                         $load_one  = $metrics[$host]["load_one"]['VAL'];
    403                                         $load = ((float) $load_one)/$cpus;
    404                                         $host_load[$host] = $load;
    405                                         $percent_hosts['load_color'.($load)] += 1;
    406                                         if ($metricname=="load_one")
    407                                                 $sorted_hosts[$host] = $load;
    408                                         else
    409                                                 $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL'];
    410                                 }
    411                                 switch ($sort) {
    412                                         case "descending":
    413                                                 arsort($sorted_hosts);
    414                                                 break;
    415                                         case "by hostname":
    416                                                 ksort($sorted_hosts);
    417                                                 break;
    418                                         default:
    419                                         case "ascending":
    420                                                 asort($sorted_hosts);
    421                                                 break;
    422                                 }
    423 
    424                                 # First pass to find the max value in all graphs for this
    425                                 # metric. The $start,$end variables comes from get_context.php,
    426                                 # included in index.php.
    427                                 list($min, $max) = find_limits($sorted_hosts, $metricname);
    428 
    429                                 # Second pass to output the graphs or metrics.
    430                                 $i = 1;
    431                                 foreach ( $sorted_hosts as $host=>$value  ) {
    432                                         $tpl->newBlock ("sorted_list");
    433                                         $host_url = rawurlencode($host);
    434                                         $cluster_url = rawurlencode($clustername);
    435 
    436                                         $textval = "";
    437                                         $val = $metrics[$host][$metricname];
    438                                         $class = "metric";
    439                                         $host_link="\"?j_view=host&c=$cluster_url&h=$host_url&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop\"";
    440 
    441                                         if ($val['TYPE']=="timestamp" or $always_timestamp[$metricname]) {
    442                                                 $textval = date("r", $val['VAL']);
    443                                         } elseif ($val['TYPE']=="string" or $val['SLOPE']=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
    444                                                 $textval = "$val['VAL'] $val['UNITS']";
    445                                         } else {
    446                                                 $graphargs = "z=small&c=$cluster_url&m=$metricname&h=$host_url&v=$val['VAL']&x=$max&n=$min&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop&min=$min&max=$max";
    447                                         }
    448                                         if ($textval) {
    449                                                 $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
    450                                         } else {
    451                                                 $cell="<td><a href=$host_link>".  "<img src=\"./graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
    452                                         }
    453 
    454                                         $tpl->assign("metric_image", $cell);
    455                                         if (! ($i++ % $hostcols) )
    456                                                 $tpl->assign ("br", "</tr><tr>");
    457                                 }
    458 
    459                         }
    460                 }
    461 
    462         }
     231    global $clustername, $tpl, $id, $owner, $name, $start_from_time, $start_to_time, $queue;
     232    global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up, $hc;
     233    global $period_start, $period_stop, $sortby, $sortorder, $COLUMN_REQUESTED_MEMORY;
     234    global $SEARCH_RESULT_LIMIT, $COLUMN_NODES, $metricname;
     235
     236    $longtitle = "Batch Archive Search :: Powered by Job Monarch!";
     237    $title = "Batch Archive Search";
     238
     239    makeHeader( 'search', $title, $longtitle );
     240
     241    $tpl->assign( "cluster", $clustername );
     242    $tpl->assign( "id_value", $id );
     243    $tpl->assign( "owner_value", $owner);
     244    $tpl->assign( "queue_value", $queue );
     245    $tpl->assign( "name_value", $name );
     246    $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) );
     247    $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) );
     248    $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) );
     249    $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) );
     250
     251    if( validateFormInput() ) {
     252
     253        $tpl->newBlock( "search_results" );
     254        $tpl->assign( "sortby", $sortby);
     255        $tpl->assign( "sortorder", $sortorder);
     256        $tdb = new TarchDbase( "127.0.0.1" );
     257        if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time );
     258        if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time );
     259        if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time );
     260        if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time );
     261        $search_ids = $tdb->searchDbase( $id, $queue, $owner, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time );
     262
     263        if( ($tdb->resultcount) > (int) $SEARCH_RESULT_LIMIT ) {
     264            $tpl->gotoBlock( "_ROOT" );
     265       
     266            $tpl->assign( "form_error_msg", "Got " . $tdb->resultcount . " search results, output limited to last " . $SEARCH_RESULT_LIMIT . " jobs." );
     267            $tpl->gotoBlock( "search_results" );
     268        }
     269
     270        $jobs = array();
     271        $nodes = array();
     272
     273        $even = 1;
     274
     275        foreach( $search_ids as $myid ) {
     276
     277            $jobs[$myid] = $tdb->getJobArray( $myid );
     278            $nodes[$myid] = $tdb->getNodesForJob( $myid );
     279        }
     280
     281        if( $COLUMN_REQUESTED_MEMORY ) {
     282            $tpl->newBlock( "column_header_req_mem" );
     283        }
     284        if( $COLUMN_NODES ) {
     285            $tpl->newBlock( "column_header_nodes" );
     286        }
     287
     288        $sorted_search = sortJobs( $jobs, $nodes, $sortby, $sortorder );
     289
     290        foreach( $sorted_search as $sortid ) {
     291
     292            $job = $jobs[$sortid];
     293            $foundid = $job['id'];
     294
     295            $tpl->newBlock( "node" );
     296            $tpl->assign( "id", $job['id'] );
     297            $tpl->assign( "state", $job['status'] );
     298            $tpl->assign( "owner", $job['owner'] );
     299            $tpl->assign( "queue", $job['queue'] );
     300            $tpl->assign( "name", $job['name'] );
     301            $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job['requested_time'] ) ) );
     302
     303            if( $COLUMN_REQUESTED_MEMORY ) {
     304                $tpl->newBlock( "column_req_mem" );
     305                $tpl->assign( "req_memory", $job['requested_memory'] );
     306                $tpl->gotoBlock( "node" );
     307            }
     308            if( $COLUMN_NODES) {
     309
     310                $job_nodes    = array();
     311
     312                foreach( $nodes[$foundid] as $mynode )
     313                    $job_nodes[] = $mynode['hostname'];
     314
     315                $tpl->newBlock( "column_nodes" );
     316                $nodes_hostnames = implode( " ", $job_nodes );
     317                $tpl->assign( "nodes_hostnames", $nodes_hostnames );
     318                $tpl->gotoBlock( "node" );
     319            }
     320
     321            $nodes_nr = count( $nodes[$foundid] );
     322
     323            if( $even ) {
     324
     325                $tpl->assign("nodeclass", "even");
     326                $even = 0;
     327            } else {
     328
     329                $tpl->assign("nodeclass", "odd");
     330                $even = 1;
     331            }
     332
     333            $ppn = (int) $job['ppn'] ? $job['ppn'] : 1;
     334            $cpus = $nodes_nr * $ppn;
     335
     336            $tpl->assign( "nodes", $nodes_nr );
     337            $tpl->assign( "cpus", $cpus );
     338
     339            $job_start = $job['start_timestamp'];
     340            $job_stop = $job['stop_timestamp'];
     341            $runningtime = intval( $job_stop - $job_start );
     342            $tpl->assign( "started", makeDate( $job_start ) );
     343            $tpl->assign( "finished", makeDate( $job_stop ) );
     344            $tpl->assign( "runningtime", makeTime( $runningtime ) );
     345           
     346        }
     347
     348        if( count( $search_ids ) == 1 ) {
     349
     350            $tpl->newBlock( "showhosts" );
     351
     352            $showhosts = isset($sh) ? $sh : $default_showhosts;
     353            $tpl->assign("checked$showhosts", "checked");
     354
     355            # Present a width list
     356            $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"archive_search_form.submit();\">\n";
     357
     358            $hostcols = ($hc) ? $hc : 4;
     359
     360            foreach(range(1,25) as $cols) {
     361                $cols_menu .= "<OPTION VALUE=$cols ";
     362                if ($cols == $hostcols)
     363                    $cols_menu .= "SELECTED";
     364                $cols_menu .= ">$cols\n";
     365            }
     366            $cols_menu .= "</SELECT>\n";
     367
     368            $tpl->assign("metric","$metricname $units");
     369            $tpl->assign("id", $id);
     370            # Host columns menu defined in header.php
     371            $tpl->assign("cols_menu", $cols_menu);
     372
     373            if( $showhosts ) {
     374
     375                if( !$period_start ) // Add an extra 10% to graphstart
     376                    $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) );
     377                else
     378                    $period_start = datetimeToEpoch( $period_start );
     379
     380                if( !$period_stop ) // Add an extra 10% to graphend
     381                    $period_stop = intval( $job_stop + (intval( $runningtime * 0.10 ) ) );
     382                else
     383                    $period_stop = datetimeToEpoch( $period_stop );
     384
     385                        $tpl->gotoBlock( "timeperiod" );
     386
     387                $tpl->assign("period_start", epochToDatetime( $period_start ) );
     388                $tpl->assign("period_stop", epochToDatetime( $period_stop ) );
     389
     390                        $tpl->gotoBlock( "_ROOT" );
     391
     392                $hosts_up = array();
     393
     394                foreach( $nodes[$id] as $mynode )
     395                    $hosts_up[] = $mynode['hostname'];
     396
     397                $sorted_hosts = array();
     398
     399                foreach ($hosts_up as $host ) {
     400                    $cpus = $metrics[$host]["cpu_num"]['VAL'];
     401                    if (!$cpus) $cpus=1;
     402                    $load_one  = $metrics[$host]["load_one"]['VAL'];
     403                    $load = ((float) $load_one)/$cpus;
     404                    $host_load[$host] = $load;
     405                    $percent_hosts['load_color'.($load)] += 1;
     406                    if ($metricname=="load_one")
     407                        $sorted_hosts[$host] = $load;
     408                    else
     409                        $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL'];
     410                }
     411                switch ($sort) {
     412                    case "descending":
     413                        arsort($sorted_hosts);
     414                        break;
     415                    case "by hostname":
     416                        ksort($sorted_hosts);
     417                        break;
     418                    default:
     419                    case "ascending":
     420                        asort($sorted_hosts);
     421                        break;
     422                }
     423
     424                # First pass to find the max value in all graphs for this
     425                # metric. The $start,$end variables comes from get_context.php,
     426                # included in index.php.
     427                list($min, $max) = find_limits($sorted_hosts, $metricname);
     428
     429                # Second pass to output the graphs or metrics.
     430                $i = 1;
     431                foreach ( $sorted_hosts as $host=>$value  ) {
     432                    $tpl->newBlock ("sorted_list");
     433                    $host_url = rawurlencode($host);
     434                    $cluster_url = rawurlencode($clustername);
     435
     436                    $textval = "";
     437                    $val = $metrics[$host][$metricname];
     438                    $class = "metric";
     439                    $host_link="\"?j_view=host&c=$cluster_url&h=$host_url&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop\"";
     440
     441                    if ($val['TYPE']=="timestamp" or $always_timestamp[$metricname]) {
     442                        $textval = date("r", $val['VAL']);
     443                    } elseif ($val['TYPE']=="string" or $val['SLOPE']=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
     444                        $textval = "$val['VAL'] $val['UNITS']";
     445                    } else {
     446                        $graphargs = "z=small&c=$cluster_url&m=$metricname&h=$host_url&v=$val['VAL']&x=$max&n=$min&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop&min=$min&max=$max";
     447                    }
     448                    if ($textval) {
     449                        $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
     450                    } else {
     451                        $cell="<td><a href=$host_link>".  "<img src=\"./graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
     452                    }
     453
     454                    $tpl->assign("metric_image", $cell);
     455                    if (! ($i++ % $hostcols) )
     456                        $tpl->assign ("br", "</tr><tr>");
     457                }
     458
     459            }
     460        }
     461
     462    }
    463463}
    464464?>
Note: See TracChangeset for help on using the changeset viewer.