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

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

jobmond/jobmond.py:

  • added queued_timestamp

web/addons/job_monarch/overview.php:

  • fixed typo in queued since assignment
  • Property svn:keywords set to Id
File size: 20.5 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 243 2006-04-07 15:31:25Z 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, $COLUMN_QUEUED;
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        global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY;
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_header_req_mem" );
513        }
514
515        if( $COLUMN_QUEUED ) {
516                $tpl->newBlock( "column_header_queued" );
517        }
518
519        foreach( $sorted_jobs as $jobid => $sortdec ) {
520
521                $report_time = $jobs[$jobid][reported];
522
523                if( $jobs[$jobid][status] == 'R' )
524                        $nodes = count( $jobs[$jobid][nodes] );
525                else if( $jobs[$jobid][status] == 'Q' )
526                        $nodes = $jobs[$jobid][nodes];
527
528                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
529                $cpus = $nodes * $ppn;
530
531                if( $report_time == $heartbeat ) {
532
533                        $display_job = 1;
534
535                        foreach( $jobs[$jobid][nodes] as $tempnode )
536                                $all_used_nodes[] = $tempnode;
537
538                        $used_cpus += $cpus;
539
540                        if( $jobs[$jobid][status] == 'R' ) {
541                                $running_cpus += $cpus;
542                                $running_jobs++;
543
544                                foreach( $jobs[$jobid][nodes] as $tempnode )
545                                        $running_name_nodes[] = $tempnode;
546                        }
547
548                        if( $jobs[$jobid][status] == 'Q' ) {
549                                $queued_cpus += $cpus;
550                                $queued_nodes += $nodes;
551                                $queued_jobs++;
552                        }
553
554                        foreach( $filter as $filtername=>$filtervalue ) {
555
556                                if( $filtername == 'id' && $jobid != $filtervalue )
557                                        $display_job = 0;
558                                else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue )
559                                        $display_job = 0;
560                                else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue )
561                                        $display_job = 0;
562                                else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue )
563                                        $display_job = 0;
564                        }
565
566                        if( $display_job ) {
567
568                                $tpl->newBlock("node");
569                                $tpl->assign( "clustername", $clustername );
570                                $tpl->assign("id", $jobid );
571                                $tpl->assign("state", $jobs[$jobid][status] );
572
573                                $fullstate = '';
574                                if( $jobs[$jobid][status] == 'R' ) {
575                                        $fullstate = "Running";
576                                } else if( $jobs[$jobid][status] == 'Q' ) {
577                                        $fullstate = "Queued";
578                                }
579
580                                $tpl->assign("fullstate", $fullstate );
581                               
582                                $tpl->assign("user", $jobs[$jobid][owner] );
583                                $tpl->assign("queue", $jobs[$jobid][queue] );
584
585                                $fulljobname = $jobs[$jobid][name];
586                                $shortjobname = '';
587
588                                $tpl->assign("fulljobname", $fulljobname );
589
590                                if( mb_strwidth( $fulljobname ) > 10 ) {
591                                        $tpl->newBlock("jobname_hint_start");
592                                        $tpl->gotoBlock("node");
593
594                                        $shortjobname = mb_strimwidth( $fulljobname, 0, 9 ) . '..';
595                                } else {
596                                        $shortjobname = $fulljobname;
597                                }
598                               
599                                $tpl->assign("name", $shortjobname );
600
601                                if( strlen( $fulljobname ) > 10 ) {
602                                        $tpl->newBlock("jobname_hint_end");
603                                        $tpl->gotoBlock("node");
604                                }
605
606                                $domain = $jobs[$jobid][domain];
607                                $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) );
608
609                                if( $COLUMN_REQUESTED_MEMORY ) {
610                                        $tpl->newBlock( "column_req_mem" );
611                                        $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] );
612                                        $tpl->gotoBlock( "node" );
613                                }
614
615                                if( $COLUMN_QUEUED ) {
616                                        $tpl->newBlock( "column_queued" );
617                                        $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) );
618                                        $tpl->gotoBlock( "node" );
619                                }
620
621                                $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
622                                $cpus = $nodes * $ppn;
623                                $tpl->assign("nodes", $nodes );
624                                $tpl->assign("cpus", $cpus );
625                                $start_time = (int) $jobs[$jobid][start_timestamp];
626                                $job_start = $start_time;
627
628                                $view_cpus += $cpus;
629                                $view_jobs++;
630
631                                if( $jobs[$jobid][status] == 'R' )
632                                        foreach( $jobs[$jobid][nodes] as $tempnode )
633                                                $view_name_nodes[] = $tempnode;
634                                else if( $jobs[$jobid][status] == 'Q' )
635                                        $view_nodes += (int) $jobs[$jobid][nodes];
636
637                                if( $even ) {
638
639                                        $tpl->assign("nodeclass", "even");
640                                        $even = 0;
641                                } else {
642
643                                        $tpl->assign("nodeclass", "odd");
644                                        $even = 1;
645                                }
646
647                                if( $start_time ) {
648
649                                        $runningtime = makeTime( $report_time - $start_time );
650                                        $job_runningtime = $report_time - $start_time;
651                                        $tpl->assign("started", makeDate( $start_time ) );
652                                        $tpl->assign("runningtime", $runningtime );
653                                }
654                        }
655                }
656        }
657        array_unique( $all_used_nodes );
658        array_unique( $view_name_nodes );
659        array_unique( $running_name_nodes );
660
661        $used_nodes = count( $all_used_nodes );
662        $view_nodes += count( $view_name_nodes );
663        $running_nodes += count( $running_name_nodes );
664
665        $total_nodes = $queued_nodes + $running_nodes;
666        $total_cpus = $queued_cpus + $running_cpus;
667        $total_jobs = $queued_jobs + $running_jobs;
668
669        //$tpl->assignGlobal("cpus_nr", $overview_cpus );
670        //$tpl->assignGlobal("jobs_nr", $overview_jobs );
671
672        $tpl->assignGlobal("avail_nodes", $avail_nodes );
673        $tpl->assignGlobal("avail_cpus", $avail_cpus );
674
675        $tpl->assignGlobal("queued_nodes", $queued_nodes );
676        $tpl->assignGlobal("queued_jobs", $queued_jobs );
677        $tpl->assignGlobal("queued_cpus", $queued_cpus );
678
679        $tpl->assignGlobal("total_nodes", $total_nodes );
680        $tpl->assignGlobal("total_jobs", $total_jobs );
681        $tpl->assignGlobal("total_cpus", $total_cpus );
682
683        $tpl->assignGlobal("running_nodes", $running_nodes );
684        $tpl->assignGlobal("running_jobs", $running_jobs );
685        $tpl->assignGlobal("running_cpus", $running_cpus );
686
687        $tpl->assignGlobal("used_nodes", $used_nodes );
688        $tpl->assignGlobal("used_jobs", $used_jobs );
689        $tpl->assignGlobal("used_cpus", $used_cpus );
690
691        $free_nodes = $avail_nodes - $running_nodes;
692        $free_cpus = $avail_cpus - $running_cpus;
693
694        $tpl->assignGlobal("free_nodes", $free_nodes );
695        $tpl->assignGlobal("free_cpus", $free_cpus );
696
697        $tpl->assignGlobal("view_nodes", $view_nodes );
698        $tpl->assignGlobal("view_jobs", $view_jobs );
699        $tpl->assignGlobal("view_cpus", $view_cpus );
700
701        $tpl->assignGlobal("report_time", makeDate( $heartbeat));
702       
703        //$tpl->assignGlobal("f_cpus_nr", $f_cpus );
704        //$tpl->assignGlobal("f_jobs_nr", $f_jobs );
705
706        if( intval($view_jobs) == 1 and $start_time ) {
707                $tpl->newBlock( "showhosts" );
708
709                # Present a width list
710                $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n";
711
712                $hostcols = ($hc) ? $hc : 4;
713
714                foreach(range(1,25) as $cols) {
715                        $cols_menu .= "<OPTION VALUE=$cols ";
716                        if ($cols == $hostcols)
717                                $cols_menu .= "SELECTED";
718                        $cols_menu .= ">$cols\n";
719                }
720                $cols_menu .= "</SELECT>\n";
721
722                //$tpl->assign("cluster", $clustername);
723                $tpl->assign("metric","$metricname $units");
724                $tpl->assign("id", $filter[id]);
725                # Host columns menu defined in header.php
726                $tpl->assign("cols_menu", $cols_menu);
727
728                $showhosts = isset($sh) ? $sh : $default_showhosts;
729                //if( !$showhosts) $showhosts = $default_showhosts;
730                $tpl->assign("checked$showhosts", "checked");
731
732                if( $showhosts ) {
733                        //-----
734
735                        if( !isset($start) ) $start="jobstart";
736                        if( !isset($stop) ) $stop="now";
737                        //$tpl->assign("start", $start);
738                        //$tpl->assign("stop", $stop);
739
740                        $sorted_hosts = array();
741                        $hosts_up = $jobs[$filter[id]][nodes];
742
743                        $r = intval($job_runningtime * 1.25);
744
745                        $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ;
746                        $jobstart = $report_time - $job_runningtime;
747
748                        if ($reports[$metricname])
749                                $metricval = "g";
750                        else
751                                $metricval = "m";
752                                               
753                        foreach ($hosts_up as $host ) {
754
755                                $domain_len = 0 - strlen( $domain );
756                                if( substr( $host, $domain_len ) != $domain ) {
757                                        $host = $host. '.'.$domain;
758                                }
759                                $cpus = $metrics[$host]["cpu_num"][VAL];
760                                if (!$cpus) $cpus=1;
761                                $load_one  = $metrics[$host]["load_one"][VAL];
762                                $load = ((float) $load_one)/$cpus;
763                                $host_load[$host] = $load;
764                                $percent_hosts[load_color($load)] += 1;
765                                if ($metricname=="load_one")
766                                        $sorted_hosts[$host] = $load;
767                                else
768                                        $sorted_hosts[$host] = $metrics[$host][$metricname][VAL];
769                        }
770                        switch ($sort) {
771                                case "descending":
772                                        arsort($sorted_hosts);
773                                        break;
774                                case "by hostname":
775                                        ksort($sorted_hosts);
776                                        break;
777                                default:
778                                case "ascending":
779                                        asort($sorted_hosts);
780                                        break;
781                        }
782
783                        //$sorted_hosts = array_merge($down_hosts, $sorted_hosts);
784
785                        # First pass to find the max value in all graphs for this
786                        # metric. The $start,$end variables comes from get_context.php,
787                        # included in index.php.
788                        list($min, $max) = find_limits($sorted_hosts, $metricname);
789
790                        # Second pass to output the graphs or metrics.
791                        $i = 1;
792                        foreach ( $sorted_hosts as $host=>$value  ) {
793                                $tpl->newBlock ("sorted_list");
794                                //$host = $host. '.'.$domain;
795                                $host_url = rawurlencode($host);
796                                $cluster_url = rawurlencode($clustername);
797
798                                $textval = "";
799                                //printf("host = %s, value = %s", $host, $value);
800                                //echo "$host: $value, ";
801                                $val = $metrics[$host][$metricname];
802                                $class = "metric";
803                                $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\"";
804
805                                if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) {
806                                        $textval = date("r", $val[VAL]);
807                                } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) {
808                                        $textval = "$val[VAL] $val[UNITS]";
809                                } else {
810                                        $load_color = load_color($host_load[$host]);
811                                        $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&";
812                                        $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart";
813                                        if( $max > 0 ) {
814
815                                                $graphargs .= "&x=$max&n=$min";
816                                        }
817                                }
818                                if ($textval) {
819                                        $cell="<td class=$class>".  "<b><a href=$host_link>$host</a></b><br>".  "<i>$metricname:</i> <b>$textval</b></td>";
820                                } else {
821                                        $cell="<td><a href=$host_link>".  "<img src=\"../../graph.php?$graphargs\" ".  "alt=\"$host\" border=0></a></td>";
822                                }
823
824                                $tpl->assign("metric_image", $cell);
825                                if (! ($i++ % $hostcols) )
826                                         $tpl->assign ("br", "</tr><tr>");
827                        }
828                }
829//---
830        }
831}
832?>
Note: See TracBrowser for help on using the repository browser.