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

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

web/addons/job_monarch/conf.php:

  • added option COLUMN_REQUESTED_MEMORY to enable/disable showing req. mem

web/addons/job_monarch/version.php:

  • version increase to 0.1.1

web/addons/job_monarch/templates/overview.tpl:

  • req. mem column is now a template block
  • added template block for queued since column (not yet used)

web/addons/job_monarch/overview.php:

  • req. mem column will now only be displayed if enabled in conf.php

web/addons/job_monarch/footer.php:

  • removed some bogus
  • Property svn:keywords set to Id
File size: 20.2 KB
Line 
1<?php
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 *
22 * SVN $Id: overview.php 241 2006-04-07 10:42:02Z bastiaans $
23 */
24
25global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh;
26global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY;
27
28//$tpl->assign("_ROOT.summary", "" );
29
30$data_gatherer = new DataGatherer( $clustername );
31
32//$tpl->assign( "self", "./index.php" );
33$tpl->assign( "clustername", $clustername );
34
35if( $JOB_ARCHIVE )
36        $tpl->assign( "cluster_url", rawurlencode($clustername) );
37
38$data_gatherer->parseXML();
39
40$heartbeat = $data_gatherer->getHeartbeat();
41$jobs = $data_gatherer->getJobs();
42$gnodes = $data_gatherer->getNodes();
43$cpus = $data_gatherer->getCpus();
44
45$filter_image_url = "";
46
47foreach( $filter as $filtername => $filtervalue ) {
48        $tpl->assign( "f_".$filtername, $filtervalue );
49        $filter_image_url .= "&$filtername=$filtervalue";
50}
51
52$tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url );
53$tpl->assign( "f_order", $filterorder );
54
55if( array_key_exists( "id", $filter ) )
56        $piefilter = 'id';
57else if( array_key_exists( "user", $filter ) )
58        $piefilter = 'user';
59else if( array_key_exists( "queue", $filter ) )
60        $piefilter = 'queue';
61
62$pie = drawPie();
63$tpl->assign("pie", $pie );
64
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
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
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];
93        }
94
95        $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
96
97        return $myepoch;
98}
99
100function makeTime( $time ) {
101
102        $days = intval( $time / 86400 );
103        $time = ($days>0) ? $time % ($days * 86400) : $time;
104
105        //printf( "time = %s, days = %s\n", $time, $days );
106
107        $date_str = '';
108        $day_str = '';
109
110        if( $days > 0 ) {
111                if( $days > 1 )
112                        $day_str .= $days . ' days';
113                else
114                        $day_str .= $days . ' day';
115        }
116
117        $hours = intval( $time / 3600 );
118        $time = $hours ? $time % ($hours * 3600) : $time;
119
120        //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );
121
122        if( $hours > 0 ) {
123                $date_str .= $hours . ':';
124                $date_unit = 'hours';
125        }
126               
127        $minutes = intval( $time / 60 );
128        $seconds = $minutes ? $time % ($minutes * 60) : $time;
129
130        if( $minutes > 0 ) {
131
132                if( $minutes >= 10 )
133                        $date_str .= $minutes . ':';
134                else
135                        $date_str .= '0' . $minutes . ':';
136
137                $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
138        } else {
139                if($hours > 0 ) {
140                        $date_str .= '00:';
141                        $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
142                }
143        }
144
145
146        $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
147
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                       
155        } else if ( $hours > 0 or $minutes > 0 )
156
157                $date_str .= '00 ' . $date_unit;
158
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
167        return $date_str;
168}
169
170function makeDate( $time ) {
171        return strftime( "%a %d %b %Y %H:%M:%S", $time );
172}
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
189        $c1r = hexDec( colorRed( $first ) );
190        $c1g = hexDec( colorGreen( $first ) );
191        $c1b = hexDec( colorBlue( $first ) );
192
193        $c2r = hexDec( colorRed( $second ) );
194        $c2g = hexDec( colorGreen( $second ) );
195        $c2b = hexDec( colorBlue( $second ) );
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
209        $start = "004E00";
210       
211        $start_red = colorRed( $start );
212        $start_green = colorGreen( $start );
213        $start_blue = colorBlue( $start );
214       
215        $end = "FFFFFF";
216
217        $end_red = colorRed( $end );
218        $end_green = colorGreen( $end );
219        $end_blue = colorBlue( $end );
220
221        $change_color = TRUE;
222
223        while( $change_color ) {
224
225                $change_color = FALSE;
226
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 ) );
230
231                $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
232
233                foreach( $known_colors as $old )
234
235                        if( !colorDiffer( $new, $old ) )
236
237                                $change_color = TRUE;
238        }
239
240        // Whoa! Actually found a good color ;)
241        return $new;
242}
243
244function drawJobPie() {
245}
246
247function drawUserPie() {
248
249}
250
251function drawQueuePie() {
252
253}
254
255
256function drawPie() {
257
258        global $jobs, $gnodes, $piefilter, $filter;
259
260        $nodes = $gnodes;
261
262        if( isset($piefilter) ) 
263                $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage");
264        else
265                $pie_args = "title=" . rawurlencode("Cluster queue usage");
266               
267        $pie_args .= "&size=250x150";
268
269        $queues = array();
270        $nr_jobs = count( $jobs );
271        $nr_nodes = count( $nodes );
272
273        $emptynodes = 0;
274
275        $job_weight = array();
276
277        foreach( $nodes as $node ) {
278
279                $myjobs = $node->getJobs();
280
281                if( count( $myjobs ) == 0 )
282                        $emptynodes++;
283        }
284        $used_nodes = $nr_nodes - $emptynodes;
285
286        $empty_percentage = ($emptynodes / $nr_nodes) * 100;
287        $job_percentage = 100 - $empty_percentage; 
288
289        $qcolors = array();
290        $color = randomColor( $qcolors );
291        $qcolors[] = $color;
292        $pie_args .= "&free=$empty_percentage,$color";
293
294        if( isset( $piefilter ) )
295                $filterpie = array();
296
297        foreach( $nodes as $node ) {
298
299                $node_jobs = $node->getJobs();
300                $nr_node_jobs = count( $node_jobs );
301                $myhost = $node->getHostname();
302
303                foreach( $node_jobs as $myjob ) {
304
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
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                        }
345                }
346        }
347
348        //$qcolors = array();
349        if( isset( $piefilter ) )
350                $graphvals = $filterpie;
351        else
352                $graphvals = $queues;
353
354        foreach( $graphvals as $name => $totalweight) {
355
356                $percentage = ( $totalweight / $used_nodes ) * $job_percentage;
357               
358                $color = randomColor( $qcolors );
359                $qcolors[] = $color;
360                $pie_args .= "&$name=$percentage,$color";
361        }
362        $pie = "../../pie.php?$pie_args";
363
364        return $pie;
365}
366
367
368function sortJobs( $jobs, $sortby, $sortorder ) {
369
370        $sorted = array();
371
372        $cmp = create_function( '$a, $b', 
373                "global \$sortby, \$sortorder;".
374
375                "if( \$a == \$b ) return 0;".
376
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];
390
391                        if( $state == 'R' )
392                                $nodes = count( $jobattrs[nodes] );
393                        else
394                                $nodes = $jobattrs[nodes];
395
396                        $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
397                        $cpus = $nodes * $ppn;
398                        $start_time = (int) $jobattrs[start_timestamp];
399                        $runningtime = $report_time - $start_time;
400
401                        switch( $sortby ) {
402                                case "id":
403                                        $sorted[$jobid] = $jobid;
404                                        break;
405
406                                case "state":
407                                        $sorted[$jobid] = $state;
408                                        break;
409
410                                case "user":
411                                        $sorted[$jobid] = $user;
412                                        break;
413
414                                case "queue":
415                                        $sorted[$jobid] = $queue;
416                                        break;
417
418                                case "name":
419                                        $sorted[$jobid] = $name;
420                                        break;
421
422                                case "req_cpu":
423                                        $sorted[$jobid] = timeToEpoch( $req_cpu );
424                                        break;
425
426                                case "req_mem":
427                                        $sorted[$jobid] = $req_memory;
428                                        break;
429
430                                case "nodes":
431                                        $sorted[$jobid] = $nodes;
432                                        break;
433
434                                case "cpus":
435                                        $sorted[$jobid] = $cpus;
436                                        break;
437
438                                case "start":
439                                        $sorted[$jobid] = $start_time;
440                                        break;
441
442                                case "runningtime":
443                                        $sorted[$jobid] = $runningtime;
444                                        break;
445
446                                default:
447                                        break;
448
449                        }
450        }
451
452        //uasort( $sorted, $cmp );
453        if( $sortorder == "asc" )
454                arsort( $sorted );
455        else if( $sortorder == "desc" )
456                asort( $sorted );
457
458        return $sorted;
459}
460
461function makeOverview() {
462
463        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
464        global $sortorder, $sortby, $filter, $sh, $hc, $m;
465        global $cluster_url, $get_metric_string, $host_url, $metrics;
466        global $start, $end, $reports, $gnodes, $default_showhosts;
467
468        $metricname = $m;
469
470        $tpl->assign("sortorder", $sortorder );
471        $tpl->assign("sortby", $sortby );
472
473        $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder );
474
475        $even = 1;
476
477        $used_jobs = 0;
478        $used_cpus = 0;
479        $used_nodes = 0;
480
481        $queued_jobs = 0;
482        $queued_nodes = 0;
483        $queued_cpus = 0;
484
485        $total_nodes = 0;
486        $total_cpus = 0;
487        $total_jobs = 0;
488
489        $all_used_nodes = array();
490        $total_used_nodes = array();
491
492        $running_name_nodes = array();
493
494        $running_nodes = 0;
495        $running_jobs = 0;
496        $running_cpus = 0;
497
498        $avail_nodes = count( $gnodes );
499        $avail_cpus = cluster_sum("cpu_num", $metrics);
500
501        $view_cpus = 0;
502        $view_jobs = 0;
503        $view_nodes = 0;
504
505        $all_nodes = 0;
506        $all_jobs = 0;
507        $all_cpus = 0;
508
509        $view_name_nodes = array();
510
511        if( $COLUMN_REQUESTED_MEMORY ) {
512                $tpl->newBlock( "column_req_mem" );
513                $tpl->gotoBlock( "node" );
514        }
515
516        foreach( $sorted_jobs as $jobid => $sortdec ) {
517
518                $report_time = $jobs[$jobid][reported];
519
520                if( $jobs[$jobid][status] == 'R' )
521                        $nodes = count( $jobs[$jobid][nodes] );
522                else if( $jobs[$jobid][status] == 'Q' )
523                        $nodes = $jobs[$jobid][nodes];
524
525                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
526                $cpus = $nodes * $ppn;
527
528                if( $report_time == $heartbeat ) {
529
530                        $display_job = 1;
531
532                        foreach( $jobs[$jobid][nodes] as $tempnode )
533                                $all_used_nodes[] = $tempnode;
534
535                        $used_cpus += $cpus;
536
537                        if( $jobs[$jobid][status] == 'R' ) {
538                                $running_cpus += $cpus;
539                                $running_jobs++;
540
541                                foreach( $jobs[$jobid][nodes] as $tempnode )
542                                        $running_name_nodes[] = $tempnode;
543                        }
544
545                        if( $jobs[$jobid][status] == 'Q' ) {
546                                $queued_cpus += $cpus;
547                                $queued_nodes += $nodes;
548                                $queued_jobs++;
549                        }
550
551                        foreach( $filter as $filtername=>$filtervalue ) {
552
553                                if( $filtername == 'id' && $jobid != $filtervalue )
554                                        $display_job = 0;
555                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
556                                        $display_job = 0;
557                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
558                                        $display_job = 0;
559                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
560                                        $display_job = 0;
561                        }
562
563                        if( $display_job ) {
564
565                                $tpl->newBlock("node");
566                                $tpl->assign( "clustername", $clustername );
567                                $tpl->assign("id", $jobid );
568                                $tpl->assign("state", $jobs[$jobid][status] );
569
570                                $fullstate = '';
571                                if( $jobs[$jobid][status] == 'R' ) {
572                                        $fullstate = "Running";
573                                } else if( $jobs[$jobid][status] == 'Q' ) {
574                                        $fullstate = "Queued";
575                                }
576
577                                $tpl->assign("fullstate", $fullstate );
578                               
579                                $tpl->assign("user", $jobs[$jobid][owner] );
580                                $tpl->assign("queue", $jobs[$jobid][queue] );
581
582                                $fulljobname = $jobs[$jobid][name];
583                                $shortjobname = '';
584
585                                $tpl->assign("fulljobname", $fulljobname );
586
587                                if( mb_strwidth( $fulljobname ) > 10 ) {
588                                        $tpl->newBlock("jobname_hint_start");
589                                        $tpl->gotoBlock("node");
590
591                                        $shortjobname = mb_strimwidth( $fulljobname, 0, 9 ) . '..';
592                                } else {
593                                        $shortjobname = $fulljobname;
594                                }
595                               
596                                $tpl->assign("name", $shortjobname );
597
598                                if( strlen( $fulljobname ) > 10 ) {
599                                        $tpl->newBlock("jobname_hint_end");
600                                        $tpl->gotoBlock("node");
601                                }
602
603                                $domain = $jobs[$jobid][domain];
604                                $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
605
606                                if( $COLUMN_REQUESTED_MEMORY ) {
607                                        $tpl->newBlock( "column_req_mem" );
608                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
609                                        $tpl->gotoBlock( "node" );
610                                }
611
612                                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
613                                $cpus = $nodes * $ppn;
614                                $tpl->assign("nodes", $nodes );
615                                $tpl->assign("cpus", $cpus );
616                                $start_time = (int) $jobs[$jobid][start_timestamp];
617                                $job_start = $start_time;
618
619                                $view_cpus += $cpus;
620                                $view_jobs++;
621
622                                if( $jobs[$jobid][status] == 'R' )
623                                        foreach( $jobs[$jobid][nodes] as $tempnode )
624                                                $view_name_nodes[] = $tempnode;
625                                else if( $jobs[$jobid][status] == 'Q' )
626                                        $view_nodes += (int) $jobs[$jobid][nodes];
627
628                                if( $even ) {
629
630                                        $tpl->assign("nodeclass", "even");
631                                        $even = 0;
632                                } else {
633
634                                        $tpl->assign("nodeclass", "odd");
635                                        $even = 1;
636                                }
637
638                                if( $start_time ) {
639
640                                        $runningtime = makeTime( $report_time - $start_time );
641                                        $job_runningtime = $report_time - $start_time;
642                                        $tpl->assign("started", makeDate( $start_time ) );
643                                        $tpl->assign("runningtime", $runningtime );
644                                }
645                        }
646                }
647        }
648        array_unique( $all_used_nodes );
649        array_unique( $view_name_nodes );
650        array_unique( $running_name_nodes );
651
652        $used_nodes = count( $all_used_nodes );
653        $view_nodes += count( $view_name_nodes );
654        $running_nodes += count( $running_name_nodes );
655
656        $total_nodes = $queued_nodes + $running_nodes;
657        $total_cpus = $queued_cpus + $running_cpus;
658        $total_jobs = $queued_jobs + $running_jobs;
659
660        //$tpl->assignGlobal("cpus_nr", $overview_cpus );
661        //$tpl->assignGlobal("jobs_nr", $overview_jobs );
662
663        $tpl->assignGlobal("avail_nodes", $avail_nodes );
664        $tpl->assignGlobal("avail_cpus", $avail_cpus );
665
666        $tpl->assignGlobal("queued_nodes", $queued_nodes );
667        $tpl->assignGlobal("queued_jobs", $queued_jobs );
668        $tpl->assignGlobal("queued_cpus", $queued_cpus );
669
670        $tpl->assignGlobal("total_nodes", $total_nodes );
671        $tpl->assignGlobal("total_jobs", $total_jobs );
672        $tpl->assignGlobal("total_cpus", $total_cpus );
673
674        $tpl->assignGlobal("running_nodes", $running_nodes );
675        $tpl->assignGlobal("running_jobs", $running_jobs );
676        $tpl->assignGlobal("running_cpus", $running_cpus );
677
678        $tpl->assignGlobal("used_nodes", $used_nodes );
679        $tpl->assignGlobal("used_jobs", $used_jobs );
680        $tpl->assignGlobal("used_cpus", $used_cpus );
681
682        $free_nodes = $avail_nodes - $running_nodes;
683        $free_cpus = $avail_cpus - $running_cpus;
684
685        $tpl->assignGlobal("free_nodes", $free_nodes );
686        $tpl->assignGlobal("free_cpus", $free_cpus );
687
688        $tpl->assignGlobal("view_nodes", $view_nodes );
689        $tpl->assignGlobal("view_jobs", $view_jobs );
690        $tpl->assignGlobal("view_cpus", $view_cpus );
691
692        $tpl->assignGlobal("report_time", makeDate( $heartbeat));
693       
694        //$tpl->assignGlobal("f_cpus_nr", $f_cpus );
695        //$tpl->assignGlobal("f_jobs_nr", $f_jobs );
696
697        if( intval($view_jobs) == 1 and $start_time ) {
698                $tpl->newBlock( "showhosts" );
699
700                # Present a width list
701                $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
702
703                $hostcols = ($hc) ? $hc : 4;
704
705                foreach(range(1,25) as $cols) {
706                        $cols_menu .= "<OPTION VALUE=$cols ";
707                        if ($cols == $hostcols)
708                                $cols_menu .= "SELECTED";
709                        $cols_menu .= ">$cols\n";
710                }
711                $cols_menu .= "</SELECT>\n";
712
713                //$tpl->assign("cluster", $clustername);
714                $tpl->assign("metric","$metricname $units");
715                $tpl->assign("id", $filter[id]);
716                # Host columns menu defined in header.php
717                $tpl->assign("cols_menu", $cols_menu);
718
719                $showhosts = isset($sh) ? $sh : $default_showhosts;
720                //if( !$showhosts) $showhosts = $default_showhosts;
721                $tpl->assign("checked$showhosts", "checked");
722
723                if( $showhosts ) {
724                        //-----
725
726                        if( !isset($start) ) $start="jobstart";
727                        if( !isset($stop) ) $stop="now";
728                        //$tpl->assign("start", $start);
729                        //$tpl->assign("stop", $stop);
730
731                        $sorted_hosts = array();
732                        $hosts_up = $jobs[$filter[id]][nodes];
733
734                        $r = intval($job_runningtime * 1.25);
735
736                        $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ;
737                        $jobstart = $report_time - $job_runningtime;
738
739                        if ($reports[$metricname])
740                                $metricval = "g";
741                        else
742                                $metricval = "m";
743                                               
744                        foreach ($hosts_up as $host ) {
745
746                                $domain_len = 0 - strlen( $domain );
747                                if( substr( $host, $domain_len ) != $domain ) {
748                                        $host = $host. '.'.$domain;
749                                }
750                                $cpus = $metrics[$host]["cpu_num"][VAL];
751                                if (!$cpus) $cpus=1;
752                                $load_one  = $metrics[$host]["load_one"][VAL];
753                                $load = ((float) $load_one)/$cpus;
754                                $host_load[$host] = $load;
755                                $percent_hosts[load_color($load)] += 1;
756                                if ($metricname=="load_one")
757                                        $sorted_hosts[$host] = $load;
758                                else
759                                        $sorted_hosts[$host] = $metrics[$host][$metricname][VAL];
760                        }
761                        switch ($sort) {
762                                case "descending":
763                                        arsort($sorted_hosts);
764                                        break;
765                                case "by hostname":
766                                        ksort($sorted_hosts);
767                                        break;
768                                default:
769                                case "ascending":
770                                        asort($sorted_hosts);
771                                        break;
772                        }
773
774                        //$sorted_hosts = array_merge($down_hosts, $sorted_hosts);
775
776                        # First pass to find the max value in all graphs for this
777                        # metric. The $start,$end variables comes from get_context.php,
778                        # included in index.php.
779                        list($min, $max) = find_limits($sorted_hosts, $metricname);
780
781                        # Second pass to output the graphs or metrics.
782                        $i = 1;
783                        foreach ( $sorted_hosts as $host=>$value  ) {
784                                $tpl->newBlock ("sorted_list");
785                                //$host = $host. '.'.$domain;
786                                $host_url = rawurlencode($host);
787                                $cluster_url = rawurlencode($clustername);
788
789                                $textval = "";
790                                //printf("host = %s, value = %s", $host, $value);
791                                //echo "$host: $value, ";
792                                $val = $metrics[$host][$metricname];
793                                $class = "metric";
794                                $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
795
796                                if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) {
797                                        $textval = date("r", $val[VAL]);
798                                } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
799                                        $textval = "$val[VAL] $val[UNITS]";
800                                } else {
801                                        $load_color = load_color($host_load[$host]);
802                                        $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
803                                        $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
804                                        if( $max > 0 ) {
805
806                                                $graphargs .= "&x=$max&n=$min";
807                                        }
808                                }
809                                if ($textval) {
810                                        $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
811                                } else {
812                                        $cell="<td><a href=$host_link>".  "<img src=\"../../graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
813                                }
814
815                                $tpl->assign("metric_image", $cell);
816                                if (! ($i++ % $hostcols) )
817                                         $tpl->assign ("br", "</tr><tr>");
818                        }
819                }
820//---
821        }
822}
823?>
Note: See TracBrowser for help on using the repository browser.