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

Last change on this file since 246 was 246, checked in by bastiaans, 18 years ago

web/addons/job_monarch/conf.php:

  • added DATETIME_FORMAT

web/addons/job_monarch/libtoga.php:

  • added makeDate()

web/addons/job_monarch/search.php,
web/addons/job_monarch/overview.php:

  • disable local makeDate, use from libtoga

web/addons/job_monarch/search.php

  • Property svn:keywords set to Id
File size: 20.7 KB
RevLine 
[113]1<?php
[225]2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006  Ramon Bastiaans
7 *
8 * Jobmonarch is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Jobmonarch is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
[231]22 * SVN $Id: overview.php 246 2006-04-11 09:46:19Z bastiaans $
[225]23 */
24
[126]25global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh;
[242]26global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED;
[114]27
[140]28//$tpl->assign("_ROOT.summary", "" );
29
[163]30$data_gatherer = new DataGatherer( $clustername );
[114]31
[117]32//$tpl->assign( "self", "./index.php" );
[116]33$tpl->assign( "clustername", $clustername );
34
[206]35if( $JOB_ARCHIVE )
[129]36        $tpl->assign( "cluster_url", rawurlencode($clustername) );
37
[114]38$data_gatherer->parseXML();
[117]39
[114]40$heartbeat = $data_gatherer->getHeartbeat();
41$jobs = $data_gatherer->getJobs();
[126]42$gnodes = $data_gatherer->getNodes();
[124]43$cpus = $data_gatherer->getCpus();
[114]44
[122]45$filter_image_url = "";
46
[119]47foreach( $filter as $filtername => $filtervalue ) {
48        $tpl->assign( "f_".$filtername, $filtervalue );
[122]49        $filter_image_url .= "&$filtername=$filtervalue";
[119]50}
51
[122]52$tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
[138]53$tpl->assign( "f_order", $filterorder );
[122]54
[126]55if( array_key_exists( "id", $filter ) )
[127]56        $piefilter = 'id';
[126]57else if( array_key_exists( "user", $filter ) )
[127]58        $piefilter = 'user';
[126]59else if( array_key_exists( "queue", $filter ) )
[127]60        $piefilter = 'queue';
[114]61
[127]62$pie = drawPie();
[114]63$tpl->assign("pie", $pie );
64
[122]65//if( !array_key_exists( 'id', $filter ) ) {
66
67//      $graph_args = "c=$cluster_url&$get_metric_string&st=$cluster[LOCALTIME]";
68//      $tpl->newBlock( "average_graphs" );
69//      $tpl->assign( "graph_args", $graph_args );
70//}
71
[120]72function timeToEpoch( $time ) {
73
74        $time_fields = explode( ':', $time );
75
76        if( count($time_fields) == 3 ) {
77
78                $hours = $time_fields[0];
79                $minutes = $time_fields[1];
80                $seconds = $time_fields[2];
81
[128]82        } else if( count($time_fields) == 2 ) {
83
84                $hours = 0;
85                $minutes = $time_fields[0];
86                $seconds = $time_fields[1];
87
88        } else if( count($time_fields) == 1 ) {
89
90                $hours = 0;
91                $minutes = 0;
92                $seconds = $time_fields[0];
[120]93        }
[128]94
95        $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
96
97        return $myepoch;
[120]98}
99
[114]100function makeTime( $time ) {
101
102        $days = intval( $time / 86400 );
[128]103        $time = ($days>0) ? $time % ($days * 86400) : $time;
[115]104
[128]105        //printf( "time = %s, days = %s\n", $time, $days );
106
107        $date_str = '';
108        $day_str = '';
109
[114]110        if( $days > 0 ) {
111                if( $days > 1 )
[128]112                        $day_str .= $days . ' days';
[114]113                else
[128]114                        $day_str .= $days . ' day';
[114]115        }
[115]116
[114]117        $hours = intval( $time / 3600 );
[115]118        $time = $hours ? $time % ($hours * 3600) : $time;
119
[128]120        //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );
121
[114]122        if( $hours > 0 ) {
123                $date_str .= $hours . ':';
[128]124                $date_unit = 'hours';
[114]125        }
[115]126               
[114]127        $minutes = intval( $time / 60 );
[115]128        $seconds = $minutes ? $time % ($minutes * 60) : $time;
129
[114]130        if( $minutes > 0 ) {
[115]131
132                if( $minutes >= 10 )
133                        $date_str .= $minutes . ':';
134                else
135                        $date_str .= '0' . $minutes . ':';
136
[114]137                $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
[128]138        } else {
139                if($hours > 0 ) {
140                        $date_str .= '00:';
141                        $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
142                }
[114]143        }
[115]144
[128]145
[114]146        $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
147
[115]148        if( $seconds > 0 ) {
149
150                if( $seconds >= 10 )
151                        $date_str .= $seconds . ' ' . $date_unit;
152                else
153                        $date_str .= '0' . $seconds . ' ' . $date_unit;
154                       
[128]155        } else if ( $hours > 0 or $minutes > 0 )
156
[115]157                $date_str .= '00 ' . $date_unit;
158
[128]159        if( $days > 0) {
160
161                if( $hours > 0 or $minutes > 0 or $seconds > 0 )
162                        $date_str = $day_str . ' - ' . $date_str;
163                else
164                        $date_str = $day_str;
165        }
166
[114]167        return $date_str;
168}
169
[246]170//function makeDate( $time ) {
171//      return strftime( "%a %d %b %Y %H:%M:%S", $time );
172//}
[114]173
174function colorRed( $color ) {
175        return substr( $color, 0, 2 );
176}
177function colorGreen( $color ) {
178        return substr( $color, 2, 2 );
179}
180function colorBlue( $color ) {
181        return substr( $color, 4, 2 );
182}
183
184function colorDiffer( $first, $second ) {
185
186        // Make sure these two colors differ atleast 50 R/G/B
187        $min_diff = 50;
188
[147]189        $c1r = hexDec( colorRed( $first ) );
190        $c1g = hexDec( colorGreen( $first ) );
191        $c1b = hexDec( colorBlue( $first ) );
[114]192
[147]193        $c2r = hexDec( colorRed( $second ) );
194        $c2g = hexDec( colorGreen( $second ) );
195        $c2b = hexDec( colorBlue( $second ) );
[114]196
197        $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
198        $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
199        $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
200
201        if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
202                return TRUE;
203        else
204                return FALSE;
205}
206
207function randomColor( $known_colors ) {
208
[147]209        $start = "004E00";
210       
211        $start_red = colorRed( $start );
212        $start_green = colorGreen( $start );
213        $start_blue = colorBlue( $start );
214       
215        $end = "FFFFFF";
[114]216
[147]217        $end_red = colorRed( $end );
218        $end_green = colorGreen( $end );
219        $end_blue = colorBlue( $end );
[114]220
[147]221        $change_color = TRUE;
[114]222
[147]223        while( $change_color ) {
[114]224
[147]225                $change_color = FALSE;
[114]226
[147]227                $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) );
228                $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) );
229                $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
[114]230
[147]231                $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
[114]232
[147]233                foreach( $known_colors as $old )
[114]234
[147]235                        if( !colorDiffer( $new, $old ) )
[114]236
[147]237                                $change_color = TRUE;
[114]238        }
239
240        // Whoa! Actually found a good color ;)
[147]241        return $new;
[114]242}
243
[126]244function drawJobPie() {
245}
[114]246
[126]247function drawUserPie() {
[124]248
[126]249}
250
251function drawQueuePie() {
252
253}
254
255
[127]256function drawPie() {
[124]257
[127]258        global $jobs, $gnodes, $piefilter, $filter;
[114]259
[126]260        $nodes = $gnodes;
[127]261
262        if( isset($piefilter) ) 
263                $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage");
264        else
265                $pie_args = "title=" . rawurlencode("Cluster queue usage");
266               
[114]267        $pie_args .= "&size=250x150";
268
269        $queues = array();
270        $nr_jobs = count( $jobs );
271        $nr_nodes = count( $nodes );
272
273        $emptynodes = 0;
274
[123]275        $job_weight = array();
276
[114]277        foreach( $nodes as $node ) {
278
279                $myjobs = $node->getJobs();
280
281                if( count( $myjobs ) == 0 )
282                        $emptynodes++;
283        }
[123]284        $used_nodes = $nr_nodes - $emptynodes;
[114]285
286        $empty_percentage = ($emptynodes / $nr_nodes) * 100;
287        $job_percentage = 100 - $empty_percentage; 
288
[127]289        $qcolors = array();
[114]290        $color = randomColor( $qcolors );
291        $qcolors[] = $color;
292        $pie_args .= "&free=$empty_percentage,$color";
293
[127]294        if( isset( $piefilter ) )
295                $filterpie = array();
296
[123]297        foreach( $nodes as $node ) {
[114]298
[123]299                $node_jobs = $node->getJobs();
300                $nr_node_jobs = count( $node_jobs );
301                $myhost = $node->getHostname();
[114]302
[123]303                foreach( $node_jobs as $myjob ) {
[114]304
[123]305                        // Determine the weight of this job on the node it is running
306                        // - what percentage of the node is in use by this job
307                        //
308                        $job_weight[$myjob] = ( 100 / count( $node_jobs ) ) / 100;
309                        $qname = $jobs[$myjob][queue];
310
[127]311                        if( isset($piefilter) ) {
312                                $countjob = 1;
313                                if( $piefilter == 'id' ) {
314                                        if( $myjob != $filter[$piefilter] )
315                                                $countjob = 0;
316                                } else if( $piefilter == 'user' ) {
317                                        if( $jobs[$myjob][owner] != $filter[$piefilter] )
318                                                $countjob = 0;
319                                } else {
320                                        if( $jobs[$myjob][$piefilter] != $filter[$piefilter] )
321                                                $countjob = 0;
322                                }
323
324                                if( $countjob ) {
325
326                                        if( !isset( $filterpie[$filter[$piefilter]] ) )
327                                                $filterpie[$filter[$piefilter]] = $job_weight[$myjob];
328                                        else
329                                                $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob];
330                                } else {
331                                        if( !isset( $filterpie["other"] ) )
332                                                $filterpie["other"] = $job_weight[$myjob];
333                                        else
334                                                $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob];
335
336                                }
337                               
338                        } else {
339
340                                if( !isset( $queues[$qname] ) )
341                                        $queues[$qname] = $job_weight[$myjob];
342                                else
343                                        $queues[$qname] = $queues[$qname] + $job_weight[$myjob];
344                        }
[114]345                }
346        }
347
[127]348        //$qcolors = array();
349        if( isset( $piefilter ) )
350                $graphvals = $filterpie;
351        else
352                $graphvals = $queues;
[114]353
[127]354        foreach( $graphvals as $name => $totalweight) {
355
[123]356                $percentage = ( $totalweight / $used_nodes ) * $job_percentage;
357               
[114]358                $color = randomColor( $qcolors );
359                $qcolors[] = $color;
[127]360                $pie_args .= "&$name=$percentage,$color";
[114]361        }
362        $pie = "../../pie.php?$pie_args";
363
364        return $pie;
365}
366
367
[117]368function sortJobs( $jobs, $sortby, $sortorder ) {
[114]369
[117]370        $sorted = array();
[114]371
[117]372        $cmp = create_function( '$a, $b', 
373                "global \$sortby, \$sortorder;".
[116]374
[117]375                "if( \$a == \$b ) return 0;".
[116]376
[117]377                "if (\$sortorder==\"desc\")".
378                        "return ( \$a < \$b ) ? 1 : -1;".
379                "else if (\$sortorder==\"asc\")".
380                        "return ( \$a > \$b ) ? 1 : -1;" );
381
382        foreach( $jobs as $jobid => $jobattrs ) {
383
384                        $state = $jobattrs[status];
385                        $user = $jobattrs[owner];
386                        $queue = $jobattrs[queue];
387                        $name = $jobattrs[name];
388                        $req_cpu = $jobattrs[requested_time];
389                        $req_memory = $jobattrs[requested_memory];
[135]390
391                        if( $state == 'R' )
392                                $nodes = count( $jobattrs[nodes] );
393                        else
394                                $nodes = $jobattrs[nodes];
395
[117]396                        $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
397                        $cpus = $nodes * $ppn;
[245]398                        $queued_time = (int) $jobattrs[queued_timestamp];
[117]399                        $start_time = (int) $jobattrs[start_timestamp];
400                        $runningtime = $report_time - $start_time;
401
402                        switch( $sortby ) {
403                                case "id":
404                                        $sorted[$jobid] = $jobid;
405                                        break;
406
407                                case "state":
408                                        $sorted[$jobid] = $state;
409                                        break;
410
411                                case "user":
412                                        $sorted[$jobid] = $user;
413                                        break;
414
415                                case "queue":
416                                        $sorted[$jobid] = $queue;
417                                        break;
418
419                                case "name":
420                                        $sorted[$jobid] = $name;
421                                        break;
422
423                                case "req_cpu":
[128]424                                        $sorted[$jobid] = timeToEpoch( $req_cpu );
[117]425                                        break;
426
427                                case "req_mem":
428                                        $sorted[$jobid] = $req_memory;
429                                        break;
430
431                                case "nodes":
432                                        $sorted[$jobid] = $nodes;
433                                        break;
434
435                                case "cpus":
436                                        $sorted[$jobid] = $cpus;
437                                        break;
438
[245]439                                case "queued":
440                                        $sorted[$jobid] = $queued_time;
441                                        break;
442
[117]443                                case "start":
444                                        $sorted[$jobid] = $start_time;
445                                        break;
446
447                                case "runningtime":
448                                        $sorted[$jobid] = $runningtime;
449                                        break;
450
451                                default:
452                                        break;
453
454                        }
455        }
456
[128]457        //uasort( $sorted, $cmp );
458        if( $sortorder == "asc" )
459                arsort( $sorted );
460        else if( $sortorder == "desc" )
461                asort( $sorted );
[117]462
463        return $sorted;
464}
465
466function makeOverview() {
467
468        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
[126]469        global $sortorder, $sortby, $filter, $sh, $hc, $m;
470        global $cluster_url, $get_metric_string, $host_url, $metrics;
[129]471        global $start, $end, $reports, $gnodes, $default_showhosts;
[242]472        global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY;
[126]473        $metricname = $m;
474
[117]475        $tpl->assign("sortorder", $sortorder );
476        $tpl->assign("sortby", $sortby );
477
478        $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder );
479
[118]480        $even = 1;
481
[135]482        $used_jobs = 0;
483        $used_cpus = 0;
484        $used_nodes = 0;
[124]485
[208]486        $queued_jobs = 0;
487        $queued_nodes = 0;
488        $queued_cpus = 0;
489
490        $total_nodes = 0;
491        $total_cpus = 0;
492        $total_jobs = 0;
493
[135]494        $all_used_nodes = array();
[208]495        $total_used_nodes = array();
[124]496
[208]497        $running_name_nodes = array();
498
499        $running_nodes = 0;
500        $running_jobs = 0;
501        $running_cpus = 0;
502
[135]503        $avail_nodes = count( $gnodes );
504        $avail_cpus = cluster_sum("cpu_num", $metrics);
505
506        $view_cpus = 0;
507        $view_jobs = 0;
508        $view_nodes = 0;
509
[208]510        $all_nodes = 0;
511        $all_jobs = 0;
512        $all_cpus = 0;
[135]513
[208]514        $view_name_nodes = array();
515
[241]516        if( $COLUMN_REQUESTED_MEMORY ) {
[242]517                $tpl->newBlock( "column_header_req_mem" );
[241]518        }
519
[242]520        if( $COLUMN_QUEUED ) {
521                $tpl->newBlock( "column_header_queued" );
522        }
523
[117]524        foreach( $sorted_jobs as $jobid => $sortdec ) {
525
526                $report_time = $jobs[$jobid][reported];
527
[208]528                if( $jobs[$jobid][status] == 'R' )
529                        $nodes = count( $jobs[$jobid][nodes] );
530                else if( $jobs[$jobid][status] == 'Q' )
531                        $nodes = $jobs[$jobid][nodes];
532
[124]533                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
534                $cpus = $nodes * $ppn;
535
[208]536                if( $report_time == $heartbeat ) {
[124]537
[208]538                        $display_job = 1;
539
540                        foreach( $jobs[$jobid][nodes] as $tempnode )
541                                $all_used_nodes[] = $tempnode;
542
[135]543                        $used_cpus += $cpus;
544
[208]545                        if( $jobs[$jobid][status] == 'R' ) {
546                                $running_cpus += $cpus;
547                                $running_jobs++;
[117]548
[208]549                                foreach( $jobs[$jobid][nodes] as $tempnode )
550                                        $running_name_nodes[] = $tempnode;
551                        }
[117]552
[208]553                        if( $jobs[$jobid][status] == 'Q' ) {
554                                $queued_cpus += $cpus;
555                                $queued_nodes += $nodes;
556                                $queued_jobs++;
557                        }
558
[119]559                        foreach( $filter as $filtername=>$filtervalue ) {
[118]560
[124]561                                if( $filtername == 'id' && $jobid != $filtervalue )
562                                        $display_job = 0;
563                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
564                                        $display_job = 0;
565                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
566                                        $display_job = 0;
567                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
568                                        $display_job = 0;
[118]569                        }
570
[119]571                        if( $display_job ) {
[117]572
[119]573                                $tpl->newBlock("node");
574                                $tpl->assign( "clustername", $clustername );
575                                $tpl->assign("id", $jobid );
576                                $tpl->assign("state", $jobs[$jobid][status] );
[240]577
578                                $fullstate = '';
579                                if( $jobs[$jobid][status] == 'R' ) {
580                                        $fullstate = "Running";
581                                } else if( $jobs[$jobid][status] == 'Q' ) {
582                                        $fullstate = "Queued";
583                                }
584
585                                $tpl->assign("fullstate", $fullstate );
586                               
[119]587                                $tpl->assign("user", $jobs[$jobid][owner] );
588                                $tpl->assign("queue", $jobs[$jobid][queue] );
[240]589
590                                $fulljobname = $jobs[$jobid][name];
591                                $shortjobname = '';
592
593                                $tpl->assign("fulljobname", $fulljobname );
594
595                                if( mb_strwidth( $fulljobname ) > 10 ) {
596                                        $tpl->newBlock("jobname_hint_start");
597                                        $tpl->gotoBlock("node");
598
599                                        $shortjobname = mb_strimwidth( $fulljobname, 0, 9 ) . '..';
600                                } else {
601                                        $shortjobname = $fulljobname;
602                                }
603                               
604                                $tpl->assign("name", $shortjobname );
605
606                                if( strlen( $fulljobname ) > 10 ) {
607                                        $tpl->newBlock("jobname_hint_end");
608                                        $tpl->gotoBlock("node");
609                                }
610
[126]611                                $domain = $jobs[$jobid][domain];
[120]612                                $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
[135]613
[241]614                                if( $COLUMN_REQUESTED_MEMORY ) {
615                                        $tpl->newBlock( "column_req_mem" );
616                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
617                                        $tpl->gotoBlock( "node" );
618                                }
[135]619
[242]620                                if( $COLUMN_QUEUED ) {
621                                        $tpl->newBlock( "column_queued" );
[243]622                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
[242]623                                        $tpl->gotoBlock( "node" );
624                                }
625
[119]626                                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
627                                $cpus = $nodes * $ppn;
628                                $tpl->assign("nodes", $nodes );
629                                $tpl->assign("cpus", $cpus );
630                                $start_time = (int) $jobs[$jobid][start_timestamp];
[126]631                                $job_start = $start_time;
[119]632
[135]633                                $view_cpus += $cpus;
634                                $view_jobs++;
[124]635
[135]636                                if( $jobs[$jobid][status] == 'R' )
637                                        foreach( $jobs[$jobid][nodes] as $tempnode )
[208]638                                                $view_name_nodes[] = $tempnode;
[135]639                                else if( $jobs[$jobid][status] == 'Q' )
[208]640                                        $view_nodes += (int) $jobs[$jobid][nodes];
[135]641
[119]642                                if( $even ) {
643
644                                        $tpl->assign("nodeclass", "even");
645                                        $even = 0;
646                                } else {
647
648                                        $tpl->assign("nodeclass", "odd");
649                                        $even = 1;
650                                }
651
652                                if( $start_time ) {
653
654                                        $runningtime = makeTime( $report_time - $start_time );
[126]655                                        $job_runningtime = $report_time - $start_time;
[119]656                                        $tpl->assign("started", makeDate( $start_time ) );
657                                        $tpl->assign("runningtime", $runningtime );
658                                }
[117]659                        }
[116]660                }
[114]661        }
[135]662        array_unique( $all_used_nodes );
[208]663        array_unique( $view_name_nodes );
664        array_unique( $running_name_nodes );
665
[135]666        $used_nodes = count( $all_used_nodes );
[208]667        $view_nodes += count( $view_name_nodes );
668        $running_nodes += count( $running_name_nodes );
[124]669
[208]670        $total_nodes = $queued_nodes + $running_nodes;
671        $total_cpus = $queued_cpus + $running_cpus;
672        $total_jobs = $queued_jobs + $running_jobs;
673
[135]674        //$tpl->assignGlobal("cpus_nr", $overview_cpus );
675        //$tpl->assignGlobal("jobs_nr", $overview_jobs );
676
677        $tpl->assignGlobal("avail_nodes", $avail_nodes );
678        $tpl->assignGlobal("avail_cpus", $avail_cpus );
679
[208]680        $tpl->assignGlobal("queued_nodes", $queued_nodes );
681        $tpl->assignGlobal("queued_jobs", $queued_jobs );
682        $tpl->assignGlobal("queued_cpus", $queued_cpus );
683
684        $tpl->assignGlobal("total_nodes", $total_nodes );
685        $tpl->assignGlobal("total_jobs", $total_jobs );
686        $tpl->assignGlobal("total_cpus", $total_cpus );
687
688        $tpl->assignGlobal("running_nodes", $running_nodes );
689        $tpl->assignGlobal("running_jobs", $running_jobs );
690        $tpl->assignGlobal("running_cpus", $running_cpus );
691
[135]692        $tpl->assignGlobal("used_nodes", $used_nodes );
693        $tpl->assignGlobal("used_jobs", $used_jobs );
694        $tpl->assignGlobal("used_cpus", $used_cpus );
695
[209]696        $free_nodes = $avail_nodes - $running_nodes;
697        $free_cpus = $avail_cpus - $running_cpus;
[208]698
699        $tpl->assignGlobal("free_nodes", $free_nodes );
700        $tpl->assignGlobal("free_cpus", $free_cpus );
701
[135]702        $tpl->assignGlobal("view_nodes", $view_nodes );
703        $tpl->assignGlobal("view_jobs", $view_jobs );
704        $tpl->assignGlobal("view_cpus", $view_cpus );
705
[124]706        $tpl->assignGlobal("report_time", makeDate( $heartbeat));
707       
[135]708        //$tpl->assignGlobal("f_cpus_nr", $f_cpus );
709        //$tpl->assignGlobal("f_jobs_nr", $f_jobs );
[126]710
[188]711        if( intval($view_jobs) == 1 and $start_time ) {
[126]712                $tpl->newBlock( "showhosts" );
713
714                # Present a width list
715                $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
716
717                $hostcols = ($hc) ? $hc : 4;
718
719                foreach(range(1,25) as $cols) {
720                        $cols_menu .= "<OPTION VALUE=$cols ";
721                        if ($cols == $hostcols)
722                                $cols_menu .= "SELECTED";
723                        $cols_menu .= ">$cols\n";
724                }
725                $cols_menu .= "</SELECT>\n";
726
727                //$tpl->assign("cluster", $clustername);
728                $tpl->assign("metric","$metricname $units");
[127]729                $tpl->assign("id", $filter[id]);
[126]730                # Host columns menu defined in header.php
731                $tpl->assign("cols_menu", $cols_menu);
732
[129]733                $showhosts = isset($sh) ? $sh : $default_showhosts;
734                //if( !$showhosts) $showhosts = $default_showhosts;
[126]735                $tpl->assign("checked$showhosts", "checked");
736
737                if( $showhosts ) {
738                        //-----
739
740                        if( !isset($start) ) $start="jobstart";
741                        if( !isset($stop) ) $stop="now";
742                        //$tpl->assign("start", $start);
743                        //$tpl->assign("stop", $stop);
744
745                        $sorted_hosts = array();
746                        $hosts_up = $jobs[$filter[id]][nodes];
747
748                        $r = intval($job_runningtime * 1.25);
749
750                        $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ;
751                        $jobstart = $report_time - $job_runningtime;
752
753                        if ($reports[$metricname])
754                                $metricval = "g";
755                        else
756                                $metricval = "m";
757                                               
758                        foreach ($hosts_up as $host ) {
[195]759
760                                $domain_len = 0 - strlen( $domain );
761                                if( substr( $host, $domain_len ) != $domain ) {
762                                        $host = $host. '.'.$domain;
763                                }
[126]764                                $cpus = $metrics[$host]["cpu_num"][VAL];
765                                if (!$cpus) $cpus=1;
766                                $load_one  = $metrics[$host]["load_one"][VAL];
767                                $load = ((float) $load_one)/$cpus;
768                                $host_load[$host] = $load;
769                                $percent_hosts[load_color($load)] += 1;
770                                if ($metricname=="load_one")
771                                        $sorted_hosts[$host] = $load;
772                                else
773                                        $sorted_hosts[$host] = $metrics[$host][$metricname][VAL];
774                        }
775                        switch ($sort) {
776                                case "descending":
777                                        arsort($sorted_hosts);
778                                        break;
779                                case "by hostname":
780                                        ksort($sorted_hosts);
781                                        break;
782                                default:
783                                case "ascending":
784                                        asort($sorted_hosts);
785                                        break;
786                        }
787
788                        //$sorted_hosts = array_merge($down_hosts, $sorted_hosts);
789
790                        # First pass to find the max value in all graphs for this
791                        # metric. The $start,$end variables comes from get_context.php,
792                        # included in index.php.
793                        list($min, $max) = find_limits($sorted_hosts, $metricname);
794
795                        # Second pass to output the graphs or metrics.
796                        $i = 1;
797                        foreach ( $sorted_hosts as $host=>$value  ) {
798                                $tpl->newBlock ("sorted_list");
799                                //$host = $host. '.'.$domain;
800                                $host_url = rawurlencode($host);
801                                $cluster_url = rawurlencode($clustername);
802
803                                $textval = "";
804                                //printf("host = %s, value = %s", $host, $value);
805                                //echo "$host: $value, ";
806                                $val = $metrics[$host][$metricname];
807                                $class = "metric";
[148]808                                $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
[126]809
810                                if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) {
811                                        $textval = date("r", $val[VAL]);
812                                } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
813                                        $textval = "$val[VAL] $val[UNITS]";
814                                } else {
815                                        $load_color = load_color($host_load[$host]);
816                                        $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
[193]817                                        $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
818                                        if( $max > 0 ) {
819
820                                                $graphargs .= "&x=$max&n=$min";
821                                        }
[126]822                                }
823                                if ($textval) {
824                                        $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
825                                } else {
[239]826                                        $cell="<td><a href=$host_link>".  "<img src=\"../../graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
[126]827                                }
828
829                                $tpl->assign("metric_image", $cell);
830                                if (! ($i++ % $hostcols) )
831                                         $tpl->assign ("br", "</tr><tr>");
832                        }
833                }
834//---
835        }
[114]836}
[113]837?>
Note: See TracBrowser for help on using the repository browser.